From ffb10a82be74a5f149a41d620b1e8e307691848b Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 26 Dec 2019 13:52:09 -0800 Subject: [PATCH] Added remove previous events selector when adding a new user. --- db.js | 2 ++ meshuser.js | 3 +++ views/default.handlebars | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/db.js b/db.js index ba834051..3954f409 100644 --- a/db.js +++ b/db.js @@ -713,6 +713,7 @@ module.exports.CreateDB = function (parent, func) { obj.GetNodeEventsSelfWithLimit = function (nodeid, domain, userid, limit, func) { obj.eventsfile.find({ domain: domain, nodeid: nodeid, userid: { $in: [userid, null] } }).project({ type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit).toArray(func); }; obj.RemoveAllEvents = function (domain) { obj.eventsfile.deleteMany({ domain: domain }, { multi: true }); }; obj.RemoveAllNodeEvents = function (domain, nodeid) { obj.eventsfile.deleteMany({ domain: domain, nodeid: nodeid }, { multi: true }); }; + obj.RemoveAllUserEvents = function (domain, userid) { obj.eventsfile.deleteMany({ domain: domain, userid: userid }, { multi: true }); }; obj.GetFailedLoginCount = function (username, domainid, lastlogin, func) { if (obj.eventsfile.countDocuments) { obj.eventsfile.countDocuments({ action: 'authfail', username: username, domain: domainid, time: { "$gte": lastlogin } }, function (err, count) { func((err == null) ? count : 0); }); @@ -846,6 +847,7 @@ module.exports.CreateDB = function (parent, func) { obj.GetNodeEventsSelfWithLimit = function (nodeid, domain, userid, limit, func) { if (obj.databaseType == 1) { obj.eventsfile.find({ domain: domain, nodeid: nodeid, userid: { $in: [userid, null] } }, { type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit).exec(func); } else { obj.eventsfile.find({ domain: domain, nodeid: nodeid }, { type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit, func); } }; obj.RemoveAllEvents = function (domain) { obj.eventsfile.remove({ domain: domain }, { multi: true }); }; obj.RemoveAllNodeEvents = function (domain, nodeid) { obj.eventsfile.remove({ domain: domain, nodeid: nodeid }, { multi: true }); }; + obj.RemoveAllUserEvents = function (domain, userid) { obj.eventsfile.remove({ domain: domain, userid: userid }, { multi: true }); }; obj.GetFailedLoginCount = function (username, domainid, lastlogin, func) { obj.eventsfile.count({ action: 'authfail', username: username, domain: domainid, time: { "$gte": lastlogin } }, function (err, count) { func((err == null) ? count : 0); }); } // Database actions on the power collection diff --git a/meshuser.js b/meshuser.js index 9ffd9377..6036831d 100644 --- a/meshuser.js +++ b/meshuser.js @@ -1396,6 +1396,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // TODO: Notify all sessions on other peers. } } else { + // Remove any events for this userid + if (command.removeEvents === true) { db.RemoveAllUserEvents(domain.id, newuserid); } + // Create a new user var newuser = { type: 'user', _id: newuserid, name: newusername, creation: Math.floor(Date.now() / 1000), domain: domain.id }; if (command.siteadmin != null) { newuser.siteadmin = command.siteadmin; } diff --git a/views/default.handlebars b/views/default.handlebars index ef79e7cf..01c98e38 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1316,6 +1316,8 @@ QS('p43iframe')['max-height'] = 'calc(100vh - ' + (84 + xh) + 'px)'; QS('p16events')['height'] = 'calc(100vh - ' + (50 + xh + xh2) + 'px)'; QS('p16events')['max-height'] = 'calc(100vh - ' + (50 + xh + xh2) + 'px)'; + QS('p31events')['height'] = 'calc(100vh - ' + (50 + xh + xh2) + 'px)'; + QS('p31events')['max-height'] = 'calc(100vh - ' + (50 + xh + xh2) + 'px)'; QS('p41events')['height'] = 'calc(100vh - ' + (48 + xh + xh2) + 'px)'; QS('p41events')['max-height'] = 'calc(100vh - ' + (48 + xh + xh2) + 'px)'; @@ -8801,6 +8803,7 @@ x += addHtmlValue("Password", ''); x += '
'; x += '
'; + x += '
'; if (serverinfo.emailcheck) { x += '
'; x += '
'; @@ -8838,7 +8841,7 @@ function showCreateNewAccountDialogEx() { var username = ((features & 0x200000) == 0) ? Q('p4name').value : Q('p4email').value; // Username is email address - var x = { action: 'adduser', username: username, email: Q('p4email').value, pass: Q('p4pass1').value, resetNextLogin: Q('p4resetNextLogin').checked, randomPassword: Q('p4randomPassword').checked }; + var x = { action: 'adduser', username: username, email: Q('p4email').value, pass: Q('p4pass1').value, resetNextLogin: Q('p4resetNextLogin').checked, randomPassword: Q('p4randomPassword').checked, removeEvents: Q('p4removeEvents').checked }; if (serverinfo.emailcheck) { x.emailVerified = Q('p4verifiedEmail').checked; x.emailInvitation = Q('p4invitationEmail').checked; @@ -9188,6 +9191,7 @@ var currentUserEvents = null; function userEventsUpdate() { + if (currentUser == null) return; var x = '', dateHeader = null; for (var i in currentUserEvents) { var event = currentUserEvents[i], time = new Date(event.time);