Add safety measures to avoid removing your drive by accident

pull/1/head
yflory 5 years ago
parent d823deff92
commit 5c6b3155ac

@ -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) {

@ -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(),

@ -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({

Loading…
Cancel
Save