From nobody Tue May 13 19:41:33 2025 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 1530281233090747.1796792573122; Fri, 29 Jun 2018 07:07:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92C3C30001E9; Fri, 29 Jun 2018 14:07:12 +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 7ED5317111; Fri, 29 Jun 2018 14:07: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 6AAF118037F0; Fri, 29 Jun 2018 14:07: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 w5TE6w2a023794 for ; Fri, 29 Jun 2018 10:06:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4896D18362; Fri, 29 Jun 2018 14:06:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F2CF17111 for ; Fri, 29 Jun 2018 14:06:54 +0000 (UTC) Received: from mail-pg0-f41.google.com (mail-pg0-f41.google.com [74.125.83.41]) (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 34953300197B for ; Fri, 29 Jun 2018 14:06:43 +0000 (UTC) Received: by mail-pg0-f41.google.com with SMTP id c9-v6so4056745pgf.5 for ; Fri, 29 Jun 2018 07:06:43 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.81]) by smtp.gmail.com with ESMTPSA id 14-v6sm20208806pgc.63.2018.06.29.07.06.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jun 2018 07:06:41 -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:in-reply-to:references; bh=tR7zFyrnt9dYnjSZfpnAD+75u2XA94fntjGcyxqdN50=; b=TuO2bmRQcAvAag3VPZr/0zLy6fy/tn/l5ItCikaJ64NBm7WtVOosJ+QsRlmMbaSJOD xMndxBYMw19OYDDgivrjDAWAx0C6Cy+DwtORFSREkLyFJB1elNtSsHPynahI+ggpsXtV 8Zc8ZJyejbejJrY7OsIDgtGFBs0yW3F0oAhwrEGHjvzSCfpVzgZZgJlxnboDkA3wRtME k7H1uxQ9WiqZntUMz3H1WSNELzpbDTrPRk8nnTAaNo02czUh5+iY4bhT2JbMq+Yofu0x qBcPHkstFJeLTn1UGtYh3r6+2EVlgton5U89XlhBXdCc9ChoaRo9yAb89vaz7UGtG+08 Yagg== 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:in-reply-to :references; bh=tR7zFyrnt9dYnjSZfpnAD+75u2XA94fntjGcyxqdN50=; b=Bm/W4d3qrNzo0I6vvFD2R+945/c1jzYlFjuDl4zKWGkkcERXU3Rt6vyyHIpuw6q9t4 672N6CISSDp2Af6KpN+vYx2AU0YLLdNW4OFpUbKydA/XWyMAcDi7VZ4W9ytgrV/PXxhe 5G2ADHbrVfQt0wUYZ4cffuiTjZOjh/7Kzyw2U6wUxaNekFI9lrdOipJSwlRbMTDDZiqZ UEBaYOT0BYmjnP06IXDRHAVTAcQ0ffGXO5ks89oM8r+zeUE6m22RBhFKlouiKNXqyk8q dgJZwi5av86HKHeWKaoulA5vkP88i78FKvW4IgOGRjG/Sxy+t/+J2JlpkRonhEFZZWjf /6fg== X-Gm-Message-State: APt69E3hRiQRKznxo4WZt36bSPq0SJHzRHeN/O3PZL9tpAahSH2NsKGh O14st7uqlX1DdoeEauVsHvKysA== X-Google-Smtp-Source: ADUXVKKOQ+4HVlRGC5fOtwwuBkmOaKruX7mupkejxZ3A0iLjjIB83+n2lY05GigpRh1Z7G3WVNaGcg== X-Received: by 2002:a63:b812:: with SMTP id p18-v6mr13115381pge.11.1530281202170; Fri, 29 Jun 2018 07:06:42 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Fri, 29 Jun 2018 19:35:51 +0530 Message-Id: <20180629140551.99829-4-shubhamjain7495@gmail.com> In-Reply-To: <20180629140551.99829-1-shubhamjain7495@gmail.com> References: <20180629140551.99829-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 29 Jun 2018 14:06:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 29 Jun 2018 14:06:43 +0000 (UTC) for IP:'74.125.83.41' DOMAIN:'mail-pg0-f41.google.com' HELO:'mail-pg0-f41.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) 74.125.83.41 mail-pg0-f41.google.com 74.125.83.41 mail-pg0-f41.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v2 3/3] Make Import Command use Rest 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 29 Jun 2018 14:07: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" Make patchew-cli's Import user REST apis. Changed the exit status of authen= ticated user from cli test while importing since in REST every authenticate= d user can access the import api but messages would be imported only to the= projects recognised ie whether it imported by maintainer or importer. Also= added warning if message is not imported to any project. --- api/rest.py | 3 ++- patchew-cli | 18 +++++++++++++----- tests/test_import.py | 8 ++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/api/rest.py b/api/rest.py index 9b47f37..876be75 100644 --- a/api/rest.py +++ b/api/rest.py @@ -423,7 +423,8 @@ class MessagesViewSet(BaseMessageViewSet): serializer_class =3D MessageSerializer permission_classes =3D (permissions.IsAuthenticatedOrReadOnly,) parser_classes =3D (JSONParser, MessagePlainTextParser, ) - =20 + authentication_classes =3D (CsrfExemptSessionAuthentication, ) + def create(self, request, *args, **kwargs): m =3D MboxMessage(request.data['mbox']) projects =3D [p for p in Project.objects.all() if p.recognizes(m)] diff --git a/patchew-cli b/patchew-cli index f90f3c5..3796caf 100755 --- a/patchew-cli +++ b/patchew-cli @@ -220,11 +220,18 @@ class ImportCommand(SubCommand): print("[OLD] " + mo["Subject"]) return print("[NEW] " + mo["Subject"]) - r =3D self.api_do("import", mboxes=3D[mo.as_string()]) - for p in r: - if p not in projects: - projects.add(p) - print(p) + for mbox in [mo.as_string()]: + r =3D self.rest_api_do(url_cmd=3D"messages", + request_method=3D'post', + content_type=3D'message/rfc822', + data=3Dmbox) + projects_list =3D [x['resource_uri'].split("messages")[0] = for x in r['results']] + for p in projects_list: + if p not in projects: + projects.add(p) + print(p) + if len(projects_list)=3D=3D0: + print("The message was not imported to any project. Pe= rhaps you're not logged in as an importer or maintainer") if ff: open(ff, "wb").close() =20 @@ -251,6 +258,7 @@ class ImportCommand(SubCommand): try: import_one(f) except: + raise print("Error in importing:", f) traceback.print_exc() r =3D 1 diff --git a/tests/test_import.py b/tests/test_import.py index 5693d7e..250f391 100755 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -107,21 +107,21 @@ class UnprivilegedImportTest(ImportTest): =20 test_import_belong_to_multiple_projects =3D None =20 - def check_import_should_fail(self): - self.cli_import("0001-simple-patch.mbox.gz", 1) + def check_import_status(self, exit_status): + self.cli_import("0001-simple-patch.mbox.gz", exit_status) a, b =3D self.check_cli(["search"]) self.assertNotIn('[Qemu-devel] [PATCH] quorum: Only compile when s= upported', a.splitlines()) =20 def test_anonymous_import(self): self.cli_logout() - self.check_import_should_fail() + self.check_import_status(exit_status=3D1) =20 def test_normal_user_import(self): self.cli_logout() self.create_user("someuser", "somepass") self.cli_login("someuser", "somepass") - self.check_import_should_fail() + self.check_import_status(exit_status=3D0) =20 def test_project_update(self): p =3D Project.objects.all()[0] --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel