Added remove previous events selector when adding a new user.

Ylian Saint-Hilaire committed Dec 26, 2019 at 13:52 UTC ffb10a82be74a5f149a41d620b1e8e307691848b
3 files changed +10 -1
db.js
+2
@@ -713,6 +713,7 @@ module.exports.CreateDB = function (parent, func) {
713 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); };
714 obj.RemoveAllEvents = function (domain) { obj.eventsfile.deleteMany({ domain: domain }, { multi: true }); };
715 obj.RemoveAllNodeEvents = function (domain, nodeid) { obj.eventsfile.deleteMany({ domain: domain, nodeid: nodeid }, { multi: true }); };
716 + obj.RemoveAllUserEvents = function (domain, userid) { obj.eventsfile.deleteMany({ domain: domain, userid: userid }, { multi: true }); };
717 obj.GetFailedLoginCount = function (username, domainid, lastlogin, func) {
718 if (obj.eventsfile.countDocuments) {
719 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) {
847 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); } };
848 obj.RemoveAllEvents = function (domain) { obj.eventsfile.remove({ domain: domain }, { multi: true }); };
849 obj.RemoveAllNodeEvents = function (domain, nodeid) { obj.eventsfile.remove({ domain: domain, nodeid: nodeid }, { multi: true }); };
850 + obj.RemoveAllUserEvents = function (domain, userid) { obj.eventsfile.remove({ domain: domain, userid: userid }, { multi: true }); };
851 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); }); }
852
853 // Database actions on the power collection
meshuser.js
+3
@@ -1396,6 +1396,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1396 // TODO: Notify all sessions on other peers.
1397 }
1398 } else {
1399 + // Remove any events for this userid
1400 + if (command.removeEvents === true) { db.RemoveAllUserEvents(domain.id, newuserid); }
1401 +
1402 // Create a new user
1403 var newuser = { type: 'user', _id: newuserid, name: newusername, creation: Math.floor(Date.now() / 1000), domain: domain.id };
1404 if (command.siteadmin != null) { newuser.siteadmin = command.siteadmin; }
views/default.handlebars
+5 -1
@@ -1316,6 +1316,8 @@
1316 QS('p43iframe')['max-height'] = 'calc(100vh - ' + (84 + xh) + 'px)';
1317 QS('p16events')['height'] = 'calc(100vh - ' + (50 + xh + xh2) + 'px)';
1318 QS('p16events')['max-height'] = 'calc(100vh - ' + (50 + xh + xh2) + 'px)';
1319 + QS('p31events')['height'] = 'calc(100vh - ' + (50 + xh + xh2) + 'px)';
1320 + QS('p31events')['max-height'] = 'calc(100vh - ' + (50 + xh + xh2) + 'px)';
1321 QS('p41events')['height'] = 'calc(100vh - ' + (48 + xh + xh2) + 'px)';
1322 QS('p41events')['max-height'] = 'calc(100vh - ' + (48 + xh + xh2) + 'px)';
1323
@@ -8801,6 +8803,7 @@
8803 x += addHtmlValue("Password", '<input id=p4pass2 type=password maxlength=256 onchange=showCreateNewAccountDialogValidate() onkeyup=showCreateNewAccountDialogValidate() />');
8804 x += '<div><label><input id=p4randomPassword onchange=showCreateNewAccountDialogValidate() type=checkbox />' + "Randomize the password." + '</label></div>';
8805 x += '<div><label><input id=p4resetNextLogin onchange=showCreateNewAccountDialogValidate() type=checkbox />' + "Force password reset on next login." + '</label></div>';
8806 + x += '<div><label><input id=p4removeEvents onchange=showCreateNewAccountDialogValidate() type=checkbox />' + "Remove all previous events for this userid." + '</label></div>';
8807 if (serverinfo.emailcheck) {
8808 x += '<div><label><input id=p4verifiedEmail onchange=showCreateNewAccountDialogValidate() type=checkbox />' + "Email is verified." + '</label></div>';
8809 x += '<div><label><input id=p4invitationEmail type=checkbox />' + "Send invitation email." + '</label></div>';
@@ -8838,7 +8841,7 @@
8841
8842 function showCreateNewAccountDialogEx() {
8843 var username = ((features & 0x200000) == 0) ? Q('p4name').value : Q('p4email').value; // Username is email address
8841 - var x = { action: 'adduser', username: username, email: Q('p4email').value, pass: Q('p4pass1').value, resetNextLogin: Q('p4resetNextLogin').checked, randomPassword: Q('p4randomPassword').checked };
8844 + 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 };
8845 if (serverinfo.emailcheck) {
8846 x.emailVerified = Q('p4verifiedEmail').checked;
8847 x.emailInvitation = Q('p4invitationEmail').checked;
@@ -9188,6 +9191,7 @@
9191
9192 var currentUserEvents = null;
9193 function userEventsUpdate() {
9194 + if (currentUser == null) return;
9195 var x = '', dateHeader = null;
9196 for (var i in currentUserEvents) {
9197 var event = currentUserEvents[i], time = new Date(event.time);