From d87a87410d17237c0bcde0f9c41c244268a28573 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 8 Jan 2019 13:57:22 +0100 Subject: [PATCH] Preserve hidden owned pads from a deleted folder --- www/common/outer/async-store.js | 9 +++- www/common/proxy-manager.js | 73 +++++++++++++++++--------- www/common/translations/messages.fr.js | 4 ++ 3 files changed, 59 insertions(+), 27 deletions(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 3192bad97..bbd2ba8f7 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1394,8 +1394,13 @@ define([ if (!store.loggedIn) { return void cb(); } Store.pinPads(null, data, cb); }; - var manager = store.manager = ProxyManager.create(proxy.drive, proxy.edPublic, - pin, unpin, loadSharedFolder, { + var manager = store.manager = ProxyManager.create(proxy.drive, { + edPublic: proxy.edPublic, + pin: pin, + unpin: unpin, + loadSharedFolder: loadSharedFolder, + settings: proxy.settings + }, { outer: true, removeOwnedChannel: function (data, cb) { Store.removeOwnedChannel('', data, cb); }, edPublic: store.proxy.edPublic, diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index 8bc59e48f..1faf4d55e 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -212,6 +212,28 @@ define([ }; }; + // Check if a given path is resolved to a shared folder or to the main drive + var _isInSharedFolder = function (Env, path) { + var resolved = _resolvePath(Env, path); + return typeof resolved.id === "number" ? resolved.id : false; + }; + + // Get the owned files in the main drive that are also duplicated in shared folders + var _isDuplicateOwned = function (Env, path, id) { + if (path && _isInSharedFolder(Env, path)) { return; } + var data = _getFileData(Env, id || Env.user.userObject.find(path)); + if (!data) { return; } + if (!_ownedByMe(Env, data.owners)) { return; } + var channel = data.channel; + if (!channel) { return; } + var foldersUO = Object.keys(Env.folders).map(function (k) { + return Env.folders[k].userObject; + }); + return foldersUO.some(function (uo) { + return uo.findChannels([channel]).length; + }); + }; + // Get a copy of the elements located in the given paths, with their files data // Note: This function is only called to move files from a proxy to another var _getCopyFromPaths = function (Env, paths, userObject) { @@ -450,7 +472,24 @@ define([ // Delete paths from the main drive and get the list of pads to unpin // We also get the list of owned pads that were removed if (resolved.main.length) { - Env.user.userObject.delete(resolved.main, waitFor(function (err, _toUnpin, _ownedRemoved) { + var uo = Env.user.userObject; + if (Util.find(Env.settings, ['drive', 'hideDuplicates'])) { + // If we hide duplicate owned pads in our drive, we have + // to make sure we're not deleting a hidden own file + // from inside a folder we're trying to delete + resolved.main.forEach(function (p) { + var el = uo.find(p); + if (uo.isFile(el) || uo.isSharedFolder(el)) { return; } + var arr = []; + uo.getFilesRecursively(el, arr); + arr.forEach(function (id) { + if (_isDuplicateOwned(Env, null, id)) { + Env.user.userObject.add(Number(id), [UserObject.ROOT]); + } + }); + }); + } + uo.delete(resolved.main, waitFor(function (err, _toUnpin, _ownedRemoved) { if (!Env.unpinPads || !_toUnpin) { return; } Array.prototype.push.apply(toUnpin, _toUnpin); ownedRemoved = _ownedRemoved; @@ -742,13 +781,14 @@ define([ }); }; - var create = function (proxy, edPublic, pinPads, unpinPads, loadSf, uoConfig) { + var create = function (proxy, data, uoConfig) { var Env = { - pinPads: pinPads, - unpinPads: unpinPads, - loadSharedFolder: loadSf, + pinPads: data.pin, + unpinPads: data.unpin, + loadSharedFolder: data.loadSharedFolder, cfg: uoConfig, - edPublic: edPublic, + edPublic: data.edPublic, + settings: data.settings, user: { proxy: proxy, userObject: UserObject.init(proxy, uoConfig) @@ -922,10 +962,7 @@ define([ return obj; }; - var isInSharedFolder = function (Env, path) { - var resolved = _resolvePath(Env, path); - return typeof resolved.id === "number" ? resolved.id : false; - }; + var isInSharedFolder = _isInSharedFolder; /* Generic: doesn't need access to a proxy */ var isFile = function (Env, el, allowStr) { @@ -971,21 +1008,7 @@ define([ return Env.user.userObject.hasFile(el, trashRoot); }; - // Get the owned files in the main drive that are also duplicated in shared folders - var isDuplicateOwned = function (Env, path) { - if (isInSharedFolder(Env, path)) { return; } - var data = getFileData(Env, Env.user.userObject.find(path)); - if (!data) { return; } - if (!_ownedByMe(Env, data.owners)) { return; } - var channel = data.channel; - if (!channel) { return; } - var foldersUO = Object.keys(Env.folders).map(function (k) { - return Env.folders[k].userObject; - }); - return foldersUO.some(function (uo) { - return uo.findChannels([channel]).length; - }); - }; + var isDuplicateOwned = _isDuplicateOwned; var createInner = function (proxy, sframeChan, edPublic, uoConfig) { var Env = { diff --git a/www/common/translations/messages.fr.js b/www/common/translations/messages.fr.js index 4be93fcfd..783ca80f8 100644 --- a/www/common/translations/messages.fr.js +++ b/www/common/translations/messages.fr.js @@ -641,6 +641,10 @@ define(function () { out.settings_logoutEverywhere = "Se déconnecter de force de toutes les autres sessions."; out.settings_logoutEverywhereConfirm = "Êtes-vous sûr ? Vous devrez vous reconnecter sur tous vos autres appareils."; + out.settings_driveDuplicateTitle = "Doublons des pads dont vous êtes propriétaire"; + out.settings_driveDuplicateHint = "Quand vous déplacez un pad dont vous êtes le propriétaire dans un dossier partagé, une copie est créée dans votre CryptDrive pour s'assurer que vous puissiez garder le contrôle de ce pad. Vous pouvez choisir de cacher ces doublons. Seules les versions partagées seront affichées, jusqu'à leur suppression, dans quels cas la version dans votre CryptDrive redeviendra visible."; + out.settings_driveDuplicateLabel = "Cacher les doublons"; + out.settings_codeIndentation = "Indentation dans l'éditeur de code (nombre d'espaces)"; out.settings_codeUseTabs = "Utiliser des tabulations au lieu d'espaces"; out.settings_codeFontSize = "Taille de la police dans l'éditeur de code (px)";