From nobody Fri Apr 26 20:06:18 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 1527701293778878.3034319113646; Wed, 30 May 2018 10:28:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A1D721FE332; Wed, 30 May 2018 17:28:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8FD445C293; Wed, 30 May 2018 17:28:12 +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 8282A4CA82; Wed, 30 May 2018 17:28:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4UHSBPV013930 for ; Wed, 30 May 2018 13:28:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id CAC655B68A; Wed, 30 May 2018 17:28:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C179E5D70C for ; Wed, 30 May 2018 17:27:59 +0000 (UTC) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) (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 ADD043173F1B for ; Wed, 30 May 2018 17:27:48 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id j20-v6so9361856pff.10 for ; Wed, 30 May 2018 10:27:48 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.29]) by smtp.gmail.com with ESMTPSA id d62-v6sm47912077pga.29.2018.05.30.10.27.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 May 2018 10:27:46 -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=+pqCno2+udkUkly75KhH66N2AR8+7Q+vD0Sbl+VFd/U=; b=l+OHo4pke41d1ibyxfXh/4fpHOK9p26kgypQ9eLGx5icCtNcWGfrxUA/pF2Ff/OAQc lbI87BTQyfsd6IaO6R+ZsMa+PgmuXBVEMwuo91FDPAEc+q4paKp7b2YGtG8a7y2rzxT3 m9mlK4TDudL0IcOMJ5elOrjwBn81JAF7OlFrYSCI1sHDPRvCQ4sRVtXjyammKHGI8u1V tc8xetqxiZXyN/OqBakWiSYTCSveKfhCR98Xqq+3MgnrCoH9yleqVC0ahOmc6ZryEbla lHJ3DFq+Y9j7PAN9nYEH+74PrQpQhvFaWiGFuTWfU1KaTk6/JF5GNGtabbv8zWu3ODz1 9Kmw== 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=+pqCno2+udkUkly75KhH66N2AR8+7Q+vD0Sbl+VFd/U=; b=RiFQK1V/YjEp6s1ha3vfseOn0Anxf0QZioTr+ojdJC0WahILFLmtOPeidR62TIHNO9 XNo2rKtn/fxVYw4dKPEXZt2sSVKKVZr4PZYn5wBpKKvw4RcXPzrHH0d0YaYb0+wtep39 HJBVT7+z680BBDDf8B+ZjEAA920PcFGojIR0qIlb+CMaqUIkEKE1cjLO8+cuwdBEdloP /pdCLKIwpt4TsVGJwGpI4UixKXoJXuC5/Uw3mDFSmqz85+GZ9jn8sPCjUb1bezTZwdMV 7qKhWsQof6Hg1nyoCWmXAC3XYHaJR3qyw6hPZjQU7BpQ1Sl1CXs3GT4RwqhlsttQ7SxR Np/A== X-Gm-Message-State: ALKqPwerg49L6A6wJOsOP9QNYTcb9ro24+2Ngc2xVxBAwmAg1J3QqwZP MrTaPhollPcBYBm3RYleMAJCZg== X-Google-Smtp-Source: ADUXVKJImC2yyemGZfy5vyPWxquE5yXX/1nqGUprP4vaOQsjJTwCLiB101pdR5Nq2SQgRfm76aDdRg== X-Received: by 2002:a62:3d05:: with SMTP id k5-v6mr3322809pfa.122.1527701267648; Wed, 30 May 2018 10:27:47 -0700 (PDT) From: Shubham To: patchew-devel@redhat.com Date: Wed, 30 May 2018 22:57:36 +0530 Message-Id: <20180530172736.76725-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 30 May 2018 17:27:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 30 May 2018 17:27:48 +0000 (UTC) for IP:'209.85.192.193' DOMAIN:'mail-pf0-f193.google.com' HELO:'mail-pf0-f193.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.146 (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.193 mail-pf0-f193.google.com 209.85.192.193 mail-pf0-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Cc: shubhamjain7495@gmail.com Subject: [Patchew-devel] [PATCH] 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 30 May 2018 17:28:12 +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 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 =3D 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, JSONFi= eld, EmailField from rest_framework.relations import HyperlinkedIdentityField from rest_framework.response import Response @@ -141,6 +141,29 @@ class ProjectsViewSet(viewsets.ModelViewSet): serializer_class =3D ProjectSerializer permission_classes =3D (PatchewPermission,) =20 + @action(methods=3D['post','get'], detail=3DTrue, permission_classes=3D= [ImportPermission]) + 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 + if request.method =3D=3D 'POST': + old_head =3D request.data['old_head'] + message_ids =3D request.data['message_ids'] + if head and head !=3D old_head: + raise Exception("wrong old head") + ret =3D project.series_update(message_ids) + project.project_head =3D request.data['new_head'] + return Response({"new_head": project.project_head, "count": re= t}) + else: + return Response({'project_head': head}) # Common classes for series and messages =20 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.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": "dummy_head" + } + 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'],"dummy_head") + 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