Fixed empty notifications titles, #4155

Ylian Saint-Hilaire committed Jun 23, 2022 at 11:43 UTC af0ff0914469e75f61153df3c468a893066e6f17
2 files changed +11 -3
meshuser.js
+6 -1
@@ -2913,7 +2913,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2913 // Perform input validation
2914 try {
2915 if (common.validateStrArray(command.nodeids, 1, 256) == false) { err = "Invalid nodeids"; } // Check nodeids
2916 - else if (common.validateString(command.title, 1, 512) == false) { err = "Invalid title"; } // Check title
2916 else if (common.validateString(command.msg, 1, 4096) == false) { err = "Invalid message"; } // Check message
2917 else {
2918 var nodeids = [];
@@ -2928,6 +2927,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2927 break;
2928 }
2929
2930 + // Check the title, if needed, use a default one
2931 + if (common.validateString(command.title, 1, 512) == false) { delete command.title } // Check title
2932 + if ((command.title == null) && (typeof domain.notificationmessages == 'object') && (typeof domain.notificationmessages.title == 'string')) { command.title = domain.notificationmessages.title; }
2933 + if ((command.title == null) && (typeof domain.title == 'string')) { command.title = domain.title; }
2934 + if (command.title == null) { command.title = "MeshCentral"; }
2935 +
2936 for (i in command.nodeids) {
2937 // Get the node and the rights for this node
2938 parent.GetNodeWithRights(domain, user, command.nodeids[i], function (node, rights, visible) {
views/default.handlebars
+5 -2
@@ -5551,6 +5551,7 @@
5551 var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, chkNodeIds = getCheckedDevices();
5552 if (msg.length == 0) return;
5553 if (title == '') { title = decodeURIComponent('{{{extitle}}}'); }
5554 + if (title == '') { title = "MeshCentral"; }
5555 if (op == 1) { // MessageBox
5556 for (var i = 0; i < chkNodeIds.length; i++) { meshserver.send({ action: 'msg', type: 'messagebox', nodeid: chkNodeIds[i], title: title, msg: msg }); }
5557 } else if (op == 2) { // Toast
@@ -7599,10 +7600,12 @@
7600 }
7601
7602 function deviceMessageFunctionEx() {
7603 + var title = decodeURIComponent('{{{extitle}}}');
7604 + if (title == '') { title = "MeshCentral"; }
7605 if (currentNode.pmt == 1) {
7603 - meshserver.send({ action: 'pushmessage', nodeid: currentNode._id, title: decodeURIComponent('{{{extitle}}}'), msg: Q('d2devMessage').value });
7606 + meshserver.send({ action: 'pushmessage', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value });
7607 } else {
7605 - meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: decodeURIComponent('{{{extitle}}}'), msg: Q('d2devMessage').value });
7608 + meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value });
7609 }
7610 }
7611