mirror of
https://github.com/wekan/wekan.git
synced 2025-12-22 02:10:12 +01:00
commit
c850669777
6 changed files with 62 additions and 2 deletions
|
|
@ -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,17 @@ if (Meteor.isServer) {
|
|||
}, {unique: true});
|
||||
});
|
||||
|
||||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue