Relay device group improvements.

Ylian Saint-Hilaire committed Apr 15, 2022 at 14:21 UTC 2bd67445dcb342bcfb3a11498a808de187afd4a5
1 file changed +19
meshuser.js
+19
@@ -1989,6 +1989,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1989 if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' created device group ' + mesh.name); }
1990
1991 try { ws.send(JSON.stringify({ action: 'createmesh', responseid: command.responseid, result: 'ok', meshid: meshid, links: links })); } catch (ex) { }
1992 +
1993 + // If needed, event that a device is now a device group relay
1994 + if (mesh.relayid != null) {
1995 + // Get the node and the rights for this node
1996 + parent.GetNodeWithRights(domain, user, mesh.relayid, function (node, rights, visible) {
1997 + if (node == null) return;
1998 + var event = { etype: 'node', userid: user._id, username: user.name, action: 'changenode', nodeid: node._id, domain: domain.id, msg: 'Is a relay for ' + mesh.name + '.', msgid: 153, msgArgs: [mesh.name], node: parent.CloneSafeNode(node) };
1999 + if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come.
2000 + parent.parent.DispatchEvent(parent.CreateNodeDispatchTargets(node.meshid, node._id, [user._id]), obj, event);
2001 + });
2002 + }
2003 });
2004 break;
2005 }
@@ -2205,6 +2216,14 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2216 if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come.
2217 parent.parent.DispatchEvent(parent.CreateNodeDispatchTargets(node.meshid, node._id, [user._id]), obj, event);
2218 });
2219 + } else if ((mesh.relayid != null) && (changesids.indexOf(1) >= 0)) {
2220 + // Notify of node name change, get the node and the rights for this node, we just want to trigger a device update.
2221 + parent.GetNodeWithRights(domain, user, mesh.relayid, function (node, rights, visible) {
2222 + if (node == null) return;
2223 + var event = { etype: 'node', userid: user._id, username: user.name, action: 'changenode', nodeid: node._id, domain: domain.id, node: parent.CloneSafeNode(node), nolog: 1 };
2224 + if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come.
2225 + parent.parent.DispatchEvent(parent.CreateNodeDispatchTargets(node.meshid, node._id, [user._id]), obj, event);
2226 + });
2227 }
2228
2229 if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'editmesh', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }