From nobody Thu Sep 19 01:07:41 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 1531369342346167.60333718753213; Wed, 11 Jul 2018 21:22:22 -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 83A8C3086265; Thu, 12 Jul 2018 04:22:21 +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 703A35D75A; Thu, 12 Jul 2018 04:22:21 +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 622784A460; Thu, 12 Jul 2018 04:22:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6C4MKxN020349 for ; Thu, 12 Jul 2018 00:22:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 77EDBC0D1F; Thu, 12 Jul 2018 04:22:20 +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 703D3C0D02 for ; Thu, 12 Jul 2018 04:22:18 +0000 (UTC) Received: from mail-pl0-f49.google.com (mail-pl0-f49.google.com [209.85.160.49]) (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 DACA030832E7 for ; Thu, 12 Jul 2018 04:22:07 +0000 (UTC) Received: by mail-pl0-f49.google.com with SMTP id b1-v6so10107176pls.5 for ; Wed, 11 Jul 2018 21:22:07 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.182]) by smtp.gmail.com with ESMTPSA id i12-v6sm31294658pgd.87.2018.07.11.21.22.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jul 2018 21:22:05 -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=8VtzSrpbwV9DVLhKb7Zyfszac8XVo7czRmhTzyy53LI=; b=D/Ww0WVosFGTOH6/u8ZuoZ02Kx/fmHh8ak6hIhq3q8UY+pwPh0M8Mg97NbZKTSUob5 s0SQAa7gTZBP5t4mi3k7m6bFRXusyOWovmtuNWjx7UvIIQ2KXhL3+NEd2DvAAJRAH/RF ofQE0KhlUygPgKvMceBPchZ4AVSUej0PavAamb1TRnm21+SuE9GZ6DsPRYG+UrYw2k0h 9gVEngLAThSQXnYsultPLF9Z2GUPth2UVwtC8j8UzOHDB6ZpA9dAo4vo5Vps/Wrm3wbe Z6RvrXwnZfD5CsB7A7fJBe2sg6uI2mOqrYXol5/UXHwY5NHK0v+FPYXhirp2ztKgfXx6 jovg== 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=8VtzSrpbwV9DVLhKb7Zyfszac8XVo7czRmhTzyy53LI=; b=Zt7U+/aa0rPG1KcfozGk47xkVFo/HCzJUJRFdO9UI83zPYKhMQSJ9+5dzz9JvHabEC /K8clrx9vWZ53VAFn1WJXoTsiQWYX/lE9ZOao6NznsieuLM0/75dUAhefdHy92RYkEZQ mdHuz92DMkA/nvaCj2KCxRcDS4W9SJQIJ3sjMywkSwruWNT0mxx/zgXxEOJHe8csL1Xy ZDw8qHLoGabbfscKM7Ph9K02q9D+ww6diIIb5tS3kQlOuoUSz6lIx+Vux61ugf3jJhqa eGQmMlEtjSkNgqB1Y+e6wL5lAcxaDJZuehr4s26NZKCViBvQwzsxs3t6XXsWjZyfxDFR y6Sw== X-Gm-Message-State: AOUpUlGY15fByvYOO3o18uK2Tbp7sA0GVSG54EEC0CIdmB3tTlrSrjGI Jylz5XFwbAX6ZSVvD+4zHXU/3g== X-Google-Smtp-Source: AAOMgpcrlBVhUFmY8uktd8a+RLRQKViOjWsoEe+veqWg7N5c9NS+g0bGlusmcpUE9bWTJBl9UkKonw== X-Received: by 2002:a17:902:1007:: with SMTP id b7-v6mr612966pla.277.1531369326936; Wed, 11 Jul 2018 21:22:06 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Thu, 12 Jul 2018 09:51:20 +0530 Message-Id: <20180712042120.2831-7-shubhamjain7495@gmail.com> In-Reply-To: <20180712042120.2831-1-shubhamjain7495@gmail.com> References: <20180712042120.2831-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 12 Jul 2018 04:22:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 12 Jul 2018 04:22:08 +0000 (UTC) for IP:'209.85.160.49' DOMAIN:'mail-pl0-f49.google.com' HELO:'mail-pl0-f49.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 3.051 *** (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_WEB, SPF_PASS, T_DKIM_INVALID) 209.85.160.49 mail-pl0-f49.google.com 209.85.160.49 mail-pl0-f49.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v5 6/6] 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.49]); Thu, 12 Jul 2018 04:22:21 +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 REST apis. For an authenticated but unauthorised = user the exit status would be 1 ie when no projects are imported. Now importing same message to a project again would not give 404 error. Also changed a test case in test_tags accordingly. --- api/models.py | 3 +++ api/rest.py | 1 + patchew-cli | 18 +++++++++++++----- tests/test_tags.py | 4 +--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/api/models.py b/api/models.py index e0c4fa2..b3ba457 100644 --- a/api/models.py +++ b/api/models.py @@ -361,6 +361,9 @@ class MessageManager(models.Manager): def create(self, project, **validated_data): mbox =3D validated_data.pop('mbox') m =3D MboxMessage(mbox) + msg =3D Message.objects.filter(message_id=3Dm.get_message_id(), pr= oject=3Dproject).first() + if msg is not None: + return msg msg =3D Message(**validated_data) if 'in_reply_to' not in validated_data: msg.in_reply_to =3D m.get_in_reply_to() or "" diff --git a/api/rest.py b/api/rest.py index d714d09..a9b6be3 100644 --- a/api/rest.py +++ b/api/rest.py @@ -423,6 +423,7 @@ class MessagesViewSet(BaseMessageViewSet): serializer_class =3D MessageSerializer permission_classes =3D (permissions.IsAuthenticatedOrReadOnly,) parser_classes =3D (JSONParser, MessagePlainTextParser, ) + authentication_classes =3D (CsrfExemptSessionAuthentication, ) =20 def create(self, request, *args, **kwargs): m =3D MboxMessage(request.data['mbox']) diff --git a/patchew-cli b/patchew-cli index cb0b650..f8d6e57 100755 --- a/patchew-cli +++ b/patchew-cli @@ -221,11 +221,16 @@ 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 ff: open(ff, "wb").close() =20 @@ -251,6 +256,9 @@ class ImportCommand(SubCommand): for f in args.file: try: import_one(f) + if len(projects) =3D=3D 0: + print("The message was not imported to any project. Pe= rhaps you're not logged in as an importer or maintainer") + r =3D 1 except: print("Error in importing:", f) traceback.print_exc() diff --git a/tests/test_tags.py b/tests/test_tags.py index 6c162de..c91e9c1 100755 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -22,9 +22,7 @@ class ImportTest(PatchewTestCase): self.p.save() =20 def test_import_one(self): - resp =3D self.apply_and_retrieve('0017-qemu-web-is-not-qemu.mbox.g= z', - self.p.id, '1504250391-6353-1-git-s= end-email-thuth@redhat.com') - self.assertEquals(resp.status_code, 404) + self.cli_import("0017-qemu-web-is-not-qemu.mbox.gz", rc=3D1) =20 def test_rest_single(self): resp =3D self.apply_and_retrieve('0003-single-patch-reviewed.mbox.= gz', --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel