From f1fc2d2ad94a251c2275f5e92efd879a35ab93b5 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 18 Feb 2022 18:45:52 +0530 Subject: [PATCH] WIP provide a reason when archiving or resoring a file through the admin panel --- lib/commands/admin-rpc.js | 28 ++++++++++++++++++++++++++-- www/admin/inner.js | 21 +++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index 59750571e..b9ec845b3 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -155,7 +155,17 @@ var flushCache = function (Env, Server, cb) { // CryptPad_AsyncStore.rpc.send('ADMIN', ['ARCHIVE_DOCUMENT', documentID], console.log) var archiveDocument = function (Env, Server, cb, data) { - var id = Array.isArray(data) && data[1]; + if (!Array.isArray(data)) { return void cb("EINVAL"); } + var args = data[1]; + + var id, reason; + if (typeof(args) === 'string') { + id = args; + } else if (args && typeof(args) === 'object') { + id = args.id; + reason = args.reason; + } + if (typeof(id) !== 'string' || id.length < 32) { return void cb("EINVAL"); } switch (id.length) { @@ -164,6 +174,7 @@ var archiveDocument = function (Env, Server, cb, data) { return void Env.msgStore.archiveChannel(id, Util.both(cb, function (err) { Env.Log.info("ARCHIVAL_CHANNEL_BY_ADMIN_RPC", { channelId: id, + reason: reason, status: err? String(err): "SUCCESS", }); })); @@ -171,6 +182,7 @@ var archiveDocument = function (Env, Server, cb, data) { return void Env.blobStore.archive.blob(id, Util.both(cb, function (err) { Env.Log.info("ARCHIVAL_BLOB_BY_ADMIN_RPC", { id: id, + reason: reason, status: err? String(err): "SUCCESS", }); })); @@ -184,7 +196,17 @@ var archiveDocument = function (Env, Server, cb, data) { }; var restoreArchivedDocument = function (Env, Server, cb, data) { - var id = Array.isArray(data) && data[1]; + if (!Array.isArray(data)) { return void cb("EINVAL"); } + var args = data[1]; + + var id, reason; + if (typeof(args) === 'string') { + id = args; + } else if (args && typeof(args) === 'object') { + id = args.id; + reason = args.reason; + } + if (typeof(id) !== 'string' || id.length < 32) { return void cb("EINVAL"); } switch (id.length) { @@ -192,6 +214,7 @@ var restoreArchivedDocument = function (Env, Server, cb, data) { return void Env.msgStore.restoreArchivedChannel(id, Util.both(cb, function (err) { Env.Log.info("RESTORATION_CHANNEL_BY_ADMIN_RPC", { id: id, + reason: reason, status: err? String(err): 'SUCCESS', }); })); @@ -201,6 +224,7 @@ var restoreArchivedDocument = function (Env, Server, cb, data) { return void Env.blobStore.restore.blob(id, Util.both(cb, function (err) { Env.Log.info("RESTORATION_BLOB_BY_ADMIN_RPC", { id: id, + reason: reason, status: err? String(err): 'SUCCESS', }); })); diff --git a/www/admin/inner.js b/www/admin/inner.js index 83143a546..a80c8ca32 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -146,6 +146,8 @@ define([ return $div; }; + Messages.admin_archiveReason = "// XXX REASON"; // XXX + var archiveForm = function (archive, $div, $button) { var label = h('label', { for: 'cp-admin-archive' }, Messages.admin_archiveInput); var input = h('input#cp-admin-archive', { @@ -159,6 +161,14 @@ define([ id: 'cp-admin-archive-pw', placeholder: Messages.login_password }); + var input3 = h('input', { + id: 'cp-admin-archive-reason', + placeholder: Messages.admin_archiveReason, + }); + var label3 = h('label', { + for: 'cp-admin-archive-reason', + }, Messages.admin_archiveReason); + var $pw = $(input2); $pw.addClass('cp-admin-pw'); var $pwInput = $pw.find('input'); @@ -168,7 +178,9 @@ define([ label, input, label2, - input2 + input2, + label3, + input3, ])); $div.addClass('cp-admin-nopassword'); @@ -234,9 +246,13 @@ define([ } }), true); }).nThen(function () { + var $reason = $(input3); sFrameChan.query('Q_ADMIN_RPC', { cmd: archive ? 'ARCHIVE_DOCUMENT' : 'RESTORE_ARCHIVED_DOCUMENT', - data: channel + data: { + id: channel, + reason: $reason.val(), // XXX + }, }, function (err, obj) { var e = err || (obj && obj.error); clicked = false; @@ -248,6 +264,7 @@ define([ UI.log(archive ? Messages.archivedFromServer : Messages.restoredFromServer); $input.val(''); $pwInput.val(''); + $reason.val('') }); }); });