|
@@ -1,5 +1,4 @@
|
|
|
Cards = new Mongo.Collection('cards');
|
|
|
-CardComments = new Mongo.Collection('card_comments');
|
|
|
|
|
|
// XXX To improve pub/sub performances a card document should include a
|
|
|
// de-normalized number of comments so we don't have to publish the whole list
|
|
@@ -54,64 +53,28 @@ Cards.attachSchema(new SimpleSchema({
|
|
|
},
|
|
|
}));
|
|
|
|
|
|
-CardComments.attachSchema(new SimpleSchema({
|
|
|
- boardId: {
|
|
|
- type: String,
|
|
|
+Cards.allow({
|
|
|
+ insert(userId, doc) {
|
|
|
+ return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
|
|
|
},
|
|
|
- cardId: {
|
|
|
- type: String,
|
|
|
- },
|
|
|
- // XXX Rename in `content`? `text` is a bit vague...
|
|
|
- text: {
|
|
|
- type: String,
|
|
|
+ update(userId, doc) {
|
|
|
+ return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
|
|
|
},
|
|
|
- // 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,
|
|
|
+ remove(userId, doc) {
|
|
|
+ return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
|
|
|
},
|
|
|
-}));
|
|
|
-
|
|
|
-if (Meteor.isServer) {
|
|
|
- Cards.allow({
|
|
|
- insert(userId, doc) {
|
|
|
- return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
|
|
|
- },
|
|
|
- update(userId, doc) {
|
|
|
- return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
|
|
|
- },
|
|
|
- remove(userId, doc) {
|
|
|
- return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
|
|
|
- },
|
|
|
- fetch: ['boardId'],
|
|
|
- });
|
|
|
-
|
|
|
- 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'],
|
|
|
- });
|
|
|
-}
|
|
|
+ fetch: ['boardId'],
|
|
|
+});
|
|
|
|
|
|
Cards.helpers({
|
|
|
list() {
|
|
|
return Lists.findOne(this.listId);
|
|
|
},
|
|
|
+
|
|
|
board() {
|
|
|
return Boards.findOne(this.boardId);
|
|
|
},
|
|
|
+
|
|
|
labels() {
|
|
|
const boardLabels = this.board().labels;
|
|
|
const cardLabels = _.filter(boardLabels, (label) => {
|
|
@@ -119,27 +82,35 @@ Cards.helpers({
|
|
|
});
|
|
|
return cardLabels;
|
|
|
},
|
|
|
+
|
|
|
hasLabel(labelId) {
|
|
|
return _.contains(this.labelIds, labelId);
|
|
|
},
|
|
|
+
|
|
|
user() {
|
|
|
return Users.findOne(this.userId);
|
|
|
},
|
|
|
+
|
|
|
isAssigned(memberId) {
|
|
|
return _.contains(this.members, memberId);
|
|
|
},
|
|
|
+
|
|
|
activities() {
|
|
|
return Activities.find({ cardId: this._id }, { sort: { createdAt: -1 }});
|
|
|
},
|
|
|
+
|
|
|
comments() {
|
|
|
return CardComments.find({ cardId: this._id }, { sort: { createdAt: -1 }});
|
|
|
},
|
|
|
+
|
|
|
attachments() {
|
|
|
return Attachments.find({ cardId: this._id }, { sort: { uploadedAt: -1 }});
|
|
|
},
|
|
|
+
|
|
|
cover() {
|
|
|
return Attachments.findOne(this.coverId);
|
|
|
},
|
|
|
+
|
|
|
absoluteUrl() {
|
|
|
const board = this.board();
|
|
|
return FlowRouter.path('card', {
|
|
@@ -148,33 +119,86 @@ Cards.helpers({
|
|
|
cardId: this._id,
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
rootUrl() {
|
|
|
return Meteor.absoluteUrl(this.absoluteUrl().replace('/', ''));
|
|
|
},
|
|
|
});
|
|
|
|
|
|
-CardComments.helpers({
|
|
|
- user() {
|
|
|
- return Users.findOne(this.userId);
|
|
|
+Cards.mutations({
|
|
|
+ archive() {
|
|
|
+ return { $set: { archived: true }};
|
|
|
+ },
|
|
|
+
|
|
|
+ restore() {
|
|
|
+ return { $set: { archived: false }};
|
|
|
+ },
|
|
|
+
|
|
|
+ setTitle(title) {
|
|
|
+ return { $set: { title }};
|
|
|
+ },
|
|
|
+
|
|
|
+ setDescription(description) {
|
|
|
+ return { $set: { description }};
|
|
|
+ },
|
|
|
+
|
|
|
+ move(listId, sortIndex) {
|
|
|
+ const mutatedFields = { listId };
|
|
|
+ if (sortIndex) {
|
|
|
+ mutatedFields.sort = sortIndex;
|
|
|
+ }
|
|
|
+ return { $set: mutatedFields };
|
|
|
+ },
|
|
|
+
|
|
|
+ addLabel(labelId) {
|
|
|
+ return { $addToSet: { labelIds: labelId }};
|
|
|
+ },
|
|
|
+
|
|
|
+ removeLabel(labelId) {
|
|
|
+ return { $pull: { labelIds: labelId }};
|
|
|
+ },
|
|
|
+
|
|
|
+ toggleLabel(labelId) {
|
|
|
+ if (this.labelIds && this.labelIds.indexOf(labelId) > -1) {
|
|
|
+ return this.removeLabel(labelId);
|
|
|
+ } else {
|
|
|
+ return this.addLabel(labelId);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ assignMember(memberId) {
|
|
|
+ return { $addToSet: { members: memberId }};
|
|
|
+ },
|
|
|
+
|
|
|
+ unassignMember(memberId) {
|
|
|
+ return { $pull: { members: memberId }};
|
|
|
+ },
|
|
|
+
|
|
|
+ toggleMember(memberId) {
|
|
|
+ if (this.members && this.members.indexOf(memberId) > -1) {
|
|
|
+ return this.unassignMember(memberId);
|
|
|
+ } else {
|
|
|
+ return this.assignMember(memberId);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ setCover(coverId) {
|
|
|
+ return { $set: { coverId }};
|
|
|
+ },
|
|
|
+
|
|
|
+ unsetCover() {
|
|
|
+ return { $unset: { coverId: '' }};
|
|
|
},
|
|
|
});
|
|
|
|
|
|
-CardComments.hookOptions.after.update = { fetchPrevious: false };
|
|
|
Cards.before.insert((userId, doc) => {
|
|
|
doc.createdAt = new Date();
|
|
|
doc.dateLastActivity = new Date();
|
|
|
-
|
|
|
- // defaults
|
|
|
doc.archived = false;
|
|
|
|
|
|
- // userId native set.
|
|
|
- if (!doc.userId)
|
|
|
+ if (!doc.userId) {
|
|
|
doc.userId = userId;
|
|
|
-});
|
|
|
-
|
|
|
-CardComments.before.insert((userId, doc) => {
|
|
|
- doc.createdAt = new Date();
|
|
|
- doc.userId = userId;
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
if (Meteor.isServer) {
|
|
@@ -264,21 +288,4 @@ if (Meteor.isServer) {
|
|
|
cardId: doc._id,
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
- });
|
|
|
}
|