mirror of https://github.com/wekan/wekan
The Open Source kanban (built with Meteor). Keep variable/table/field names camelCase. For translations, only add Pull Request changes to wekan/i18n/en.i18n.json , other translations are done at https://transifex.com/wekan/wekan only.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.5 KiB
70 lines
1.5 KiB
![]()
10 years ago
|
CardComments = new Mongo.Collection('card_comments');
|
||
|
|
||
|
CardComments.attachSchema(new SimpleSchema({
|
||
|
boardId: {
|
||
|
type: String,
|
||
|
},
|
||
|
cardId: {
|
||
|
type: String,
|
||
|
},
|
||
|
// XXX Rename in `content`? `text` is a bit vague...
|
||
|
text: {
|
||
|
type: String,
|
||
|
},
|
||
|
// XXX We probably don't need this information here, since we already have it
|
||
|
// in the associated comment creation activity
|
||
|
createdAt: {
|
||
|
type: Date,
|
||
|
denyUpdate: false,
|
||
|
},
|
||
|
// XXX Should probably be called `authorId`
|
||
|
userId: {
|
||
|
type: String,
|
||
|
},
|
||
|
}));
|
||
|
|
||
|
CardComments.allow({
|
||
|
insert(userId, doc) {
|
||
|
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
|
||
|
},
|
||
|
update(userId, doc) {
|
||
|
return userId === doc.userId;
|
||
|
},
|
||
|
remove(userId, doc) {
|
||
|
return userId === doc.userId;
|
||
|
},
|
||
|
fetch: ['userId', 'boardId'],
|
||
|
});
|
||
|
|
||
|
CardComments.helpers({
|
||
|
user() {
|
||
|
return Users.findOne(this.userId);
|
||
|
},
|
||
|
});
|
||
|
|
||
|
CardComments.hookOptions.after.update = { fetchPrevious: false };
|
||
|
|
||
|
CardComments.before.insert((userId, doc) => {
|
||
|
doc.createdAt = new Date();
|
||
|
doc.userId = userId;
|
||
|
});
|
||
|
|
||
|
if (Meteor.isServer) {
|
||
|
CardComments.after.insert((userId, doc) => {
|
||
|
Activities.insert({
|
||
|
userId,
|
||
|
activityType: 'addComment',
|
||
|
boardId: doc.boardId,
|
||
|
cardId: doc.cardId,
|
||
|
commentId: doc._id,
|
||
|
});
|
||
|
});
|
||
|
|
||
|
CardComments.after.remove((userId, doc) => {
|
||
|
const activity = Activities.findOne({ commentId: doc._id });
|
||
|
if (activity) {
|
||
|
Activities.remove(activity._id);
|
||
|
}
|
||
|
});
|
||
|
}
|