diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 0311387ee..c19baf0a9 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -254,8 +254,12 @@ define([ common.clearOwnedChannel = function (channel, cb) { postMessage("CLEAR_OWNED_CHANNEL", channel, cb); }; - common.removeOwnedChannel = function (channel, cb) { - postMessage("REMOVE_OWNED_CHANNEL", channel, cb); + // "force" allows you to delete your drive ID + common.removeOwnedChannel = function (channel, cb, force) { + postMessage("REMOVE_OWNED_CHANNEL", { + channel: channel, + force: force + }, cb); }; common.getDeletedPads = function (data, cb) { @@ -769,7 +773,7 @@ define([ waitFor.abort(); return void cb(obj); } - })); + }), true); common.unpinPads([oldChannel], waitFor()); common.pinPads([newSecret.channel], waitFor()); }).nThen(function (waitFor) { @@ -950,7 +954,7 @@ define([ common.logoutFromAll(waitFor(function () { postMessage("DISCONNECT"); })); - })); + }), true); } }).nThen(function (waitFor) { if (!oldIsOwned) { diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index ca7e4cd7c..0304a5006 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -34,7 +34,7 @@ define([ var sendDriveEvent = function () {}; var registerProxyEvents = function () {}; - var storeHash; + var storeHash, storeChannel; var store = window.CryptPad_AsyncStore = { modules: {} @@ -239,6 +239,20 @@ define([ Store.removeOwnedChannel = function (clientId, data, cb) { if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } + + // "data" used to be a string (channelID), now it can also be an object + // data.force tells us we can safely remove the drive ID + var channel = data; + var force = false; + if (typeof(data) === "object") { + channel = data.channel; + force = data.force; + } + + if (channel === storeChannel && !force) { + return void cb({error: 'User drive removal blocked!'}); + } + store.rpc.removeOwnedChannel(data, function (err) { cb({error:err}); }); @@ -786,6 +800,7 @@ define([ var h = p.hashData; if (AppConfig.disableAnonymousStore && !store.loggedIn) { return void cb(); } + if (p.type === "debug") { return void cb(); } var channelData = Store.channels && Store.channels[channel]; @@ -1915,6 +1930,7 @@ define([ } // No password for drive var secret = Hash.getSecrets('drive', hash); + storeChannel = secret.channel; var listmapConfig = { data: {}, websocketURL: NetConfig.getWebsocketURL(), diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 13229969d..0103cdbaf 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -838,13 +838,6 @@ define([ Cryptpad.setLanguage(data, cb); }); - sframeChan.on('Q_CLEAR_OWNED_CHANNEL', function (channel, cb) { - Cryptpad.clearOwnedChannel(channel, cb); - }); - sframeChan.on('Q_REMOVE_OWNED_CHANNEL', function (channel, cb) { - Cryptpad.removeOwnedChannel(channel, cb); - }); - sframeChan.on('Q_GET_ALL_TAGS', function (data, cb) { Cryptpad.listAllTags(function (err, tags) { cb({