diff options
Diffstat (limited to 'models/cards.js')
-rw-r--r-- | models/cards.js | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/models/cards.js b/models/cards.js index 4197f7ab..b0783898 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)); @@ -1048,6 +1058,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 +1186,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 +1529,13 @@ Cards.mutations({ }, }; }, - setVoteQuestion(question, publicVote) { + setVoteQuestion(question, publicVote, allowNonBoardMembers) { return { $set: { vote: { question, public: publicVote, + allowNonBoardMembers, positive: [], negative: [], }, @@ -1495,6 +1549,16 @@ Cards.mutations({ }, }; }, + setVoteEnd(end) { + return { + $set: { 'vote.end': end }, + }; + }, + unsetVoteEnd() { + return { + $unset: { 'vote.end': '' }, + }; + }, setVote(userId, forIt) { switch (forIt) { case true: |