From 6c0d80f1a299ef047ea341fef405779b8fdcba17 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Mon, 16 Dec 2024 15:05:23 +0100 Subject: [PATCH] Add option to rename command to disable alias rename Add options options.enableRootRename (default: true). When set to false, root folders cannot be renamed by storing the new name in the preferences. It is not always useful to users to set an arbitrary alias and can, in some use cases, lead to more confusion rather than being helpful. --- js/commands/rename.js | 11 +++++++---- js/elFinder.js | 2 +- js/elFinder.options.js | 7 ++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/js/commands/rename.js b/js/commands/rename.js index aeed7d1f96..fbaf555614 100644 --- a/js/commands/rename.js +++ b/js/commands/rename.js @@ -9,12 +9,15 @@ elFinder.prototype.commands.rename = function() { "use strict"; // set alwaysEnabled to allow root rename on client size - this.alwaysEnabled = true; + if (this.fm.options.enableRootRename !== false) { + this.alwaysEnabled = true; + } this.syncTitleOnChange = true; var self = this, fm = self.fm, + enableRootRename = fm.options.enableRootRename !== false, request = function(dfrd, targtes, file, name) { var sel = targtes? [file.hash].concat(targtes) : [file.hash], cnt = sel.length, @@ -22,7 +25,7 @@ elFinder.prototype.commands.rename = function() { fm.lockfiles({files : sel}); - if (fm.isRoot(file) && !file.netkey) { + if (fm.isRoot(file) && !file.netkey && enableRootRename) { if (!(rootNames = fm.storage('rootNames'))) { rootNames = {}; } @@ -268,7 +271,7 @@ elFinder.prototype.commands.rename = function() { isRoot = fm.isRoot(sel[0]); } - state = (cnt === 1 && ((fm.cookieEnabled && isRoot) || !sel[0].locked) || (fm.api > 2.1030 && cnt === $.grep(sel, function(f) { + state = (cnt === 1 && ((enableRootRename && fm.cookieEnabled && isRoot) || !sel[0].locked) || (fm.api > 2.1030 && cnt === $.grep(sel, function(f) { if (!brk && !f.locked && f.phash === phash && !fm.isRoot(f) && (mime === f.mime || ext === fm.splitFileExtention(f.name)[1].toLowerCase())) { return true; } else { @@ -539,7 +542,7 @@ elFinder.prototype.commands.rename = function() { return dfrd.reject('errCmdParams', this.title); } - if (file.locked && !fm.isRoot(file)) { + if (file.locked && (!fm.isRoot(file) || !enableRootRename)) { return dfrd.reject(['errLocked', file.name]); } diff --git a/js/elFinder.js b/js/elFinder.js index 20707b844b..a6190a3d27 100644 --- a/js/elFinder.js +++ b/js/elFinder.js @@ -8112,7 +8112,7 @@ elFinder.prototype = { } } - if (isRoot) { + if (isRoot && self.options.enableRootRename !== false) { if (rootNames = self.storage('rootNames')) { if (rootNames[file.hash]) { file._name = file.name; diff --git a/js/elFinder.options.js b/js/elFinder.options.js index 9e66f6e26c..aec0a8cf18 100644 --- a/js/elFinder.options.js +++ b/js/elFinder.options.js @@ -1363,5 +1363,10 @@ elFinder.prototype._options = { * * @type Boolean|Object (toast options) */ - toastBackendWarn : true + toastBackendWarn : true, + + /** + * Whether renaming root folders is enabled. If true, the alias for the root folder is stored as a preference for the user. + */ + enableRootRename : true, };