diff --git a/meshuser.js b/meshuser.js index 4bab10ba..02ef275f 100644 --- a/meshuser.js +++ b/meshuser.js @@ -895,6 +895,15 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use if ((command.emailVerified === true || command.emailVerified === false) && (chguser.emailVerified != command.emailVerified)) { chguser.emailVerified = command.emailVerified; change = 1; } if ((common.validateInt(command.quota, 0) || command.quota == null) && (command.quota != chguser.quota)) { chguser.quota = command.quota; if (chguser.quota == null) { delete chguser.quota; } change = 1; } if ((user.siteadmin == 0xFFFFFFFF) && common.validateInt(command.siteadmin) && (chguser.siteadmin != command.siteadmin)) { chguser.siteadmin = command.siteadmin; change = 1; } + + if ((Array.isArray(command.groups)) && (user.name != command.name)) { + if (command.groups.length == 0) { + if (chguser.groups != null) { delete chguser.groups; change = 1; } + } else { + if (chguser.groups != command.groups) { chguser.groups = command.groups; change = 1; } + } + } + if (change == 1) { db.SetUser(chguser); parent.parent.DispatchEvent([chguser._id], obj, 'resubscribe'); diff --git a/views/default.handlebars b/views/default.handlebars index 2e911020..09427ecd 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -6775,6 +6775,34 @@ meshserver.send({ action: 'adduser', username: Q('p4name').value, email: Q('p4email').value, pass: Q('p4pass1').value, resetNextLogin: Q('p4resetNextLogin').checked }); } + function showUserGroupDialog(e, userid) { + if (xxdialogMode) return; + haltEvent(e); + userid = decodeURIComponent(userid); + var user = users[userid.toLowerCase()], groups = ""; + if (user.groups != null) { groups = user.groups.join(', ') } + var x = 'Enter a comma seperate list of groups.

'; + x += addHtmlValue('Groups', ''); + setDialogMode(2, "User Groups", 3, showUserGroupDialogEx, x, user); + focusTextBox('dp4usergroups'); + p4validateUserGroups(); + return false; + } + + function p4validateUserGroups() { + var groups = Q('dp4usergroups').value; + var k = 0, i = groups.indexOf('\"') + groups.indexOf('/') + groups.indexOf('>') + groups.indexOf('<') + groups.indexOf('\''); + var g = groups.split(','); + for (var j in g) { if (g[j].trim().length == 0) k++; } + QE('idx_dlgOkButton', (groups == '') || ((i == -5) && (k < 1))); + } + + function showUserGroupDialogEx(event, user) { + var groups = Q('dp4usergroups').value, g = groups.split(','), g2 = []; + for (var j in g) { var x = g[j].trim(); if (x.length > 0) { g2.push(x); } } + meshserver.send({ action: 'edituser', name: user.name, groups: g2 }); + } + function showUserAdminDialog(e, userid) { if (xxdialogMode) return; haltEvent(e); @@ -6886,6 +6914,7 @@ if (user.passchange == -1) { x += addDeviceAttribute('Password', 'Will be changed on next login.'); } else if (user.passchange) { x += addDeviceAttribute('Password', 'Last changed: ' + new Date(user.passchange * 1000).toLocaleString()); } + // Device Groups var linkCount = 0, linkCountStr = 'None'; if (user.links) { for (var i in user.links) { linkCount++; } @@ -6893,6 +6922,10 @@ } x += addDeviceAttribute('Device Groups', linkCountStr); + // User Groups + if (user.groups) { linkCountStr = EscapeHtml(user.groups.join(', ')); } else { linkCountStr = 'None'; } + x += addDeviceAttribute('User Groups', addLinkConditional(linkCountStr, 'showUserGroupDialog(event,\"' + userid + '\")', ((userinfo.groups == null) && (userinfo.siteadmin & 2) && (userinfo._id != user._id)))); + var multiFactor = 0; if ((user.otpsecret > 0) || (user.otphkeys > 0)) { multiFactor = 1;