summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2019-05-09 16:37:18 +0300
committerLauri Ojansivu <x@xet7.org>2019-05-09 16:37:18 +0300
commit34b1654077c791e583c9d9dbbc4e73c910b7d373 (patch)
treeb81e1d2604eeefb4f76ebaa6c0159ab00d4bf47f /models
parent5dcd1b630e12010b186a42ab4431d410956b582b (diff)
parent7ff4067e88ed59686c86d81447fa2ce550032034 (diff)
downloadwekan-34b1654077c791e583c9d9dbbc4e73c910b7d373.tar.gz
wekan-34b1654077c791e583c9d9dbbc4e73c910b7d373.tar.bz2
wekan-34b1654077c791e583c9d9dbbc4e73c910b7d373.zip
Merge branch 'edge' into meteor-1.8
Diffstat (limited to 'models')
-rw-r--r--models/users.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/models/users.js b/models/users.js
index 3240f8de..5f949c80 100644
--- a/models/users.js
+++ b/models/users.js
@@ -238,6 +238,19 @@ Users.allow({
const user = Users.findOne(userId);
return user && Meteor.user().isAdmin;
},
+ remove(userId, doc) {
+ const adminsNumber = Users.find({ isAdmin: true }).count();
+ const { isAdmin } = Users.findOne({ _id: userId }, { fields: { 'isAdmin': 1 } });
+
+ // Prevents remove of the only one administrator
+ if (adminsNumber === 1 && isAdmin && userId === doc._id) {
+ return false;
+ }
+
+ // If it's the user or an admin
+ return userId === doc._id || isAdmin;
+ },
+ fetch: [],
});
// Search a user in the complete server database by its name or username. This
@@ -364,6 +377,10 @@ Users.helpers({
getTemplatesBoardSlug() {
return (Boards.findOne((this.profile || {}).templatesBoardId) || {}).slug;
},
+
+ remove() {
+ User.remove({ _id: this._id});
+ },
});
Users.mutations({
@@ -673,6 +690,23 @@ if (Meteor.isServer) {
}, {unique: true});
});
+ // OLD WAY THIS CODE DID WORK: When user is last admin of board,
+ // if admin is removed, board is removed.
+ // NOW THIS IS COMMENTED OUT, because other board users still need to be able
+ // to use that board, and not have board deleted.
+ // Someone can be later changed to be admin of board, by making change to database.
+ // TODO: Add UI for changing someone as board admin.
+ //Users.before.remove((userId, doc) => {
+ // Boards
+ // .find({members: {$elemMatch: {userId: doc._id, isAdmin: true}}})
+ // .forEach((board) => {
+ // // If only one admin for the board
+ // if (board.members.filter((e) => e.isAdmin).length === 1) {
+ // Boards.remove(board._id);
+ // }
+ // });
+ //});
+
// Each board document contains the de-normalized number of users that have
// starred it. If the user star or unstar a board, we need to update this
// counter.