Almost done with per-device notifications.
Ylian Saint-Hilaire committed
Oct 14, 2021 at 16:57 UTC
2a363c0f60c616e6bb0f53309b9677026873e8aa
2 files changed
+104
-2
meshuser.js
+43
@@ -2150,6 +2150,49 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2150
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.
2151
parent.parent.DispatchEvent(targets, obj, event);
2152
2153
+ break;
2154
+ }
2155
+ case 'changeusernotify':
2156
+ {
2157
+ if ((user.siteadmin != 0xFFFFFFFF) && ((user.siteadmin & 1024) != 0)) return; // If this account is settings locked, return here.
2158
+
2159
+ // 2 = WebPage device connections
2160
+ // 4 = WebPage device disconnections
2161
+ // 8 = WebPage device desktop and serial events
2162
+ // 16 = Email device connections
2163
+ // 32 = Email device disconnections
2164
+
2165
+ var err = null;
2166
+ try {
2167
+ // Change the current user's notification flags for a meshid
2168
+ if (common.validateString(command.nodeid, 1, 1024) == false) { err = 'Invalid device identifier'; } // Check the meshid
2169
+ else if (command.nodeid.indexOf('/') == -1) { command.nodeid = 'node/' + domain.id + '/' + command.nodeid; }
2170
+ if (common.validateInt(command.notify) == false) { err = 'Invalid notification flags'; }
2171
+ //if (parent.IsMeshViewable(user, command.nodeid) == false) err = 'Access denied';
2172
+ } catch (ex) { err = 'Validation exception: ' + ex; }
2173
+
2174
+ // Handle any errors
2175
+ if (err != null) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'changeusernotify', responseid: command.responseid, result: err })); } catch (ex) { } } break; }
2176
+
2177
+ // Check if nothing has changed
2178
+ if ((user.notify == null) && (command.notify == 0)) return;
2179
+ if ((user.notify != null) && (user.notify[command.nodeid] == command.notify)) return;
2180
+
2181
+ // Change the notification
2182
+ if (user.notify == null) { user.notify = {}; }
2183
+ if (command.notify == 0) { delete user.notify[command.nodeid]; } else { user.notify[command.nodeid] = command.notify; }
2184
+ if (Object.keys(user.notify).length == 0) { delete user.notify; }
2185
+
2186
+ // Save the user
2187
+ parent.db.SetUser(user);
2188
+
2189
+ // Notify change
2190
+ var targets = ['*', 'server-users', user._id];
2191
+ if (user.groups) { for (var i in user.groups) { targets.push('server-users:' + i); } }
2192
+ var event = { etype: 'user', userid: user._id, username: user.name, account: parent.CloneSafeUser(user), action: 'accountchange', msgid: 130, msg: 'User notifications changed', domain: domain.id };
2193
+ 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.
2194
+ parent.parent.DispatchEvent(targets, obj, event);
2195
+
2196
break;
2197
}
2198
case 'changepassword':
views/default.handlebars
+61
-2
@@ -2912,6 +2912,7 @@
2912
delete users[message.event.account._id]; // No longer part of our groups, remove this user.
2913
}
2914
2915
+ if (currentNode) { refreshDevice(currentNode._id); }
2916
mainUpdate(4 | 16384);
2917
break;
2918
}
@@ -3213,6 +3214,12 @@
3214
n |= userinfo.links[message.event.meshid].notify;
3215
}
3216
3217
+ // Per-user notification settings
3218
+ if (userinfo.notify != null) {
3219
+ if (userinfo.notify[message.event.meshid] != null) { n |= userinfo.notify[message.event.meshid]; }
3220
+ if (userinfo.notify[message.event.nodeid] != null) { n |= userinfo.notify[message.event.nodeid]; }
3221
+ }
3222
+
3223
// Show the notification
3224
if (n & 2) {
3225
var agentPrivilages = "Agent connected";
@@ -6722,9 +6729,24 @@
6729
x += addDeviceAttribute("User Consent", addLinkConditional(meshFeatures, 'p20editmeshconsent(3)', meshrights & 1));
6730
}
6731
6732
+ var devNotifyStr = [];
6733
+ if ((userinfo.notify != null) && (userinfo.notify[node._id] != null)) {
6734
+ var devNotify = userinfo.notify[node._id];
6735
+ if (devNotify & 2) { devNotifyStr.push("Connect"); }
6736
+ if (devNotify & 4) { devNotifyStr.push("Disconnect"); }
6737
+ if ((node.intelamt != null) && (devNotify & 8)) { devNotifyStr.push("Intel® AMT"); }
6738
+ if ((features2 & 0x00004000) && (userinfo.emailVerified)) {
6739
+ if (devNotify & 16) { devNotifyStr.push("Email Connect"); }
6740
+ if (devNotify & 32) { devNotifyStr.push("Email Disconnect"); }
6741
+ }
6742
+ }
6743
+ devNotifyStr = devNotifyStr.join(', ');
6744
+ if (devNotifyStr == '') { devNotifyStr = '<i>' + "None" + '</i>'; }
6745
+ x += addDeviceAttribute("Notifications", addLink(devNotifyStr, 'p20editDeviceNotify()'));
6746
+
6747
// Attribute: Connectivity (Only show this if more than just the agent is connected).
6748
var connectivity = node.conn;
6727
- if (connectivity && connectivity > 1) {
6749
+ if (connectivity && (connectivity > 1)) {
6750
var cstate = [];
6751
if ((node.conn & 1) != 0) cstate.push('<span title="' + "Mesh agent is connected and ready for use." + '">' + "Mesh Agent" + '</span>');
6752
if ((node.conn & 2) != 0) cstate.push('<span title="' + "Intel® AMT CIRA is connected and ready for use." + '">' + "Intel® AMT CIRA" + '</span>');
@@ -7056,6 +7078,42 @@
7078
go(panel);
7079
}
7080
7081
+ function p20editDeviceNotify() {
7082
+ if (xxdialogMode) return false;
7083
+ var devNotify = 0, fx = ((features2 & 0x00004000) && (userinfo.emailVerified))?1:0;
7084
+ if (userinfo.notify && userinfo.notify[currentNode._id]) { devNotify = userinfo.notify[currentNode._id]; }
7085
+ var x = '<div style="border-bottom: 1px solid #888;margin-bottom:3px">Web Page Notifications</div>';
7086
+ x += '<div><label><input id=p20notifyIntelDeviceConnect type=checkbox />' + "Device connections" + '</label></div>';
7087
+ x += '<div><label><input id=p20notifyIntelDeviceDisconnect type=checkbox />' + "Device disconnections" + '</label></div>';
7088
+ if (currentNode.intelamt != null) { fx += 2; x += '<div><label><input id=p20notifyIntelAmtKvmActions type=checkbox />' + "Intel® AMT desktop and serial events" + '</label></div>'; }
7089
+ if (fx & 1) {
7090
+ x += '<br /><div style="border-bottom: 1px solid #888;margin-bottom:3px">Email Notifications</div>';
7091
+ x += '<div><label><input id=p20enotifyIntelDeviceConnect type=checkbox />' + "Device connections" + '</label></div>';
7092
+ x += '<div><label><input id=p20enotifyIntelDeviceDisconnect type=checkbox />' + "Device disconnections" + '</label></div>';
7093
+ }
7094
+ setDialogMode(2, "Notification Settings", 3, p20editDeviceNotifyEx, x, fx);
7095
+ Q('p20notifyIntelDeviceConnect').checked = (devNotify & 2);
7096
+ Q('p20notifyIntelDeviceDisconnect').checked = (devNotify & 4);
7097
+ if (fx & 2) { Q('p20notifyIntelAmtKvmActions').checked = (devNotify & 8); }
7098
+ if (fx & 1) {
7099
+ Q('p20enotifyIntelDeviceConnect').checked = (devNotify & 16);
7100
+ Q('p20enotifyIntelDeviceDisconnect').checked = (devNotify & 32);
7101
+ }
7102
+ return false;
7103
+ }
7104
+
7105
+ function p20editDeviceNotifyEx(b, fx) {
7106
+ var devNotify = 0;
7107
+ devNotify += Q('p20notifyIntelDeviceConnect').checked ? 2 : 0;
7108
+ devNotify += Q('p20notifyIntelDeviceDisconnect').checked ? 4 : 0;
7109
+ if (fx & 2) { devNotify += Q('p20notifyIntelAmtKvmActions').checked ? 8 : 0; }
7110
+ if (fx & 1) {
7111
+ devNotify += Q('p20enotifyIntelDeviceConnect').checked ? 16 : 0;
7112
+ devNotify += Q('p20enotifyIntelDeviceDisconnect').checked ? 32 : 0;
7113
+ }
7114
+ meshserver.send({ action: 'changeusernotify', nodeid: currentNode._id, notify: devNotify });
7115
+ }
7116
+
7117
function makeUserDeviceRightsString(rights) {
7118
if (rights == 57592) { return "Full Device Rights"; }
7119
var str = [];
@@ -12937,7 +12995,8 @@
12995
126: "Left Web-VNC session after {0} second(s).",
12996
127: "Changed account display name to {0}.",
12997
128: "Account created, name is {0}.",
12940
- 129: "Removed account display name."
12998
+ 129: "Removed account display name.",
12999
+ 130: "User notifications changed"
13000
};
13001
13002
// Highlights the device being hovered