<div dir="ltr">Two questions regarding the patch. I couldn't find the test case in the legacy update-head and hence couldn't think of how to test this.<div>Second, Is the data required in the POST correct? I mean, is there any other way we can feed the message ids?</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, May 29, 2018 at 5:35 PM Shubham <<a href="mailto:shubhamjain7495@gmail.com">shubhamjain7495@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Wingify <wingify@Wingifys-MacBook-Air-3.local><br>
<br>
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<br>
---<br>
api/rest.py | 25 ++++++++++++++++++++++++-<br>
1 file changed, 24 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/api/rest.py b/api/rest.py<br>
index fa6ca3f..e9282c3 100644<br>
--- a/api/rest.py<br>
+++ b/api/rest.py<br>
@@ -18,7 +18,7 @@ from .models import Project, Message<br>
from .search import SearchEngine<br>
from rest_framework import (permissions, serializers, viewsets, filters,<br>
mixins, generics, renderers, status)<br>
-from rest_framework.decorators import detail_route<br>
+from rest_framework.decorators import detail_route, action<br>
from rest_framework.fields import SerializerMethodField, CharField, JSONField, EmailField<br>
from rest_framework.relations import HyperlinkedIdentityField<br>
from rest_framework.response import Response<br>
@@ -141,6 +141,29 @@ class ProjectsViewSet(viewsets.ModelViewSet):<br>
serializer_class = ProjectSerializer<br>
permission_classes = (PatchewPermission,)<br>
<br>
+ @action(methods=['post','get'], detail=True, permission_classes=[ImportPermission])<br>
+ def update_project_head(self, request, pk=None):<br>
+ """<br>
+ updates the project head and message_id which are matched are merged. <br>
+ Data input format:<br>
+ {<br>
+ "old_head": "..",<br>
+ "new_head": "..",<br>
+ "message_ids": []<br>
+ }<br>
+ """<br>
+ project = self.get_object()<br>
+ head = project.project_head<br>
+ if request.method == 'POST':<br>
+ old_head = request.data['old_head']<br>
+ message_ids = request.data['message_ids']<br>
+ if old_head_0 and old_head_0 != old_head:<br>
+ raise Exception("wrong old head")<br>
+ ret = project.series_update(message_ids)<br>
+ project.project_head = request.data['new_head']<br>
+ Response({"new_head": project.project_head, "count": ret})<br>
+ else:<br>
+ return Response({'project_head': head})<br>
# Common classes for series and messages<br>
<br>
class HyperlinkedMessageField(HyperlinkedIdentityField):<br>
-- <br>
2.15.1 (Apple Git-101)<br>
<br>
</blockquote></div>