From nobody Fri Mar 29 08:20:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528168735504768.5613938647697; Mon, 4 Jun 2018 20:18:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 65699363560; Tue, 5 Jun 2018 03:18:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4FA4010018FC; Tue, 5 Jun 2018 03:18:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 436F218005DA; Tue, 5 Jun 2018 03:18:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w553Im9b023353 for ; Mon, 4 Jun 2018 23:18:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 22360261C2; Tue, 5 Jun 2018 03:18:48 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BC7B261AD for ; Tue, 5 Jun 2018 03:18:45 +0000 (UTC) Received: from mail-pf0-f173.google.com (mail-pf0-f173.google.com [209.85.192.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D338C30A8397 for ; Tue, 5 Jun 2018 03:18:34 +0000 (UTC) Received: by mail-pf0-f173.google.com with SMTP id b17-v6so498921pfi.0 for ; Mon, 04 Jun 2018 20:18:34 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.29]) by smtp.gmail.com with ESMTPSA id s16-v6sm73897139pfm.114.2018.06.04.20.18.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Jun 2018 20:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ksnpOpXLQkhrAaCWa/xhkxevpnAJ7gbGUYzMkhI80ac=; b=mRrOe5TZhYLrBrHlcZmYVoMcDvqH6rL6YmLqCOgxm0nn9C8neod0RC+P0HJFX8WHKr pOBfPpTRjGsahKxtCuZh6ANA0hdwijyXdjUsiO59eiQF9BLwblRSXh5+G9RFTRQVIBHd BfsrxLvp+idwFVKcWseDXblMuaDxq6O5KChgTjmUyQ+/5ZvNDv0i+9F84C4Yf65281rC 3/swY6J92hMez9JNe2nQb0VrSB/7eXxwFFGWydhZJVqGRJYawJUNkAhphx+JGyF4LtvD 1kTV0j5b3MLCuQMjcBxylgEqnz8vjkW5Ezla6uRyJ9w1yInxhtGAXVJjmW7U6TLUeHMk 7rEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ksnpOpXLQkhrAaCWa/xhkxevpnAJ7gbGUYzMkhI80ac=; b=CE18ctsIZX1HQc/TJdvHpMuThy6JZEMeKsi3RZnfg/incpDE4zZmh/fVPIqgV875ba 2M0+Y05JlDd+bqEpK8Zi2T6XyCR9sXkRUPtZWEKPyjrKQGt6VvkM4GsNDPazhGxv9flN 84SXq7wfrrTvM/SiLNIUnXRnfQ66sRDF+vq5xUPE4dQxugjcVngSUXZgE0W1dKrN12CI 04xZDT8xZJqRqp7JjG5QBBK3Qn0KekJ0R7ELoYc2TeiWRZPQdAcVLmKYOJI1sgNus+CB wuO2/6VGd8dZjfeq4iXTBsBr569Md9QeUJ3+Qs5RJh93Y7Jb5XZUmuAtQLLsbHsk02A2 J1oA== X-Gm-Message-State: ALKqPwfxm3Ylf+oekm6m8y6Pg0BAlO0AyK/Et2F/sjtPQp/XWe3/GNFC typ9xcu791b/5cQUiq44fAZjxw== X-Google-Smtp-Source: ADUXVKKnu8OrtlkhtAYYHe4ymBaeyZX//AtDx56Y1Ip0rUVbmomgqYyQfOCQi8fVRHUqt81/8X1lVQ== X-Received: by 2002:a63:7741:: with SMTP id s62-v6mr19612160pgc.103.1528168713896; Mon, 04 Jun 2018 20:18:33 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Tue, 5 Jun 2018 08:47:42 +0530 Message-Id: <20180605031742.16613-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 05 Jun 2018 03:18:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 05 Jun 2018 03:18:34 +0000 (UTC) for IP:'209.85.192.173' DOMAIN:'mail-pf0-f173.google.com' HELO:'mail-pf0-f173.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.551 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.192.173 mail-pf0-f173.google.com 209.85.192.173 mail-pf0-f173.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v2] rest: Add endpoint from update-project-head X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 05 Jun 2018 03:18:54 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Added extra action in the ProjectViewSet which will update the project head= at endpoint /projects/../update_project_head. This is legacy conversion(Up= dateProjectHeadView) into rest --- api/rest.py | 23 ++++++++++++++++++++++- tests/test_rest.py | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/api/rest.py b/api/rest.py index fa6ca3f..084dbbc 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, JSONFi= eld, EmailField from rest_framework.relations import HyperlinkedIdentityField from rest_framework.response import Response @@ -141,6 +141,27 @@ class ProjectsViewSet(viewsets.ModelViewSet): serializer_class =3D ProjectSerializer permission_classes =3D (PatchewPermission,) =20 + @action(methods=3D['post'], detail=3DTrue, permission_classes=3D[Impor= tPermission]) + def update_project_head(self, request, pk=3DNone): + """ + updates the project head and message_id which are matched are merg= ed.=20 + Data input format: + { + "old_head": "..", + "new_head": "..", + "message_ids": [] + } + """ + project =3D self.get_object() + head =3D project.project_head + old_head =3D request.data['old_head'] + message_ids =3D request.data['message_ids'] + if head and head !=3D old_head: + return Response('Wrong old head', status_code=3Dstatus.HTTP_40= 9_CONFLICT) + ret =3D project.series_update(message_ids) + project.project_head =3D request.data['new_head'] + return Response({"new_head": project.project_head, "count": ret}) + # Common classes for series and messages =20 class HyperlinkedMessageField(HyperlinkedIdentityField): diff --git a/tests/test_rest.py b/tests/test_rest.py index 1399801..2a85815 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -86,6 +86,24 @@ class RestTest(PatchewTestCase): self.assertEquals(resp.data['mailing_list'], "qemu-block@nongnu.or= g") self.assertEquals(resp.data['parent_project'], self.PROJECT_BASE) =20 + def test_update_project_head(self): + resp =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', + self.p.id, '20160628014747.20971-1-= famz@redhat.com') + self.api_client.login(username=3Dself.user, password=3Dself.passwo= rd) =20 + resp_before =3D self.api_client.get(self.PROJECT_BASE + "series/"+= "20160628014747.20971-1-famz@redhat.com/") + data =3D { + "message_ids": ["20160628014747.20971-1-famz@redhat.com"], + "old_head": "None", + "new_head": "000000" + } + resp =3D self.api_client.post(self.PROJECT_BASE + "update_project_= head/", data=3Djson.dumps(data), content_type=3D'application/json') + resp_after =3D 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'], "000000") + self.assertEquals(resp_after.data['is_merged'], True) + def test_project_post_no_login(self): data =3D { 'name': 'keycodemapdb', --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel