]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] WebUI: Allow computing fuzzy hashes without writable storages 5878/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Thu, 5 Feb 2026 09:06:48 +0000 (12:06 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Thu, 5 Feb 2026 09:06:48 +0000 (12:06 +0300)
interface/js/app/upload.js

index b3b463986e44c1f6f154e33163dc685366ec6ddf..d8d84e6cc034ce49dc3730d2e21d6852827c1c60 100644 (file)
@@ -350,12 +350,18 @@ define(["jquery", "app/common", "app/libft"],
             {
                 picker: "#fuzzy-flag-picker",
                 input: "#fuzzy-flag",
-                container: ($picker) => $picker.parent()
+                container: ($picker) => $picker.parent(),
+                includeReadOnly: true,
+                requiresWritable: false,
+                emptyText: "No fuzzy storages"
             },
             {
                 picker: "#fuzzyFlagText-picker",
                 input: "#fuzzyFlagText",
-                container: ($picker) => $picker.closest("div.card")
+                container: ($picker) => $picker.closest("div.card"),
+                includeReadOnly: false,
+                requiresWritable: true,
+                emptyText: "No writable storages"
             }
         ];
 
@@ -366,8 +372,10 @@ define(["jquery", "app/common", "app/libft"],
             });
         }
 
-        function setWidgetsDisabled(disable) {
-            fuzzyWidgets.forEach(({picker, container}) => {
+        function setWidgetsDisabled(disable, predicate = () => true) {
+            fuzzyWidgets.forEach((widget) => {
+                if (!predicate(widget)) return;
+                const {picker, container} = widget;
                 container($(picker))[disable ? "addClass" : "removeClass"]("disabled");
             });
         }
@@ -384,25 +392,30 @@ define(["jquery", "app/common", "app/libft"],
                     const hasWritableStorages = Object.keys(storages).some((name) => !storages[name].read_only);
 
                     toggleWidgets(true, false);
-                    setWidgetsDisabled(!hasWritableStorages);
+                    setWidgetsDisabled(!hasWritableStorages, (widget) => widget.requiresWritable);
 
-                    fuzzyWidgets.forEach(({picker, input}) => {
+                    fuzzyWidgets.forEach((widget) => {
+                        const {picker, input, includeReadOnly, emptyText} = widget;
                         const $sel = $(picker);
 
                         $sel.empty();
 
-                        if (hasWritableStorages) {
-                            Object.entries(storages).forEach(([name, info]) => {
-                                if (!info.read_only) {
-                                    Object.entries(info.flags).forEach(([symbol, val]) => {
-                                        $sel.append($("<option>", {value: val, text: `${name}:${symbol} (${val})`}));
-                                    });
-                                }
+                        const applicableStorages = Object.entries(storages)
+                            .filter(([, info]) => includeReadOnly || !info.read_only);
+
+                        applicableStorages.forEach(([name, info]) => {
+                            Object.entries(info.flags).forEach(([symbol, val]) => {
+                                $sel.append($("<option>", {value: val, text: `${name}:${symbol} (${val})`}));
                             });
+                        });
+
+                        if ($sel.children().length > 0) {
                             $(input).val($sel.val());
                             $sel.off("change").on("change", () => $(input).val($sel.val()));
                         } else {
-                            $sel.append($("<option>", {value: "", text: "No writable storages"}));
+                            $sel.append($("<option>", {value: "", text: emptyText}));
+                            $(input).val("");
+                            $sel.off("change");
                         }
                     });
                 },