mirror of
https://github.com/wekan/wekan.git
synced 2025-12-17 07:50:12 +01:00
Added update all user profile from admin panel
This commit is contained in:
parent
e3b7f85cc3
commit
fa1d8cd5ef
2 changed files with 81 additions and 59 deletions
|
|
@ -89,22 +89,25 @@ Template.editUserPopup.events({
|
||||||
const username = tpl.find('.js-profile-username').value.trim();
|
const username = tpl.find('.js-profile-username').value.trim();
|
||||||
const initials = tpl.find('.js-profile-initials').value.trim();
|
const initials = tpl.find('.js-profile-initials').value.trim();
|
||||||
const isAdmin = tpl.find('.js-profile-isadmin').value.trim();
|
const isAdmin = tpl.find('.js-profile-isadmin').value.trim();
|
||||||
|
const isActive = tpl.find('.js-profile-isactive').value.trim();
|
||||||
const email = tpl.find('.js-profile-email').value.trim();
|
const email = tpl.find('.js-profile-email').value.trim();
|
||||||
console.log('isAdmin', isAdmin);
|
|
||||||
let isChangeUserName = false;
|
let isChangeUserName = false;
|
||||||
let isChangeEmail = false;
|
let isChangeEmail = false;
|
||||||
|
|
||||||
Users.update(this.userId, {
|
Users.update(this.userId, {
|
||||||
$set: {
|
$set: {
|
||||||
'profile.fullname': fullname,
|
'profile.fullname': fullname,
|
||||||
'profile.initials': initials,
|
'profile.initials': initials,
|
||||||
'isAdmin': true,
|
'isAdmin': isAdmin === 'true',
|
||||||
|
'loginDisabled': isActive === 'true',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
isChangeUserName = username !== user.username;
|
isChangeUserName = username !== user.username;
|
||||||
isChangeEmail = email.toLowerCase() !== user.emails[0].address.toLowerCase();
|
isChangeEmail = email.toLowerCase() !== user.emails[0].address.toLowerCase();
|
||||||
|
|
||||||
if (isChangeUserName && isChangeEmail) {
|
if (isChangeUserName && isChangeEmail) {
|
||||||
Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), function (error) {
|
Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), this.userId, function (error) {
|
||||||
const usernameMessageElement = tpl.$('.username-taken');
|
const usernameMessageElement = tpl.$('.username-taken');
|
||||||
const emailMessageElement = tpl.$('.email-taken');
|
const emailMessageElement = tpl.$('.email-taken');
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
@ -119,29 +122,35 @@ Template.editUserPopup.events({
|
||||||
} else {
|
} else {
|
||||||
usernameMessageElement.hide();
|
usernameMessageElement.hide();
|
||||||
emailMessageElement.hide();
|
emailMessageElement.hide();
|
||||||
Popup.back();
|
Popup.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (isChangeUserName) {
|
} else if (isChangeUserName) {
|
||||||
Meteor.call('setUsername', username, function (error) {
|
Meteor.call('setUsername', username, this.userId, function (error) {
|
||||||
const messageElement = tpl.$('.username-taken');
|
const usernameMessageElement = tpl.$('.username-taken');
|
||||||
if (error) {
|
if (error) {
|
||||||
messageElement.show();
|
const errorElement = error.error;
|
||||||
|
if (errorElement === 'username-already-taken') {
|
||||||
|
usernameMessageElement.show();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
messageElement.hide();
|
usernameMessageElement.hide();
|
||||||
Popup.back();
|
Popup.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (isChangeEmail) {
|
} else if (isChangeEmail) {
|
||||||
Meteor.call('setEmail', email.toLowerCase(), function (error) {
|
Meteor.call('setEmail', email.toLowerCase(), this.userId, function (error) {
|
||||||
const messageElement = tpl.$('.email-taken');
|
const emailMessageElement = tpl.$('.email-taken');
|
||||||
if (error) {
|
if (error) {
|
||||||
messageElement.show();
|
const errorElement = error.error;
|
||||||
|
if (errorElement === 'email-already-taken') {
|
||||||
|
emailMessageElement.show();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
messageElement.hide();
|
emailMessageElement.hide();
|
||||||
Popup.back();
|
Popup.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else Popup.back();
|
} else Popup.close();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,13 @@ Users.attachSchema(new SimpleSchema({
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
Users.allow({
|
||||||
|
update(userId) {
|
||||||
|
const user = Users.findOne(userId);
|
||||||
|
return user && Meteor.user().isAdmin;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// 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
|
||||||
// is used for instance to add a new user to a board.
|
// is used for instance to add a new user to a board.
|
||||||
const searchInFields = ['username', 'profile.fullname'];
|
const searchInFields = ['username', 'profile.fullname'];
|
||||||
|
|
@ -458,7 +465,11 @@ if (Meteor.isServer) {
|
||||||
if (!options || !options.profile) {
|
if (!options || !options.profile) {
|
||||||
throw new Meteor.Error('error-invitation-code-blank', 'The invitation code is required');
|
throw new Meteor.Error('error-invitation-code-blank', 'The invitation code is required');
|
||||||
}
|
}
|
||||||
const invitationCode = InvitationCodes.findOne({ code: options.profile.invitationcode, email: options.email, valid: true });
|
const invitationCode = InvitationCodes.findOne({
|
||||||
|
code: options.profile.invitationcode,
|
||||||
|
email: options.email,
|
||||||
|
valid: true
|
||||||
|
});
|
||||||
if (!invitationCode) {
|
if (!invitationCode) {
|
||||||
throw new Meteor.Error('error-invitation-code-not-exist', 'The invitation code doesn\'t exist');
|
throw new Meteor.Error('error-invitation-code-not-exist', 'The invitation code doesn\'t exist');
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -493,6 +504,7 @@ if (Meteor.isServer) {
|
||||||
function getStarredBoardsIds(doc) {
|
function getStarredBoardsIds(doc) {
|
||||||
return doc.profile && doc.profile.starredBoards;
|
return doc.profile && doc.profile.starredBoards;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldIds = getStarredBoardsIds(this.previous);
|
const oldIds = getStarredBoardsIds(this.previous);
|
||||||
const newIds = getStarredBoardsIds(user);
|
const newIds = getStarredBoardsIds(user);
|
||||||
|
|
||||||
|
|
@ -504,6 +516,7 @@ if (Meteor.isServer) {
|
||||||
Boards.update(boardId, {$inc: {stars: inc}});
|
Boards.update(boardId, {$inc: {stars: inc}});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
incrementBoards(_.difference(oldIds, newIds), -1);
|
incrementBoards(_.difference(oldIds, newIds), -1);
|
||||||
incrementBoards(_.difference(newIds, oldIds), +1);
|
incrementBoards(_.difference(newIds, oldIds), +1);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue