mirror of
https://github.com/wekan/wekan.git
synced 2025-12-18 08:20:12 +01:00
Delete user feature
This commit is contained in:
parent
11a91bfc78
commit
cdef8a33e4
6 changed files with 62 additions and 2 deletions
|
|
@ -107,5 +107,8 @@ template(name="editUserPopup")
|
||||||
label
|
label
|
||||||
| {{_ 'password'}}
|
| {{_ 'password'}}
|
||||||
input.js-profile-password(type="password")
|
input.js-profile-password(type="password")
|
||||||
|
div.buttonsContainer
|
||||||
input.primary.wide(type="submit" value="{{_ 'save'}}")
|
input.primary.wide(type="submit" value="{{_ 'save'}}")
|
||||||
|
div
|
||||||
|
input#deleteButton.primary.wide(type="button" value="{{_ 'delete'}}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ Template.peopleRow.helpers({
|
||||||
|
|
||||||
Template.editUserPopup.onCreated(function() {
|
Template.editUserPopup.onCreated(function() {
|
||||||
this.authenticationMethods = new ReactiveVar([]);
|
this.authenticationMethods = new ReactiveVar([]);
|
||||||
|
this.errorMessage = new ReactiveVar('');
|
||||||
|
|
||||||
Meteor.call('getAuthenticationsEnabled', (_, result) => {
|
Meteor.call('getAuthenticationsEnabled', (_, result) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|
@ -129,6 +130,9 @@ Template.editUserPopup.helpers({
|
||||||
const selected = Users.findOne(userId).authenticationMethod;
|
const selected = Users.findOne(userId).authenticationMethod;
|
||||||
return selected === 'ldap';
|
return selected === 'ldap';
|
||||||
},
|
},
|
||||||
|
errorMessage() {
|
||||||
|
return Template.instance().errorMessage.get();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
BlazeComponent.extendComponent({
|
BlazeComponent.extendComponent({
|
||||||
|
|
@ -220,4 +224,9 @@ Template.editUserPopup.events({
|
||||||
});
|
});
|
||||||
} else Popup.close();
|
} else Popup.close();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'click #deleteButton'() {
|
||||||
|
Users.remove(this.userId);
|
||||||
|
Popup.close();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -34,3 +34,15 @@ table
|
||||||
|
|
||||||
button
|
button
|
||||||
min-width: 60px;
|
min-width: 60px;
|
||||||
|
|
||||||
|
.content-wrapper
|
||||||
|
margin-top: 10px
|
||||||
|
|
||||||
|
.buttonsContainer
|
||||||
|
display: flex
|
||||||
|
|
||||||
|
input
|
||||||
|
margin: 0
|
||||||
|
|
||||||
|
div
|
||||||
|
margin: auto
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,10 @@ template(name="editProfilePopup")
|
||||||
input.js-profile-email(type="email" value="{{emails.[0].address}}")
|
input.js-profile-email(type="email" value="{{emails.[0].address}}")
|
||||||
else
|
else
|
||||||
input.js-profile-email(type="email" value="{{emails.[0].address}}" readonly)
|
input.js-profile-email(type="email" value="{{emails.[0].address}}" readonly)
|
||||||
|
div.buttonsContainer
|
||||||
input.primary.wide(type="submit" value="{{_ 'save'}}")
|
input.primary.wide(type="submit" value="{{_ 'save'}}")
|
||||||
|
div
|
||||||
|
input#deleteButton.primary.wide(type="button" value="{{_ 'delete'}}")
|
||||||
|
|
||||||
template(name="changePasswordPopup")
|
template(name="changePasswordPopup")
|
||||||
+atForm(state='changePwd')
|
+atForm(state='changePwd')
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,11 @@ Template.editProfilePopup.events({
|
||||||
});
|
});
|
||||||
} else Popup.back();
|
} else Popup.back();
|
||||||
},
|
},
|
||||||
|
'click #deleteButton'() {
|
||||||
|
Users.remove(Meteor.userId());
|
||||||
|
Popup.close();
|
||||||
|
AccountsTemplates.logout();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// XXX For some reason the useraccounts autofocus isnt working in this case.
|
// XXX For some reason the useraccounts autofocus isnt working in this case.
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,19 @@ Users.allow({
|
||||||
const user = Users.findOne(userId);
|
const user = Users.findOne(userId);
|
||||||
return user && Meteor.user().isAdmin;
|
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
|
// Search a user in the complete server database by its name or username. This
|
||||||
|
|
@ -364,6 +377,10 @@ Users.helpers({
|
||||||
getTemplatesBoardSlug() {
|
getTemplatesBoardSlug() {
|
||||||
return Boards.findOne(this.profile.templatesBoardId).slug;
|
return Boards.findOne(this.profile.templatesBoardId).slug;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
remove() {
|
||||||
|
User.remove({ _id: this._id});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Users.mutations({
|
Users.mutations({
|
||||||
|
|
@ -673,6 +690,17 @@ if (Meteor.isServer) {
|
||||||
}, {unique: true});
|
}, {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
|
// 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
|
// starred it. If the user star or unstar a board, we need to update this
|
||||||
// counter.
|
// counter.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue