Card vote options in new fork

This commit is contained in:
Nico 2020-05-03 00:33:15 +02:00
parent 533bc045d0
commit 3cc0a93e0e
10 changed files with 239 additions and 65 deletions

View file

@ -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: