Browse Source

If role doesn't change, say that

theflametrooper 8 năm trước cách đây
mục cha
commit
8a2489054c
1 tập tin đã thay đổi với 11 bổ sung0 xóa
  1. 11 0
      backend/logic/actions/users.js

+ 11 - 0
backend/logic/actions/users.js

@@ -470,9 +470,20 @@ module.exports = {
 	updateRole: hooks.adminRequired((session, updatingUserId, newRole, cb, userId) => {
 		newRole = newRole.toLowerCase();
 		async.waterfall([
+
+			(next) => {
+				db.models.user.findOne({ _id: updatingUserId }, next);
+			},
+
+			(user, next) => {
+				if (!user) return next('User not found.');
+				else if (user.role === newRole) return next('New role can\'t be the same as the old role.');
+				else return next();
+			},
 			(next) => {
 				db.models.user.update({_id: updatingUserId}, {$set: {role: newRole}}, next);
 			}
+
 		], (err) => {
 			if (err && err !== true) {
 				let error = 'An error occurred.';