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'; noWorker = localStorage.CryptPad_noWorkers === '1';
console.error('WebWorker/SharedWorker state forced to ' + !noWorker); console.error('WebWorker/SharedWorker state forced to ' + !noWorker);
} }
noWorker = true;
Nthen(function (waitFor2) { Nthen(function (waitFor2) {
if (Worker) { if (Worker) {
var w = waitFor2(); var w = waitFor2();

@ -1154,9 +1154,12 @@ define([
hide.push('openro'); // Remove open 'view' mode hide.push('openro'); // Remove open 'view' mode
} }
// if it's not a plain text file // if it's not a plain text file
var metadata = manager.getFileData(manager.find(path)); // XXX: there is a bug with this code in anon shared folder, so we disable it
if (!metadata || !Util.isPlainTextFile(metadata.fileType, metadata.title)) { if (APP.loggedIn || !APP.newSharedFolder) {
hide.push('openincode'); 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')) { } else if ($element.is('.cp-app-drive-element-sharedf')) {
if (containsFolder) { if (containsFolder) {

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

@ -687,6 +687,12 @@ define([
href = el.href && ((el.href.indexOf('#') !== -1) ? el.href : exp.cryptor.decrypt(el.href)); href = el.href && ((el.href.indexOf('#') !== -1) ? el.href : exp.cryptor.decrypt(el.href));
} catch (e) {} } 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 parsed = Hash.parsePadUrl(href || el.roHref);
var secret; var secret;

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

@ -114,10 +114,16 @@ define([
var getHref = exp.getHref = function (pad) { var getHref = exp.getHref = function (pad) {
if (pad.href && pad.href.indexOf('#') !== -1) { if (pad.href && pad.href.indexOf('#') !== -1) {
// Href exists and is not encrypted: return href
return pad.href; return pad.href;
} }
if (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; return pad.roHref;
}; };

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

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

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

Loading…
Cancel
Save