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);
}
}
}
}

View File

@ -2847,6 +2847,21 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
parent.parent.DispatchEvent(targets, obj, event);
}
} else if (i.startsWith('ugrp/')) {
var cusergroup = parent.userGroups[i];
console.log(cusergroup);
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; }
db.Set(cusergroup);
// Notify user change
var targets = ['*', 'server-users', cusergroup._id];
var event = { etype: 'ugrp', userid: user._id, username: user.name, 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 (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
parent.parent.DispatchEvent(targets, obj, event);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -15411,7 +15411,8 @@
159: "Device Powered On",
160: "Enabled Duo two-factor authentication",
161: "Disabled Duo two-factor authentication",
162: "Started messenger session \"{0}\" from {1} to {2}"
162: "Started messenger session \"{0}\" from {1} to {2}",
163: "Removed device {0} from user group {1}"
};
var eventsShortMessageId = {

View File

@ -16569,7 +16569,8 @@
159: "Device Powered On",
160: "Enabled Duo two-factor authentication",
161: "Disabled Duo two-factor authentication",
162: "Started messenger session \"{0}\" from {1} to {2}"
162: "Started messenger session \"{0}\" from {1} to {2}",
163: "Removed device {0} from user group {1}"
};
var eventsShortMessageId = {