Fix for #2663. Invitation codes are removed for deleted device groups.

This commit is contained in:
Ylian Saint-Hilaire 2021-05-21 09:01:06 -07:00
parent 76fde352f6
commit 29e30504f0
3 changed files with 8 additions and 2 deletions

3
db.js
View File

@ -201,6 +201,9 @@ module.exports.CreateDB = function (parent, func) {
// Make sure all mesh types are number type, if not, fix it.
if (typeof docs[i].mtype == 'string') { docs[i].mtype = parseInt(docs[i].mtype); meshChange = true; }
// If the device group is deleted, remove any invite codes
if (docs[i].deleted && docs[i].invite) { delete docs[i].invite; meshChange = true; }
// Take a look at the links
if (docs[i].links != null) {
for (var j in docs[i].links) {

View File

@ -3113,6 +3113,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}
}
// Delete any invitation codes
delete mesh.invite;
// Delete all files on the server for this mesh
try {
var meshpath = parent.getServerRootFilePath(mesh);
@ -3187,7 +3190,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
var dup = null;
for (var i in command.invite.codes) {
for (var j in parent.meshes) {
if ((j != command.meshid) && (parent.meshes[j].domain == domain.id) && (parent.meshes[j].invite != null) && (parent.meshes[j].invite.codes.indexOf(command.invite.codes[i]) >= 0)) { dup = command.invite.codes[i]; break; }
if ((j != command.meshid) && (parent.meshes[j].deleted == null) && (parent.meshes[j].domain == domain.id) && (parent.meshes[j].invite != null) && (parent.meshes[j].invite.codes.indexOf(command.invite.codes[i]) >= 0)) { dup = command.invite.codes[i]; break; }
}
}
if (dup != null) {

View File

@ -1824,7 +1824,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
// Each for a device group that has this invite code.
for (var i in obj.meshes) {
if ((obj.meshes[i].domain == domain.id) && (obj.meshes[i].invite != null) && (obj.meshes[i].invite.codes.indexOf(req.body.inviteCode) >= 0)) {
if ((obj.meshes[i].domain == domain.id) && (parent.meshes[i].deleted == null) && (obj.meshes[i].invite != null) && (obj.meshes[i].invite.codes.indexOf(req.body.inviteCode) >= 0)) {
// Send invitation link, valid for 1 minute.
res.redirect(domain.url + 'agentinvite?c=' + parent.encodeCookie({ a: 4, mid: i, f: obj.meshes[i].invite.flags, expire: 1 }, parent.invitationLinkEncryptionKey) + (req.query.key ? ('&key=' + req.query.key) : ''));
return;