Fix more issues when changing password of a readonly folder

pull/1/head
yflory 5 years ago
parent f9723a6183
commit 37a72d2f87

@ -629,7 +629,7 @@ define([
};
var getPadProperties = function (common, data, cb) {
var $d = $('<div>');
if (!data || (!data.href && !data.roHref)) { return void cb(void 0, $d); }
if (!data) { return void cb(void 0, $d); }
if (data.href) {
$('<label>', {'for': 'cp-app-prop-link'}).text(Messages.editShare).appendTo($d);

@ -1524,6 +1524,7 @@ define([
var noSharedWorker = false;
if (localStorage.CryptPad_noWorkers) {
noWorker = localStorage.CryptPad_noWorkers === '1';
noWorker = true;
console.error('WebWorker/SharedWorker state forced to ' + !noWorker);
}
Nthen(function (waitFor2) {

@ -3803,7 +3803,8 @@ define([
}
if (manager.isSharedFolder(el)) {
delete data.roHref;
var ro = folders[el] && folders[el].version >= 2;
if (!ro) { delete data.roHref; }
//data.noPassword = true;
//data.noEditPassword = true;
data.noExpiration = true;

@ -76,6 +76,12 @@ define([
var parsed = Hash.parsePadUrl(href);
var secret = Hash.getSecrets('drive', parsed.hash, data.password);
// If we don' have valid keys, abort and remove the proxy to make sure
// we don't block the drive permanently
if (!secret.keys) {
store.manager.deprecateProxy(id);
return void cb(null);
}
var secondaryKey = secret.keys.secondaryKey;
// If we try to load an existing shared folder (isNew === false) but this folder
@ -232,21 +238,13 @@ define([
var sf = allSharedFolders[oldChannel];
if (!sf) { return void cb({ error: 'ENOTFOUND' }); }
if (sf.rt && sf.rt.stop) {
sf.rt.stop();
try { sf.rt.stop(); } catch (e) {}
}
var nt = nThen;
sf.teams.forEach(function (obj) {
nt = nt(function (waitFor) {
var s = obj.store;
var sfId = obj.id;
// We can't update the password of a shared folder in a read-only team
if (s.manager.user.userObject.readOnly) {
// Just deprecate the folder so that inner can stop displaying a folder no longer available
if (s.manager.folders[sfId]) {
s.manager.folders[sfId].proxy = { deprecated: true };
}
return;
}
var shared = Util.find(s.proxy, ['drive', UserObject.SHARED_FOLDERS]) || {};
if (!sfId || !shared[sfId]) { return; }
var sf = JSON.parse(JSON.stringify(shared[sfId]));

@ -41,6 +41,11 @@ define([
team.manager.user.userObject.getHref(data) : data.href;
var parsed = Hash.parsePadUrl(href);
var secret = Hash.getSecrets(parsed.type, parsed.hash, o);
// We've received a new password, we should update it locally
// NOTE: this is an async call because new password means new roHref!
// We need to wait for the new roHref in the proxy before calling the handlers
// because a read-only team will use it when connecting to the new channel
setTimeout(function () {
SF.updatePassword(ctx.Store, {
oldChannel: secret.channel,
password: n,
@ -48,6 +53,7 @@ define([
}, ctx.store.network, function () {
console.log('Shared folder password changed');
});
});
return false;
}
});

@ -59,7 +59,7 @@ define([
}
return void Env.Store.refreshDriveUI();
}
Env.unpinPads([channel], function () {});
if (channel) { Env.unpinPads([channel], function () {}); }
Env.user.userObject.deprecateSharedFolder(id);
if (Env.Store && Env.Store.refreshDriveUI) {
Env.Store.refreshDriveUI();
@ -200,11 +200,12 @@ define([
var obj = Env.folders[id].proxy.metadata || {};
for (var k in Env.user.proxy[UserObject.SHARED_FOLDERS][id] || {}) {
var data = JSON.parse(JSON.stringify(Env.user.proxy[UserObject.SHARED_FOLDERS][id][k]));
if (data.href && data.href.indexOf('#') === -1) {
if (k === "href" && data.indexOf('#') === -1) {
try {
data.href = Env.user.userObject.cryptor.decrypt(data.href);
data = Env.user.userObject.cryptor.decrypt(data);
} catch (e) {}
}
if (k === "href" && data.indexOf('#') === -1) { data = undefined; }
obj[k] = data;
}
return obj;
@ -561,8 +562,9 @@ define([
var secret = Hash.getSecrets(parsed.type, parsed.hash, newPassword);
data.password = newPassword;
data.channel = secret.channel;
var _href = '/drive/#'+Hash.getEditHashFromKeys(secret);
data.href = Env.user.userObject.cryptor.encrypt(_href);
if (secret.keys.editKeyStr) {
data.href = '/drive/#'+Hash.getEditHashFromKeys(secret);
}
data.roHref = '/drive/#'+Hash.getViewHashFromKeys(secret);
_addSharedFolder(Env, {
path: ['root'],

@ -106,7 +106,8 @@ define([
exp.setReadOnly = function (state, key) {
config.editKey = key;
createCryptor(key);
exp.cryptor = createCryptor(key);
exp.cryptor.k = Math.random();
exp.readOnly = state;
if (exp._setReadOnly) {
// Change outer

@ -67,6 +67,9 @@ define([
if (manager && oldIds.indexOf(fId) === -1) {
manager.addProxy(fId, { proxy: folders[fId] }, null, secret.keys.secondaryKey);
}
var readOnly = !secret.keys.editKeyStr;
if (!manager || !manager.folders[fId]) { return; }
manager.folders[fId].userObject.setReadOnly(readOnly, secret.keys.secondaryKey);
}));
});
}).nThen(function () {

Loading…
Cancel
Save