diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 79dc781b3..2b3dd4412 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -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(); diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 197c31cd5..206ead590 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -1154,9 +1154,12 @@ define([ hide.push('openro'); // Remove open 'view' mode } // if it's not a plain text file - var metadata = manager.getFileData(manager.find(path)); - if (!metadata || !Util.isPlainTextFile(metadata.fileType, metadata.title)) { - hide.push('openincode'); + // 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) { diff --git a/www/common/outer/sharedfolder.js b/www/common/outer/sharedfolder.js index d9a7058a3..8e6009a17 100644 --- a/www/common/outer/sharedfolder.js +++ b/www/common/outer/sharedfolder.js @@ -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, diff --git a/www/common/outer/userObject.js b/www/common/outer/userObject.js index bf9c16fa2..79047f4e3 100644 --- a/www/common/outer/userObject.js +++ b/www/common/outer/userObject.js @@ -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; diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index d7cc0a0d4..0e057f874 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -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; }; diff --git a/www/common/userObject.js b/www/common/userObject.js index 909e0e654..0dfaf9bee 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -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; }; diff --git a/www/drive/inner.js b/www/drive/inner.js index 94847f661..6f5c3de72 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -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(); diff --git a/www/drive/main.js b/www/drive/main.js index 273f6b153..0cda8a9cc 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -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, }); }); diff --git a/www/teams/inner.js b/www/teams/inner.js index d14cb53a8..7d855558c 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -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