Merge branch 'staging' of github.com:xwiki-labs/cryptpad into teams-server-features

This commit is contained in:
ansuz
2019-09-03 17:08:16 +02:00
15 changed files with 495 additions and 261 deletions

View File

@@ -28,10 +28,14 @@ commands.ADD_OWNERS = function (meta, args) {
throw new Error("METADATA_NONSENSE_OWNERS");
}
var changed = false;
args.forEach(function (owner) {
if (meta.owners.indexOf(owner) >= 0) { return; }
meta.owners.push(owner);
changed = true;
});
return changed;
};
// ["RM_OWNERS", ["CrufexqXcY-z+eKJlEbNELVy5Sb7E-EAAEFI8GnEtZ0="], 1561623439989]
@@ -45,13 +49,24 @@ commands.RM_OWNERS = function (meta, args) {
throw new Error("METADATA_NONSENSE_OWNERS");
}
var changed = false;
// remove owners one by one
// we assume there are no duplicates
args.forEach(function (owner) {
var index = meta.owners.indexOf(owner);
if (index < 0) { return; }
if (meta.mailbox) {
if (typeof(meta.mailbox) === "string") {
delete meta.mailbox;
} else {
delete meta.mailbox[owner];
}
}
meta.owners.splice(index, 1);
changed = true;
});
return changed;
};
// ["ADD_PENDING_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623438989]
@@ -67,16 +82,20 @@ commands.ADD_PENDING_OWNERS = function (meta, args) {
throw new Error("METADATA_NONSENSE_PENDING_OWNERS");
}
var changed = false;
// Add pending_owners array if it doesn't exist
if (!meta.pending_owners) {
meta.pending_owners = deduplicate(args);
return;
return true;
}
// or fill it
args.forEach(function (owner) {
if (meta.pending_owners.indexOf(owner) >= 0) { return; }
meta.pending_owners.push(owner);
changed = true;
});
return changed;
};
// ["RM_PENDING_OWNERS", ["CrufexqXcY-z+eKJlEbNELVy5Sb7E-EAAEFI8GnEtZ0="], 1561623439989]
@@ -90,13 +109,17 @@ commands.RM_PENDING_OWNERS = function (meta, args) {
throw new Error("METADATA_NONSENSE_PENDING_OWNERS");
}
var changed = false;
// remove owners one by one
// we assume there are no duplicates
args.forEach(function (owner) {
var index = meta.pending_owners.indexOf(owner);
if (index < 0) { return; }
meta.pending_owners.splice(index, 1);
changed = true;
});
return changed;
};
// ["RESET_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623439989]
@@ -112,6 +135,41 @@ commands.RESET_OWNERS = function (meta, args) {
// overwrite the existing owners with the new one
meta.owners = deduplicate(args);
return true;
};
// ["ADD_MAILBOX", {"7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I=": mailbox, ...}, 1561623439989]
commands.ADD_MAILBOX = function (meta, args) {
// expect a new array, even if it's empty
if (!args || typeof(args) !== "object") {
throw new Error('METADATA_INVALID_MAILBOX');
}
// assume there are owners to start
if (!Array.isArray(meta.owners)) {
throw new Error("METADATA_NONSENSE_OWNERS");
}
var changed = false;
// For each mailbox we try to add, check if the associated edPublic is an owner
// If they are, add or replace the mailbox
Object.keys(args).forEach(function (edPublic) {
if (meta.owners.indexOf(edPublic) === -1) { return; }
if (typeof(meta.mailbox) === "string") {
var str = meta.mailbox;
meta.mailbox = {};
meta.mailbox[meta.owners[0]] = str;
}
// Make sure mailbox is defined
if (!meta.mailbox) { meta.mailbox = {}; }
meta.mailbox[edPublic] = args[edPublic];
changed = true;
});
return changed;
};
commands.UPDATE_EXPIRATION = function () {
@@ -127,7 +185,7 @@ var handleCommand = Meta.handleCommand = function (meta, line) {
throw new Error("METADATA_UNSUPPORTED_COMMAND");
}
commands[command](meta, args);
return commands[command](meta, args);
};
Meta.commands = Object.keys(commands);