[Patchew-devel] [PATCH 03/17] api: do not blindly return all properties from get-projects

Paolo Bonzini posted 17 patches 5 years, 7 months ago
[Patchew-devel] [PATCH 03/17] api: do not blindly return all properties from get-projects
Posted by Paolo Bonzini 5 years, 7 months ago
Only return the two properties that patchew-cli actually needs, through
a new hook.  Do this before the configuration is moved out of the
properties table, because these "properties" are actually configuration
items.

This will be cleaned up once patchew-cli switches to the REST API.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 api/views.py | 6 +++++-
 mods/git.py  | 4 ++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/api/views.py b/api/views.py
index 4ac5636..887f9ed 100644
--- a/api/views.py
+++ b/api/views.py
@@ -18,6 +18,7 @@ import json
 from .search import SearchEngine
 from django.views.decorators.csrf import csrf_exempt
 from django.utils.decorators import method_decorator
+from mod import dispatch_module_hook
 
 
 class APIView(View):
@@ -83,8 +84,11 @@ def prepare_project(p):
         "url": p.url,
         "git": p.git,
         "description": p.description,
-        "properties": p.get_properties(),
+        "properties": {},
     }
+    dispatch_module_hook("get_projects_prepare_hook", project=p,
+                         response=ret['properties'])
+
     return ret
 
 
diff --git a/mods/git.py b/mods/git.py
index d0b1f87..89e711d 100644
--- a/mods/git.py
+++ b/mods/git.py
@@ -128,6 +128,10 @@ class GitModule(PatchewModule):
     def rest_series_fields_hook(self, request, fields, detailed):
         fields['based_on'] = PluginMethodField(obj=self, required=False)
 
+    def get_projects_prepare_hook(self, project, response):
+        response["git.head"] = project.get_property("git.head")
+        response["git.push_to"] = project.get_property("git.push_to")
+
     def prepare_message_hook(self, request, message, detailed):
         if not message.is_series_head:
             return
-- 
2.21.0


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel