I have a users table where the site permissions are set using an integer variable in a field userLevel.
The userLevel is set from a select list, superadmin=1, admin=2, member=3, contact=4.
The admin pages are accessible by userLevels 1 and 2
I have ensured that if superadmin is logged in, all items in the select list are available, but if admin is logged in, they can only set user levels of admin and below.
Problem comes with an admin editing a superadmin user, as I don't want the admin to be able to to change userlevel above their own, and this is compounded by the fact that the superadmin option is not available in the admin select list.
I feel my best option would be to check the existing userLevel and if it is 1, re-set it to 1 on preEdit.
I can successfully detect the existing user level, but cannot work out how to update the value
var existingUserLevel;
editor
.on( 'initEdit', function ( e, node, data ) {
existingUserLevel = data.contacts.UserLevel;
})
.on( 'preEdit', function ( e, json, data ) {
selectedlevel = data.contacts.UserLevel;
console.log(existingUserLevel);
console.log(selectedlevel);
if (existingUserLevel == 1) {
data.contacts.UserLevel = 1;
console.log('is a super admin, do nothing');
} else {
console.log('not a super admin, so update');
data.contacts.UserLevel = selectedlevel;
}
});