From 88dcadcb1b561bfc6297b7bb7aad20a3f785e925 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 23 Jan 2020 14:31:45 -0500 Subject: [PATCH] sketch out trimHistory interface --- rpc.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/rpc.js b/rpc.js index 69eb9313f..f690b2bf1 100644 --- a/rpc.js +++ b/rpc.js @@ -961,13 +961,27 @@ var removeOwnedChannel = function (Env, channelId, unsafeKey, cb) { }; var removeOwnedChannelHistory = function (Env, channelId, unsafeKey, hash, cb) { - // XXX validate that the user sending the request owns the channel in question - // proceed to call Env.msgStore.trimChannel(channelId, hash, cb) if ok - // otherwise reject with INSUFFICIENT_PERMISSIONS + nThen(function (w) { + getMetadata(Env, channelId, w(function (err, metadata) { + if (err) { return void cb(err); } + if (!hasOwners(metadata)) { + w.abort(); + return void cb('E_NO_OWNERS'); + } + if (!isOwner(metadata, unsafeKey)) { + w.abort(); + return void cb("INSUFFICIENT_PERMISSIONS"); + } + // else fall through to the next block + })); + }).nThen(function () { + Env.msgStore.trimChannel(channelId, hash, function (err) { + if (err) { return void cb(err); } + - // XXX if trimChannel calls back without an error - // you must also clear the channel's index from historyKeeper cache - cb("E_NOT_IMPLEMENTED"); + // XXX you must also clear the channel's index from historyKeeper cache + }); + }); }; /* Users should be able to clear their own pin log with an authenticated RPC