Ability to open an anonymous read only shared folder

pull/1/head
yflory 5 years ago
parent 4e4d01a471
commit 9a0251f4ba

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

@ -1154,10 +1154,13 @@ define([
hide.push('openro'); // Remove open 'view' mode
}
// if it's not a plain text file
// XXX: there is a bug with this code in anon shared folder, so we disable it
if (APP.loggedIn || !APP.newSharedFolder) {
var metadata = manager.getFileData(manager.find(path));
if (!metadata || !Util.isPlainTextFile(metadata.fileType, metadata.title)) {
hide.push('openincode');
}
}
} else if ($element.is('.cp-app-drive-element-sharedf')) {
if (containsFolder) {
// More than 1 folder selected: cannot create a new subfolder

@ -68,7 +68,7 @@ define([
var listmapConfig = {
data: {},
channel: secret.channel,
readOnly: false,
readOnly: secret.keys && !secret.keys.editKeyStr,
crypto: Crypto.createEncryptor(secret.keys),
userName: 'sharedFolder',
logLevel: 1,

@ -687,6 +687,12 @@ define([
href = el.href && ((el.href.indexOf('#') !== -1) ? el.href : exp.cryptor.decrypt(el.href));
} catch (e) {}
if (href && href.indexOf('#') === -1) {
// If we can't decrypt the href, it means we don't have the correct secondaryKey and we're in readOnly mode:
// abort now, we won't be able to fix anything anyway
continue;
}
var parsed = Hash.parsePadUrl(href || el.roHref);
var secret;

@ -164,7 +164,7 @@ define([
var data = {};
userObjects.some(function (uo) {
data = uo.getFileData(id, editable);
if (Object.keys(data).length) { return true; }
if (data && Object.keys(data).length) { return true; }
});
return data;
};

@ -114,10 +114,16 @@ define([
var getHref = exp.getHref = function (pad) {
if (pad.href && pad.href.indexOf('#') !== -1) {
// Href exists and is not encrypted: return href
return pad.href;
}
if (pad.href) {
return exp.cryptor.decrypt(pad.href);
// Href exists and is encrypted
var d = exp.cryptor.decrypt(pad.href);
// If we can decrypt, return the decrypted value, otherwise continue and return roHref
if (d.indexOf('#') !== -1) {
return d;
}
}
return pad.roHref;
};

@ -65,7 +65,10 @@ define([
copyObjectValue(obj, newObj);
if (!APP.loggedIn && APP.newSharedFolder) {
obj.drive.sharedFolders = obj.drive.sharedFolders || {};
obj.drive.sharedFolders[APP.newSharedFolder] = {};
obj.drive.sharedFolders[APP.newSharedFolder] = {
href: APP.anonSFHref,
password: APP.anonSFPassword
};
}
cb();
});
@ -124,6 +127,8 @@ define([
var privateData = metadataMgr.getPrivateData();
if (privateData.newSharedFolder) {
APP.newSharedFolder = privateData.newSharedFolder;
APP.anonSFHref = privateData.anonSFHref;
APP.anonSFPassword = privateData.password;
}
var sframeChan = common.getSframeChannel();

@ -107,12 +107,17 @@ define([
sframeChan.event('EV_DRIVE_REMOVE', data);
});
};
var addData = function (meta) {
if (!window.CryptPad_newSharedFolder) { return; }
meta.anonSFHref = window.location.href;
};
SFCommonO.start({
afterSecrets: afterSecrets,
noHash: true,
noRealtime: true,
driveEvents: true,
addRpc: addRpc,
addData: addData,
isDrive: true,
});
});

@ -72,10 +72,6 @@ define([
var updateObject = function (sframeChan, obj, cb) {
sframeChan.query('Q_DRIVE_GETOBJECT', null, function (err, newObj) {
copyObjectValue(obj, newObj);
if (!driveAPP.loggedIn && driveAPP.newSharedFolder) {
obj.drive.sharedFolders = obj.drive.sharedFolders || {};
obj.drive.sharedFolders[driveAPP.newSharedFolder] = {};
}
cb();
});
};
@ -922,9 +918,6 @@ define([
common.setTabTitle(Messages.type.teams);
// Drive data
if (privateData.newSharedFolder) {
driveAPP.newSharedFolder = privateData.newSharedFolder;
}
driveAPP.disableSF = !privateData.enableSF && AppConfig.disableSharedFolders;
// Toolbar

Loading…
Cancel
Save