From nobody Mon Feb 9 22:19:56 2026 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 1530902030303442.4637414079996; Fri, 6 Jul 2018 11:33:50 -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 C166AC057F9F; Fri, 6 Jul 2018 18:33:49 +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 A4A081062244; Fri, 6 Jul 2018 18:33:49 +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 81C674A460; Fri, 6 Jul 2018 18:33:49 +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 w66IXmAL014168 for ; Fri, 6 Jul 2018 14:33:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 69C8C2B4DC; Fri, 6 Jul 2018 18:33:48 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61A642B4D6 for ; Fri, 6 Jul 2018 18:33:48 +0000 (UTC) Received: from mail-pl0-f46.google.com (mail-pl0-f46.google.com [209.85.160.46]) (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 3D9A783F3D for ; Fri, 6 Jul 2018 18:33:37 +0000 (UTC) Received: by mail-pl0-f46.google.com with SMTP id 6-v6so3237874plb.0 for ; Fri, 06 Jul 2018 11:33:37 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.85]) by smtp.gmail.com with ESMTPSA id o4-v6sm19941545pfa.128.2018.07.06.11.33.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Jul 2018 11:33:34 -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=o6BzZ76883LdCXmmzrzt054u79q4IR8x4zSI0FA2Xgw=; b=cX0XSU55tks3SFOlXchpgCb8zBnbly6m1/RCQh5f8rGkOSp03HILpJzXfeV1QnYXKF 4jMxngq3aM2Tkc6eWwANA6wym3FKsVpN1Sa0tS+I3Ard5CPX7lAT2pltVb6VSdQFHpWc yYW0c66d5z4eyLj+4IzwCRsBU4q3tAasLP1eHK2yE8/YOJXT0aWjNHTmo85+iG+RLxOI L8LMuxY4qSfW65N3AaJGo6A6EY0Fj+e5FQD/MNXf13hVAlbf/3vUn/uCOH94NHluO5VJ VeVn5jgEfdFv2dHmMVcKO3c4pQQ58A+fz2HCQfxs4QQzAzm2hF8MVHHFlo+6rx433p8f 9ngw== 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=o6BzZ76883LdCXmmzrzt054u79q4IR8x4zSI0FA2Xgw=; b=Iy1q7bXnEZjtQ6wQuFx652lr07ZJ/SztKquQetd+wCa7FGVVr2gGccC21+3jBVELzq U2u8MXhj1y+4lJPuHBil21/sDPJSoFoCvyJXBhrcod/92aILr03H6EUMzFAV5D4IJvYV scUDhUJc/ELzMOSjaEosKB6btT5OG7spZ6UHqfn9kIExWv84hOgoqK2BrjHSBd34AC6F RtT8RD5HUWN3M+Hjn7DbUHAB+MqKe621josmMypieJzIQz1b4ka3qW5Dc9lSURLEaxvY fu5N+mxYHKNqNoSw9L1oSPYkgmb6YRCkPZ0+NBznky0FSsH9+7pADe84ORztgtrgiyKa Mzmg== X-Gm-Message-State: APt69E20CNT3I7DTLirtvkOOAD06fqE4hxLCEE6UcjguSTa3STqX3uLz btQSyqb2NpzeAGvzpkm9wIkISA== X-Google-Smtp-Source: AAOMgpc9lE/mrcbaLqXlJK7gJLYgjOVMrdfn1i9RsMYdgVnDgb+55+gN1vzRRFm7eUiyZprH9Dsgzw== X-Received: by 2002:a17:902:a702:: with SMTP id w2-v6mr11403285plq.41.1530902016109; Fri, 06 Jul 2018 11:33:36 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Sat, 7 Jul 2018 00:02:07 +0530 Message-Id: <20180706183207.31842-5-shubhamjain7495@gmail.com> In-Reply-To: <20180706183207.31842-1-shubhamjain7495@gmail.com> References: <20180706183207.31842-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 06 Jul 2018 18:33:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 06 Jul 2018 18:33:37 +0000 (UTC) for IP:'209.85.160.46' DOMAIN:'mail-pl0-f46.google.com' HELO:'mail-pl0-f46.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.531 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.46 mail-pl0-f46.google.com 209.85.160.46 mail-pl0-f46.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v4 4/4] 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.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.32]); Fri, 06 Jul 2018 18:33:49 +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 | 5 +++-- patchew-cli | 18 +++++++++++++----- tests/test_tags.py | 4 +--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/api/models.py b/api/models.py index e712149..813a56f 100644 --- a/api/models.py +++ b/api/models.py @@ -359,6 +359,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 c7818c4..876be75 100644 --- a/api/rest.py +++ b/api/rest.py @@ -321,7 +321,7 @@ class SeriesViewSet(BaseMessageViewSet): class ProjectSeriesViewSet(ProjectMessagesViewSetMixin, SeriesViewSet, mixins.DestroyModelMixin): authentication_classes =3D (CsrfExemptSessionAuthentication, ) - =20 + def collect_patches(self, series): if series.is_patch: patches =3D [series] @@ -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 509bb62..d553ea1 100755 --- a/patchew-cli +++ b/patchew-cli @@ -220,11 +220,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 @@ -250,6 +255,9 @@ class ImportCommand(SubCommand): for f in args.file: try: import_one(f) + if len(projects)=3D=3D0: + print("The message was not imported to any project. Pe= rhaps you're not logged in as an importer or maintainer") + r =3D1 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