From 3092734c62c60d9c1cfa33d5ce5fec7e940b048c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 8 Sep 2022 13:36:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20Require=20FILES=5FDELET?= =?UTF-8?q?E=20permission=20to=20overwrite=20a=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/server/api/files.py | 9 ++++++ .../static/js/app/viewmodels/files.js | 28 +++++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index 40e6200c9..fd34153e7 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -607,6 +607,15 @@ def uploadGcodeFile(target): ): abort(409, description="File already exists and noOverwrite was set") + if ( + fileManager.file_exists(FileDestinations.LOCAL, futureFullPathInStorage) + and not Permissions.FILES_DELETE.can() + ): + abort( + 403, + description="File already exists, cannot overwrite due to a lack of permissions", + ) + reselect = printer.is_current_file(futureFullPathInStorage, sd) user = current_user.get_name() diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index 637a56c0b..7537c81f9 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -1600,9 +1600,7 @@ $(function () { name: file.name }) ); - $("input", self.uploadExistsDialog) - .val("") - .prop("placeholder", response.suggestion); + $("input", self.uploadExistsDialog).val(response.suggestion); $("a.upload-rename", self.uploadExistsDialog) .prop("disabled", false) .off("click") @@ -1611,7 +1609,6 @@ $(function () { "input", self.uploadExistsDialog ).val(); - if (newName === "") newName = response.suggestion; OctoPrint.files .exists("local", path, newName) @@ -1645,13 +1642,22 @@ $(function () { } }); }); - $("a.upload-overwrite", self.uploadExistsDialog) - .off("click") - .on("click", function () { - self.uploadExistsDialog.modal("hide"); - data.formData = formData; - data.submit(); - }); + if ( + self.loginState.hasPermission( + self.access.permissions.FILES_DELETE + ) + ) { + $("a.upload-overwrite", self.uploadExistsDialog) + .off("click") + .show() + .on("click", function () { + self.uploadExistsDialog.modal("hide"); + data.formData = formData; + data.submit(); + }); + } else { + $("a.upload-overwrite", self.uploadExistsDialog).hide(); + } self.uploadExistsDialog.modal("show"); } else { data.formData = formData;