diff options
author | Romulus Tsai 蔡仲明 <urakagi@gmail.com> | 2020-05-14 16:45:21 +0800 |
---|---|---|
committer | Romulus Tsai 蔡仲明 <urakagi@gmail.com> | 2020-05-14 16:45:21 +0800 |
commit | 5d8cca40d217b6a3895f1f6eb154b6aba9576b37 (patch) | |
tree | 697e686168f41fef0da5903722bbda98e17d0ff0 /models/cards.js | |
parent | cfcc73724fcd394150d1b815d0a7a4c466e216b5 (diff) | |
parent | 9c6cd51ca720502cc993451505f95a43ef16a707 (diff) | |
download | wekan-5d8cca40d217b6a3895f1f6eb154b6aba9576b37.tar.gz wekan-5d8cca40d217b6a3895f1f6eb154b6aba9576b37.tar.bz2 wekan-5d8cca40d217b6a3895f1f6eb154b6aba9576b37.zip |
Merge branch 'master' of https://github.com/wekan/wekan
Diffstat (limited to 'models/cards.js')
-rw-r--r-- | models/cards.js | 87 |
1 files changed, 83 insertions, 4 deletions
diff --git a/models/cards.js b/models/cards.js index 4197f7ab..aace2647 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)); @@ -428,6 +438,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); }, @@ -1048,6 +1073,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 } }); @@ -1153,6 +1201,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({ @@ -1476,12 +1544,13 @@ Cards.mutations({ }, }; }, - setVoteQuestion(question, publicVote) { + setVoteQuestion(question, publicVote, allowNonBoardMembers) { return { $set: { vote: { question, public: publicVote, + allowNonBoardMembers, positive: [], negative: [], }, @@ -1495,6 +1564,16 @@ Cards.mutations({ }, }; }, + setVoteEnd(end) { + return { + $set: { 'vote.end': end }, + }; + }, + unsetVoteEnd() { + return { + $unset: { 'vote.end': '' }, + }; + }, setVote(userId, forIt) { switch (forIt) { case true: @@ -2156,7 +2235,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({ |