From f98f8f17239eca5eb1733d38b8edcfdc720a60d4 Mon Sep 17 00:00:00 2001 From: UlrichB22 <97119703+UlrichB22@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:10:54 +0200 Subject: [PATCH] Fix delete/destroy from +index and ... --- src/moin/apps/frontend/views.py | 15 ++++++++++----- src/moin/static/js/index_action.js | 6 +++--- src/moin/templates/index.html | 2 +- src/moin/translations/de/LC_MESSAGES/messages.po | 8 ++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/moin/apps/frontend/views.py b/src/moin/apps/frontend/views.py index 926d15472..49489d995 100644 --- a/src/moin/apps/frontend/views.py +++ b/src/moin/apps/frontend/views.py @@ -1071,8 +1071,8 @@ def ajaxdestroy(item_name, req="destroy"): # user probably checked a subitem and checked do subitems response["messages"].append(_("Item '{bad_name}' does not exist.").format(bad_name=item.name)) continue + subitem_names = [] if req == "destroy": - subitem_names = [] if do_subitems: subitems = item.get_subitem_revs() # if subitem has alias of unselected sibling or ancester, it will be included @@ -1094,7 +1094,6 @@ def ajaxdestroy(item_name, req="destroy"): response["itemnames"] += subitem_names + itemnames except AccessDenied: response["messages"].append(_("Access denied processing '{bad_name}'.").format(bad_name=itemname)) - response["itemnames"] = [url_for_item(x) for x in response["itemnames"]] return jsonify(response) @@ -1148,11 +1147,17 @@ def ajaxsubitems(): alias_names = [] subitems = list(item.get_subitem_revs()) # TODO: add check for delete/destroy auth, add to rejected names, - item_names = tuple(x + "/" for x in item.names) # subitems may have alias names pointing to sibling or parent of user selected items - subitem_names = [y for x in subitems for y in x.meta[NAME]] + + if fqname.namespace: + namespace_prefix = f"{fqname.namespace}/" # used to build fullname for aliases and subitems + else: + namespace_prefix = "" + + subitem_names = [f"{namespace_prefix}{y}" for x in subitems for y in x.meta[NAME]] + if not [item.name] == item.names: - alias_names = [x for x in item.names if not x == item.name] + alias_names = [f"{namespace_prefix}{x}" for x in item.names if not x == item.name] all_alias_names += alias_names all_subitem_names += subitem_names all_selected_names.append(item_name) diff --git a/src/moin/static/js/index_action.js b/src/moin/static/js/index_action.js index 0978c8281..be254a1b6 100644 --- a/src/moin/static/js/index_action.js +++ b/src/moin/static/js/index_action.js @@ -27,7 +27,7 @@ $("document").ready(function () { function get_checked() { var checked_names = []; $("input.moin-item:checked").each(function () { - var itemname = $(this).attr("value").slice(1); + var itemname = $(this).attr("value"); checked_names.push(itemname); }); return checked_names; @@ -106,7 +106,7 @@ $("document").ready(function () { url; // create an array of selected item names $("input.moin-item:checked").each(function () { - var itemname = $(this).attr("value").slice(1); + var itemname = $(this).attr("value"); links.push(itemname); }); // remove any flash messages, display "deleting..." or "destroying..." flash msg while process is in progress @@ -125,7 +125,7 @@ $("document").ready(function () { comment: comment, do_subitems: $("#moin-do-subitems").is(":checked") ? "true" : "false" }, function (data) { - // incoming itemnames is url-encoded list of item names (including alias names) successfully deleted/destroyed + // incoming itemnames is list of item names (including alias names) successfully deleted/destroyed var itemnames = data.itemnames, idx; // display success/fail flash messages created by server for each selected item and subitem diff --git a/src/moin/templates/index.html b/src/moin/templates/index.html index 268f64a3c..7dd42bf80 100644 --- a/src/moin/templates/index.html +++ b/src/moin/templates/index.html @@ -27,7 +27,7 @@