api/models.py | 2 +- api/rest.py | 25 ++++++++++++++++++++++++- tests/test_rest.py | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-)
Added extra action in the ProjectViewSet which will update the project head at endpoint /projects/../update_project_head. This is legacy conversion(UpdateProjectHeadView) into rest
Also fixed the variable name in the series_update
---
api/models.py | 2 +-
api/rest.py | 25 ++++++++++++++++++++++++-
tests/test_rest.py | 19 +++++++++++++++++++
3 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/api/models.py b/api/models.py
index e3585e4..b4f8468 100644
--- a/api/models.py
+++ b/api/models.py
@@ -193,7 +193,7 @@ class Project(models.Model):
s = mo.get_series_head()
if s:
updated_series.append(s)
- for s in updated_series:
+ for series in updated_series:
for p in series.get_patches():
if not p.is_merged:
break
diff --git a/api/rest.py b/api/rest.py
index fa6ca3f..837cdd7 100644
--- a/api/rest.py
+++ b/api/rest.py
@@ -18,7 +18,7 @@ from .models import Project, Message
from .search import SearchEngine
from rest_framework import (permissions, serializers, viewsets, filters,
mixins, generics, renderers, status)
-from rest_framework.decorators import detail_route
+from rest_framework.decorators import detail_route, action
from rest_framework.fields import SerializerMethodField, CharField, JSONField, EmailField
from rest_framework.relations import HyperlinkedIdentityField
from rest_framework.response import Response
@@ -141,6 +141,29 @@ class ProjectsViewSet(viewsets.ModelViewSet):
serializer_class = ProjectSerializer
permission_classes = (PatchewPermission,)
+ @action(methods=['post','get'], detail=True, permission_classes=[ImportPermission])
+ def update_project_head(self, request, pk=None):
+ """
+ updates the project head and message_id which are matched are merged.
+ Data input format:
+ {
+ "old_head": "..",
+ "new_head": "..",
+ "message_ids": []
+ }
+ """
+ project = self.get_object()
+ head = project.project_head
+ if request.method == 'POST':
+ old_head = request.data['old_head']
+ message_ids = request.data['message_ids']
+ if head and head != old_head:
+ raise Exception("wrong old head")
+ ret = project.series_update(message_ids)
+ project.project_head = request.data['new_head']
+ return Response({"new_head": project.project_head, "count": ret})
+ else:
+ return Response({'project_head': head})
# Common classes for series and messages
class HyperlinkedMessageField(HyperlinkedIdentityField):
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 1399801..75d8e9e 100755
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -86,6 +86,25 @@ class RestTest(PatchewTestCase):
self.assertEquals(resp.data['mailing_list'], "qemu-block@nongnu.org")
self.assertEquals(resp.data['parent_project'], self.PROJECT_BASE)
+ def test_update_project_head(self):
+ resp = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
+ self.p.id, '20160628014747.20971-1-famz@redhat.com')
+ self.api_client.login(username=self.user, password=self.password)
+ resp_before = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
+ data = {
+ "message_ids": ["20160628014747.20971-1-famz@redhat.com"],
+ "old_head": "None",
+ "new_head": "dummy_head"
+ }
+ resp = self.api_client.post(self.PROJECT_BASE + "update_project_head/", data=json.dumps(data), content_type='application/json')
+ resp_after = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
+ self.assertEquals(resp_before.data['is_merged'], False)
+ self.assertEquals(resp.status_code, 200)
+ self.assertEquals(resp.data['count'],1)
+ self.assertEquals(resp.data['new_head'],"dummy_head")
+ self.assertEquals(resp_after.data['is_merged'], True)
+
+
def test_project_post_no_login(self):
data = {
'name': 'keycodemapdb',
--
2.15.1 (Apple Git-101)
_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
On Wed, 05/30 22:57, Shubham wrote: > Added extra action in the ProjectViewSet which will update the project head at endpoint /projects/../update_project_head. This is legacy conversion(UpdateProjectHeadView) into rest > Also fixed the variable name in the series_update > --- > api/models.py | 2 +- > api/rest.py | 25 ++++++++++++++++++++++++- > tests/test_rest.py | 19 +++++++++++++++++++ > 3 files changed, 44 insertions(+), 2 deletions(-) > > diff --git a/api/models.py b/api/models.py > index e3585e4..b4f8468 100644 > --- a/api/models.py > +++ b/api/models.py > @@ -193,7 +193,7 @@ class Project(models.Model): > s = mo.get_series_head() > if s: > updated_series.append(s) > - for s in updated_series: > + for series in updated_series: Could you move this fix to a separate patch? > for p in series.get_patches(): > if not p.is_merged: > break > diff --git a/api/rest.py b/api/rest.py > index fa6ca3f..837cdd7 100644 > --- a/api/rest.py > +++ b/api/rest.py > @@ -18,7 +18,7 @@ from .models import Project, Message > from .search import SearchEngine > from rest_framework import (permissions, serializers, viewsets, filters, > mixins, generics, renderers, status) > -from rest_framework.decorators import detail_route > +from rest_framework.decorators import detail_route, action > from rest_framework.fields import SerializerMethodField, CharField, JSONField, EmailField > from rest_framework.relations import HyperlinkedIdentityField > from rest_framework.response import Response > @@ -141,6 +141,29 @@ class ProjectsViewSet(viewsets.ModelViewSet): > serializer_class = ProjectSerializer > permission_classes = (PatchewPermission,) > > + @action(methods=['post','get'], detail=True, permission_classes=[ImportPermission]) > + def update_project_head(self, request, pk=None): > + """ > + updates the project head and message_id which are matched are merged. > + Data input format: > + { > + "old_head": "..", > + "new_head": "..", > + "message_ids": [] > + } > + """ > + project = self.get_object() > + head = project.project_head > + if request.method == 'POST': > + old_head = request.data['old_head'] > + message_ids = request.data['message_ids'] > + if head and head != old_head: > + raise Exception("wrong old head") > + ret = project.series_update(message_ids) > + project.project_head = request.data['new_head'] > + return Response({"new_head": project.project_head, "count": ret}) > + else: > + return Response({'project_head': head}) > # Common classes for series and messages > > class HyperlinkedMessageField(HyperlinkedIdentityField): > diff --git a/tests/test_rest.py b/tests/test_rest.py > index 1399801..75d8e9e 100755 > --- a/tests/test_rest.py > +++ b/tests/test_rest.py > @@ -86,6 +86,25 @@ class RestTest(PatchewTestCase): > self.assertEquals(resp.data['mailing_list'], "qemu-block@nongnu.org") > self.assertEquals(resp.data['parent_project'], self.PROJECT_BASE) > > + def test_update_project_head(self): > + resp = self.apply_and_retrieve('0001-simple-patch.mbox.gz', > + self.p.id, '20160628014747.20971-1-famz@redhat.com') > + self.api_client.login(username=self.user, password=self.password) > + resp_before = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/") > + data = { > + "message_ids": ["20160628014747.20971-1-famz@redhat.com"], > + "old_head": "None", > + "new_head": "dummy_head" > + } > + resp = self.api_client.post(self.PROJECT_BASE + "update_project_head/", data=json.dumps(data), content_type='application/json') > + resp_after = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/") > + self.assertEquals(resp_before.data['is_merged'], False) > + self.assertEquals(resp.status_code, 200) > + self.assertEquals(resp.data['count'],1) > + self.assertEquals(resp.data['new_head'],"dummy_head") > + self.assertEquals(resp_after.data['is_merged'], True) > + > + > def test_project_post_no_login(self): > data = { > 'name': 'keycodemapdb', > -- > 2.15.1 (Apple Git-101) > > _______________________________________________ > Patchew-devel mailing list > Patchew-devel@redhat.com > https://www.redhat.com/mailman/listinfo/patchew-devel _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel
© 2016 - 2023 Red Hat, Inc.