summaryrefslogtreecommitdiffstats
path: root/models/cards.js
diff options
context:
space:
mode:
authorRomulus Tsai 蔡仲明 <urakagi@gmail.com>2020-05-14 16:47:05 +0800
committerRomulus Tsai 蔡仲明 <urakagi@gmail.com>2020-05-14 16:47:05 +0800
commit0735981366047dd9ac41defe5e9fc5f9c4d7e913 (patch)
treeabf05428dc79dba2d3dd82a4f5c33c0becfd507d /models/cards.js
parent09ce3e464fd609b3ecc8bec5263ab06093c3a442 (diff)
parent5d8cca40d217b6a3895f1f6eb154b6aba9576b37 (diff)
downloadwekan-0735981366047dd9ac41defe5e9fc5f9c4d7e913.tar.gz
wekan-0735981366047dd9ac41defe5e9fc5f9c4d7e913.tar.bz2
wekan-0735981366047dd9ac41defe5e9fc5f9c4d7e913.zip
Merge branch 'master' into lib-change
Diffstat (limited to 'models/cards.js')
-rw-r--r--models/cards.js87
1 files changed, 83 insertions, 4 deletions
diff --git a/models/cards.js b/models/cards.js
index ae52ff04..f4bb464c 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -340,6 +340,10 @@ Cards.attachSchema(
type: Boolean,
defaultValue: false,
},
+ 'vote.allowNonBoardMembers': {
+ type: Boolean,
+ defaultValue: false,
+ },
}),
);
@@ -347,8 +351,14 @@ Cards.allow({
insert(userId, doc) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
},
- update(userId, doc) {
- return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+
+ update(userId, doc, fields) {
+ // Allow board members or logged in users if only vote get's changed
+ return (
+ allowIsBoardMember(userId, Boards.findOne(doc.boardId)) ||
+ (_.isEqual(fields, ['vote', 'modifiedAt', 'dateLastActivity']) &&
+ !!userId)
+ );
},
remove(userId, doc) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
@@ -432,6 +442,21 @@ Cards.helpers({
return _id;
},
+ link(boardId, swimlaneId, listId) {
+ // TODO is there a better method to create a deepcopy?
+ linkCard = JSON.parse(JSON.stringify(this));
+ // TODO is this how it is meant to be?
+ linkCard.linkedId = linkCard.linkedId || linkCard._id;
+ linkCard.boardId = boardId;
+ linkCard.swimlaneId = swimlaneId;
+ linkCard.listId = listId;
+ linkCard.type = 'cardType-linkedCard';
+ delete linkCard._id;
+ // TODO shall we copy the labels for a linked card?!
+ delete linkCard.labelIds;
+ return Cards.insert(linkCard);
+ },
+
list() {
return Lists.findOne(this.listId);
},
@@ -1053,6 +1078,29 @@ Cards.helpers({
}
},
+ getVoteEnd() {
+ if (this.isLinkedCard()) {
+ const card = Cards.findOne({ _id: this.linkedId });
+ if (card && card.vote) return card.vote.end;
+ else return null;
+ } else if (this.isLinkedBoard()) {
+ const board = Boards.findOne({ _id: this.linkedId });
+ if (board && board.vote) return board.vote.end;
+ else return null;
+ } else if (this.vote) {
+ return this.vote.end;
+ } else {
+ return null;
+ }
+ },
+ expiredVote() {
+ let end = this.getVoteEnd();
+ if (end) {
+ end = moment(end);
+ return end.isBefore(new Date());
+ }
+ return false;
+ },
voteMemberPositive() {
if (this.vote && this.vote.positive)
return Users.find({ _id: { $in: this.vote.positive } });
@@ -1158,6 +1206,26 @@ Cards.helpers({
isTemplateCard() {
return this.type === 'template-card';
},
+
+ votePublic() {
+ if (this.vote) return this.vote.public;
+ return null;
+ },
+ voteAllowNonBoardMembers() {
+ if (this.vote) return this.vote.allowNonBoardMembers;
+ return null;
+ },
+ voteCountNegative() {
+ if (this.vote && this.vote.negative) return this.vote.negative.length;
+ return null;
+ },
+ voteCountPositive() {
+ if (this.vote && this.vote.positive) return this.vote.positive.length;
+ return null;
+ },
+ voteCount() {
+ return this.voteCountPositive() + this.voteCountNegative();
+ },
});
Cards.mutations({
@@ -1481,12 +1549,13 @@ Cards.mutations({
},
};
},
- setVoteQuestion(question, publicVote) {
+ setVoteQuestion(question, publicVote, allowNonBoardMembers) {
return {
$set: {
vote: {
question,
public: publicVote,
+ allowNonBoardMembers,
positive: [],
negative: [],
},
@@ -1500,6 +1569,16 @@ Cards.mutations({
},
};
},
+ setVoteEnd(end) {
+ return {
+ $set: { 'vote.end': end },
+ };
+ },
+ unsetVoteEnd() {
+ return {
+ $unset: { 'vote.end': '' },
+ };
+ },
setVote(userId, forIt) {
switch (forIt) {
case true:
@@ -2161,7 +2240,7 @@ if (Meteor.isServer) {
const check = Users.findOne({
_id: req.body.authorId,
});
- const members = req.body.members || [req.body.authorId];
+ const members = req.body.members;
const assignees = req.body.assignees;
if (typeof check !== 'undefined') {
const id = Cards.direct.insert({