apps: add archive action

This commit is contained in:
Girish Ramakrishnan
2024-12-09 18:28:35 +01:00
parent 147e014205
commit 710bd270d7
9 changed files with 85 additions and 7 deletions
+15
View File
@@ -22,6 +22,7 @@ exports = module.exports = {
// user actions
install,
uninstall,
archive,
setAccessRestriction,
setOperators,
@@ -2477,6 +2478,20 @@ async function uninstall(app, auditSource) {
return { taskId };
}
async function archive(app, backupId, auditSource) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof backupId, 'string');
assert.strictEqual(typeof auditSource, 'object');
const result = await backups.getByIdentifierAndStatePaged(app.id, backups.BACKUP_STATE_NORMAL, 1, 1);
if (result.length === 0) throw new BoxError(BoxError.BAD_STATE, 'No recent backup to archive');
if (result[0].id !== backupId) throw new BoxError(BoxError.BAD_STATE, 'Latest backup id has changed');
const { taskId } = await uninstall(app, auditSource);
await backups.update(result[0].id, { archive: true });
return { taskId };
}
async function start(app, auditSource) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof auditSource, 'object');