summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2020-05-13 03:07:05 +0300
committerLauri Ojansivu <x@xet7.org>2020-05-13 03:07:05 +0300
commiteece32d51b6b30f66d90ccd6a12f48eb1710ed93 (patch)
tree0d411d58b2127da87724c08a8785bb3ce6ffe377 /models
parent1fe7394d05032f65d1f8e035d6d4cf1fc41d8d35 (diff)
parent1865bdbee9ec1cf195425aed2509131ee6f19461 (diff)
downloadwekan-eece32d51b6b30f66d90ccd6a12f48eb1710ed93.tar.gz
wekan-eece32d51b6b30f66d90ccd6a12f48eb1710ed93.tar.bz2
wekan-eece32d51b6b30f66d90ccd6a12f48eb1710ed93.zip
Merge branch 'NicoP-S-master'
Diffstat (limited to 'models')
-rw-r--r--models/cards.js70
-rw-r--r--models/users.js41
2 files changed, 107 insertions, 4 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:
diff --git a/models/users.js b/models/users.js
index a1bc5b0f..1a021bb7 100644
--- a/models/users.js
+++ b/models/users.js
@@ -1240,6 +1240,25 @@ if (Meteor.isServer) {
Authentication.checkLoggedIn(req.userId);
const data = Meteor.users.findOne({ _id: req.userId });
delete data.services;
+
+ // get all boards where the user is member of
+ let boards = Boards.find(
+ {
+ type: 'board',
+ 'members.userId': req.userId,
+ },
+ {
+ fields: { _id: 1, members: 1 },
+ },
+ );
+ boards = boards.map(b => {
+ const u = b.members.find(m => m.userId === req.userId);
+ delete u.userId;
+ u.boardId = b._id;
+ return u;
+ });
+
+ data.boards = boards;
JsonRoutes.sendResult(res, {
code: 200,
data,
@@ -1292,9 +1311,29 @@ if (Meteor.isServer) {
try {
Authentication.checkUserId(req.userId);
const id = req.params.userId;
+
+ // get all boards where the user is member of
+ let boards = Boards.find(
+ {
+ type: 'board',
+ 'members.userId': id,
+ },
+ {
+ fields: { _id: 1, members: 1 },
+ },
+ );
+ boards = boards.map(b => {
+ const u = b.members.find(m => m.userId === id);
+ delete u.userId;
+ u.boardId = b._id;
+ return u;
+ });
+
+ const user = Meteor.users.findOne({ _id: id });
+ user.boards = boards;
JsonRoutes.sendResult(res, {
code: 200,
- data: Meteor.users.findOne({ _id: id }),
+ data: user,
});
} catch (error) {
JsonRoutes.sendResult(res, {