From 874156ccf0507bd08245d1bafdeb6b4b0fca044e Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 17 Sep 2018 17:53:18 +0200 Subject: [PATCH] Prevent shared folders from being moved to the trash using the del key --- customize.dist/translations/messages.fr.js | 1 + customize.dist/translations/messages.js | 9 +++++---- server.js | 1 - www/drive/inner.js | 23 ++++++++++++++++++---- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 9e8215e3b..4b5b9f825 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -416,6 +416,7 @@ define(function () { out.fm_noname = "Document sans titre"; out.fm_emptyTrashDialog = "Êtes-vous sûr de vouloir vider la corbeille ?"; out.fm_removeSeveralPermanentlyDialog = "Êtes-vous sûr de vouloir supprimer ces {0} éléments de votre CryptDrive de manière permanente ?"; + out.fm_removePermanentlyNote = "Les pads dont vous êtes le propriétaire seront supprimés du serveur."; out.fm_removePermanentlyDialog = "Êtes-vous sûr de vouloir supprimer cet élément de votre CryptDrive de manière permanente ?"; out.fm_deleteOwnedPad = "Êtes-vous sûr de vouloir supprimer définitivement ce pad du serveur ?"; out.fm_deleteOwnedPads = "Êtes-vous sûr de vouloir supprimer définitivement ces pads du serveur ?"; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 6c678da44..5f57a8905 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -417,12 +417,13 @@ define(function () { out.fm_openParent = "Show in folder"; out.fm_noname = "Untitled Document"; out.fm_emptyTrashDialog = "Are you sure you want to empty the trash?"; - out.fm_removeSeveralPermanentlyDialog = "Are you sure you want to remove these {0} elements from your CryptDrive permanently?"; - out.fm_removePermanentlyDialog = "Are you sure you want to remove that element from your CryptDrive permanently?"; + out.fm_removeSeveralPermanentlyDialog = "Are you sure you want to permanently remove these {0} elements from your CryptDrive?"; + out.fm_removePermanentlyNote = "Owned pads will be removed from the server if you continue."; + out.fm_removePermanentlyDialog = "Are you sure you want to permanently remove that element from your CryptDrive?"; out.fm_removeSeveralDialog = "Are you sure you want to move these {0} elements to the trash?"; out.fm_removeDialog = "Are you sure you want to move {0} to the trash?"; - out.fm_deleteOwnedPad = "Are you sure you want to remove permanently this pad from the server?"; - out.fm_deleteOwnedPads = "Are you sure you want to remove permanently these pads from the server?"; + out.fm_deleteOwnedPad = "Are you sure you want to permanently remove this pad from the server?"; + out.fm_deleteOwnedPads = "Are you sure you want to permanently remove these pads from the server?"; out.fm_restoreDialog = "Are you sure you want to restore {0} to its previous location?"; out.fm_unknownFolderError = "The selected or last visited directory no longer exist. Opening the parent folder..."; out.fm_contextMenuError = "Unable to open the context menu for that element. If the problem persist, try to reload the page."; diff --git a/server.js b/server.js index 49cd9108f..17e793f29 100644 --- a/server.js +++ b/server.js @@ -86,7 +86,6 @@ var setHeaders = (function () { (function () { if (!config.logFeedback) { return; } -console.log(config.logFeedback); const logFeedback = function (url) { url.replace(/\?(.*?)=/, function (all, fb) { diff --git a/www/drive/inner.js b/www/drive/inner.js index a250ca83a..e9271f7c3 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -1207,15 +1207,23 @@ define([ if (paths) { paths.forEach(function (p) { pathsList.push(p.path); }); } + var hasOwned = pathsList.some(function (p) { + var el = manager.find(p); + var data = manager.isSharedFolder(el) ? manager.getSharedFolderData(el) + : manager.getFileData(el); + return data.owners && data.owners.indexOf(edPublic) !== -1; + }); var msg = Messages._getKey("fm_removeSeveralPermanentlyDialog", [pathsList.length]); if (pathsList.length === 1) { - msg = Messages.fm_removePermanentlyDialog; + msg = hasOwned ? Messages.fm_deleteOwnedPad : Messages.fm_removePermanentlyDialog; + } else if (hasOwned) { + msg = msg + '
' + Messages.fm_removePermanentlyNote + ''; } UI.confirm(msg, function(res) { $(window).focus(); if (!res) { return; } manager.delete(pathsList, refresh); - }); + }, null, true); }; // Drag & drop: // The data transferred is a stringified JSON containing the path of the dragged element @@ -3231,16 +3239,23 @@ define([ paths.push($(elmt).data('path')); }); if (!paths.length) { return; } + // Remove shared folders from the selection (they can't be moved to the trash) + // unless the selection is only shared folders + var paths2 = paths.filter(function (p) { + var el = manager.find(p); + return !manager.isSharedFolder(el); + }); // If we are in the trash or anon pad or if we are holding the "shift" key, // delete permanently // Or if we are in a shared folder + // Or if the selection is only shared folders if (!APP.loggedIn || isTrash || manager.isInSharedFolder(currentPath) - || e.shiftKey) { + || e.shiftKey || !paths2.length) { deletePaths(null, paths); return; } // else move to trash - moveElements(paths, [TRASH], false, refresh); + moveElements(paths2, [TRASH], false, refresh); return; } });