mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
The activity feed rendered "edited comment undefined" / "deleted comment undefined" for comment edits and deletions. The template passed the comment's ID into the "%s" of activity-editComment / activity-deleteComment: on older activities the id was absent (literally "undefined"), and a deleted comment's CardComment document is already removed so it cannot be looked up live either. The edit and delete activities now store the comment text (commentText), and a new Activities.commentDisplayText() helper picks the stored text, else the live comment text (edit case), else an empty string — so the feed never renders the word "undefined". The template shows the (sanitized) comment text. The text-selection logic is a Meteor-free helper models/lib/commentActivity.js, unit tested (positive + negative) in tests/commentActivity.test.cjs. Thanks to janchuelo and xet7.
90 lines
2.7 KiB
JavaScript
90 lines
2.7 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { findWhere, where } from '/imports/lib/collectionHelpers';
|
|
|
|
// Activities don't need a schema because they are always set from the a trusted
|
|
// environment - the server - and there is no risk that a user change the logic
|
|
// we use with this collection. Moreover using a schema for this collection
|
|
// would be difficult (different activities have different fields) and wouldn't
|
|
// bring any direct advantage.
|
|
//
|
|
// XXX The activities API is not so nice and need some functionalities. For
|
|
// instance if a user archive a card, and un-archive it a few seconds later we
|
|
// should remove both activities assuming it was an error the user decided to
|
|
// revert.
|
|
const Activities = new Mongo.Collection('activities');
|
|
|
|
Activities.helpers({
|
|
board() {
|
|
return ReactiveCache.getBoard(this.boardId);
|
|
},
|
|
oldBoard() {
|
|
return ReactiveCache.getBoard(this.oldBoardId);
|
|
},
|
|
user() {
|
|
return ReactiveCache.getUser(this.userId);
|
|
},
|
|
member() {
|
|
return ReactiveCache.getUser(this.memberId);
|
|
},
|
|
list() {
|
|
return ReactiveCache.getList(this.listId);
|
|
},
|
|
swimlane() {
|
|
return ReactiveCache.getSwimlane(this.swimlaneId);
|
|
},
|
|
oldSwimlane() {
|
|
return ReactiveCache.getSwimlane(this.oldSwimlaneId);
|
|
},
|
|
oldList() {
|
|
return ReactiveCache.getList(this.oldListId);
|
|
},
|
|
card() {
|
|
return ReactiveCache.getCard(this.cardId);
|
|
},
|
|
comment() {
|
|
return ReactiveCache.getCardComment(this.commentId);
|
|
},
|
|
// #3606: text to show for editComment/deleteComment activities — the stored
|
|
// commentText, else the live comment's text, else '' (never "undefined").
|
|
commentDisplayText() {
|
|
const { commentActivityDisplayText } = require('./lib/commentActivity');
|
|
return commentActivityDisplayText({
|
|
commentText: this.commentText,
|
|
comment: this.comment(),
|
|
});
|
|
},
|
|
attachment() {
|
|
return ReactiveCache.getAttachment(this.attachmentId);
|
|
},
|
|
checklist() {
|
|
return ReactiveCache.getChecklist(this.checklistId);
|
|
},
|
|
checklistItem() {
|
|
return ReactiveCache.getChecklistItem(this.checklistItemId);
|
|
},
|
|
subtasks() {
|
|
return ReactiveCache.getCard(this.subtaskId);
|
|
},
|
|
customField() {
|
|
return ReactiveCache.getCustomField(this.customFieldId);
|
|
},
|
|
label() {
|
|
// Label activity did not work yet, unable to edit labels when tried this.
|
|
return ReactiveCache.getCard(this.labelId);
|
|
},
|
|
});
|
|
|
|
Activities.before.update((userId, doc, fieldNames, modifier) => {
|
|
modifier.$set = modifier.$set || {};
|
|
modifier.$set.modifiedAt = new Date();
|
|
});
|
|
|
|
Activities.before.insert((userId, doc) => {
|
|
doc.createdAt = new Date();
|
|
doc.modifiedAt = doc.createdAt;
|
|
});
|
|
|
|
export default Activities;
|