Display an error message if the file cannot be deleted
authorCyperghost <olaf_schmitz_1@t-online.de>
Wed, 13 Nov 2024 10:13:01 +0000 (11:13 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Wed, 13 Nov 2024 10:13:01 +0000 (11:13 +0100)
ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js
wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php
wcfsetup/install/files/style/ui/fileList.scss
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 0a55ad8202b132742a0f817bb222ff8929063cd2..e31777867285d4c39327ca3786ba755fa079fdb9 100644 (file)
@@ -16,6 +16,7 @@ import {
   trackUploadProgress,
 } from "WoltLabSuite/Core/Component/File/Helper";
 import { clearPreviousErrors } from "WoltLabSuite/Core/Component/File/Upload";
+import { innerError } from "WoltLabSuite/Core/Dom/Util";
 
 type FileId = string;
 const fileProcessors = new Map<FileId, FileProcessor>();
@@ -129,9 +130,21 @@ export class FileProcessor {
     deleteButton.classList.add("button", "small");
     deleteButton.textContent = getPhrase("wcf.global.button.delete");
     deleteButton.addEventListener("click", async () => {
-      await deleteFile(element.fileId!);
+      const result = await deleteFile(element.fileId!);
+      if (result.ok) {
+        this.#unregisterFile(element);
+      } else {
+        let container: HTMLElement = element;
+        if (!this.#useBigPreview) {
+          container = container.parentElement!;
+        }
 
-      this.#unregisterFile(element);
+        if (result.error.code === "permission_denied") {
+          innerError(container, getPhrase("wcf.upload.error.delete.permissionDenied"), true);
+        } else {
+          innerError(container, result.error.message ?? getPhrase("wcf.upload.error.delete.unknownError"));
+        }
+      }
     });
 
     return deleteButton;
index c08dbf919a4ffd64e4feee6d7354d3ed510e9e40..9732fb6df654c7ad3c9c88752c8521b527757e4e 100644 (file)
@@ -4,7 +4,7 @@
  * @license   GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @since     6.1
  */
-define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Api/Files/DeleteFile", "WoltLabSuite/Core/Dom/Change/Listener", "WoltLabSuite/Core/Component/File/Helper", "WoltLabSuite/Core/Component/File/Upload"], function (require, exports, tslib_1, Language_1, DeleteFile_1, Listener_1, Helper_1, Upload_1) {
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Api/Files/DeleteFile", "WoltLabSuite/Core/Dom/Change/Listener", "WoltLabSuite/Core/Component/File/Helper", "WoltLabSuite/Core/Component/File/Upload", "WoltLabSuite/Core/Dom/Util"], function (require, exports, tslib_1, Language_1, DeleteFile_1, Listener_1, Helper_1, Upload_1, Util_1) {
     "use strict";
     Object.defineProperty(exports, "__esModule", { value: true });
     exports.FileProcessor = void 0;
@@ -92,8 +92,22 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui
             deleteButton.classList.add("button", "small");
             deleteButton.textContent = (0, Language_1.getPhrase)("wcf.global.button.delete");
             deleteButton.addEventListener("click", async () => {
-                await (0, DeleteFile_1.deleteFile)(element.fileId);
-                this.#unregisterFile(element);
+                const result = await (0, DeleteFile_1.deleteFile)(element.fileId);
+                if (result.ok) {
+                    this.#unregisterFile(element);
+                }
+                else {
+                    let container = element;
+                    if (!this.#useBigPreview) {
+                        container = container.parentElement;
+                    }
+                    if (result.error.code === "permission_denied") {
+                        (0, Util_1.innerError)(container, (0, Language_1.getPhrase)("wcf.upload.error.delete.permissionDenied"), true);
+                    }
+                    else {
+                        (0, Util_1.innerError)(container, result.error.message ?? (0, Language_1.getPhrase)("wcf.upload.error.delete.unknownError"));
+                    }
+                }
             });
             return deleteButton;
         }
index eab6ba99d9689cb835e55808aea25af215ac23b9..6bced647c05f3a51a7a25f0c9c98d2d471185a4a 100644 (file)
@@ -153,6 +153,8 @@ final class PreloadPhrasesCollectingListener
         $event->preload('wcf.upload.error.fileExtensionNotPermitted');
         $event->preload('wcf.upload.error.fileSizeTooLarge');
         $event->preload('wcf.upload.error.maximumCountReached');
+        $event->preload('wcf.upload.error.delete.permissionDenied');
+        $event->preload('wcf.upload.error.delete.unknownError');
 
         $event->preload('wcf.user.activityPoint');
         $event->preload('wcf.user.language');
index 21f32e74ce3ee3db14eebdede8b00513fb2fa383..ccd0a1067f2ca9b6b7e3d4c9ce07d256e8583139 100644 (file)
@@ -25,7 +25,8 @@
        grid-template-areas:
                "file filename"
                "file fileSize"
-               "file buttons";
+               "file buttons"
+               "file error";
        grid-template-columns: 80px auto;
        padding: 10px;
 }
        color: var(--wcfStatusErrorText);
 }
 
+.fileList__item .innerError {
+       grid-area: error;
+}
+
 .fileList__item__file {
        display: flex;
        grid-area: file;
index 99fa14ec691327a87ac23febcddeacd0bb85b4b6..0f1663d4d8cf9c9117206d590c552c4f66dc65a0 100644 (file)
@@ -5566,6 +5566,8 @@ Benachrichtigungen auf <a href="{link isHtmlEmail=true}{/link}">{PAGE_TITLE|phra
                <item name="wcf.upload.error.fileSizeTooLarge"><![CDATA[Die Datei ist zu groß.]]></item>
                <item name="wcf.upload.error.maximumCountReached"><![CDATA[Es {plural value=$maximumCount 1='darf nur eine Datei' other='dürfen nur # Dateien'} hochgeladen werden.]]></item>
                <item name="wcf.upload.error.adopt"><![CDATA[Die Datei „{$filename}“ kann nicht zugewiesen werden.]]></item>
+               <item name="wcf.upload.error.delete.unknownError"><![CDATA[Beim Löschen der Datei ist ein unbekannter Fehler aufgetreten.]]></item>
+               <item name="wcf.upload.error.delete.permissionDenied"><![CDATA[Die Datei kann nicht gelöscht werden, {if LANGUAGE_USE_INFORMAL_VARIANT}verwende{else}verwenden Sie{/if} stattdessen <b>Ersetzen</b>, um die Datei zu erneuern.]]></item>
        </category>
 </import>
 <delete>
index 179f1f29da09aeda6ed6f09735d0d19a3db371e4..bbdb3026474216b336592e2b5242411f86a29ea7 100644 (file)
@@ -5568,6 +5568,8 @@ your notifications on <a href="{link isHtmlEmail=true}{/link}">{PAGE_TITLE|phras
                <item name="wcf.upload.error.fileSizeTooLarge"><![CDATA[The file is too large.]]></item>
                <item name="wcf.upload.error.maximumCountReached"><![CDATA[{plural value=$maximumCount 1='Only one file' other='Only up to # files'} may be uploaded.]]></item>
                <item name="wcf.upload.error.adopt"><![CDATA[The file “{$filename}” cannot be assigned.]]></item>
+               <item name="wcf.upload.error.delete.unknownError"><![CDATA[An unknown error occurred while deleting the file.]]></item>
+               <item name="wcf.upload.error.delete.permissionDenied"><![CDATA[The file cannot be deleted, use <b>Replace</b> instead to renew the file.]]></item>
        </category>
 </import>
 <delete>