fix usergroup links not being removed correctly #7198

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458
2025-08-01 14:44:53 +01:00
parent 27472852a2
commit 5c5bcb4152
5 changed files with 1539 additions and 1478 deletions

14
db.js
View File

@@ -261,6 +261,20 @@ module.exports.CreateDB = function (parent, func) {
if (obj.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
parent.DispatchEvent(targets, obj, event);
}
} else if (i.startsWith('ugrp/')) {
var cusergroup = parent.userGroups[i];
if ((cusergroup != null) && (cusergroup.links != null) && (cusergroup.links[node._id] != null)) {
// Remove the user link & save the user
delete cusergroup.links[node._id];
if (Object.keys(cusergroup.links).length == 0) { delete cusergroup.links; }
obj.Set(cusergroup);
// Notify user change
var targets = ['*', 'server-users', cusergroup._id];
var event = { etype: 'ugrp', ugrpid: cusergroup._id, name: cusergroup.name, desc: cusergroup.desc, action: 'usergroupchange', links: cusergroup.links, msgid: 163, msgArgs: [node.name, cusergroup.name], msg: 'Removed device ' + node.name + ' from user group ' + cusergroup.name };
if (obj.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
parent.DispatchEvent(targets, obj, event);
}
}
}
}