[Patchew-devel] [PATCH 3/3] Rework map entry delete

Fam Zheng famz at redhat.com
Wed Oct 31 01:24:29 UTC 2018


Stale data of "testing.tests.FOO.users" in testing has prevented
deleting from working. Use a prefix based approach to do delete to make
it more robust.

Signed-off-by: Fam Zheng <famz at redhat.com>
---
 api/views.py | 11 +++++++++++
 mod.py       | 10 ++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/api/views.py b/api/views.py
index f224a63..615ff97 100644
--- a/api/views.py
+++ b/api/views.py
@@ -158,6 +158,17 @@ def get_properties(m):
         r['tags'] = m.tags
     return r
 
+class DeleteProjectPropertiesByPrefixView(APILoginRequiredView):
+    name = "delete-project-properties-by-prefix"
+    allowed_groups = ["maintainers"]
+
+    def handle(self, request, project, prefix):
+        po = Project.objects.get(name=project)
+        if not po.maintained_by(request.user):
+            raise PermissionDenied("Access denied to this project")
+        for k in [x for x in po.get_properties().keys() if x.startswith(prefix)]:
+            po.set_property(k, None)
+
 def prepare_patch(p):
     r = {"subject": p.subject,
          "message-id": p.message_id,
diff --git a/mod.py b/mod.py
index 90880ea..8d48772 100644
--- a/mod.py
+++ b/mod.py
@@ -317,6 +317,7 @@ TMPL_MAP_ITEM = """
     <div class="panel-heading panel-toggler" onclick="patchew_toggler_onclick(this)">
         {{ item_schema.title }}
         <strong id="item-name">{{ item.name }}</strong>
+        <input type="hidden" value="{{ prefix }}{{ item.name }}." id="prefix" />
     </div>
     <div class="panel-body panel-collapse collapse">
         {{ item.html }}
@@ -447,19 +448,16 @@ function map_add_item(btn) {
 }
 function map_delete_item(btn) {
     name = $(btn).parent().parent().parent().find("#item-name").html();
+    prefix = $(btn).parent().parent().parent().find("#prefix").val();
     if (!window.confirm("Really delete '" + name +"'?")) {
         return;
     }
-    props = collect_properties(btn, false);
-    for (var k in props) {
-        props[k] = null;
-    }
     $(btn).addClass("disabled");
     $(btn).text("Deleting...");
     $(btn).parent().find(".delete-message").remove();
-    patchew_api_do("set-project-properties",
+    patchew_api_do("delete-project-properties-by-prefix",
                    { project: "{{ project.name }}",
-                     properties: props })
+                     prefix: prefix })
         .done(function (data) {
             container = $(btn).parent().parent().parent();
             container.remove();
-- 
2.17.2




More information about the Patchew-devel mailing list