From nobody Fri Apr 26 16:38:55 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 1522847665521439.24779938352356; Wed, 4 Apr 2018 06:14:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74D70C04BD33; Wed, 4 Apr 2018 13:14:24 +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 550917FB86; Wed, 4 Apr 2018 13:14:24 +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 42B8C4CA96; Wed, 4 Apr 2018 13:14:24 +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 w34DEMn9001171 for ; Wed, 4 Apr 2018 09:14:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD11E5D6A2; Wed, 4 Apr 2018 13:14:22 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2E487A4D0 for ; Wed, 4 Apr 2018 13:14:18 +0000 (UTC) Received: from mail-pl0-f48.google.com (mail-pl0-f48.google.com [209.85.160.48]) (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 A52A08046B for ; Wed, 4 Apr 2018 13:14:17 +0000 (UTC) Received: by mail-pl0-f48.google.com with SMTP id 91-v6so13904207pld.3 for ; Wed, 04 Apr 2018 06:14:17 -0700 (PDT) Received: from localhost.localdomain ([14.141.249.170]) by smtp.gmail.com with ESMTPSA id 67sm10515798pfz.57.2018.04.04.06.14.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Apr 2018 06:14:14 -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=Lq4Zzyz8VsSVuPUOlwH4fLYXK+dtYL2+G3cCG7Ayg6Y=; b=acR0Qx0HA50Rfz8uKbwvl5/XcQ/L0ZogLeeC7UZ0jv/VRkstdkB1/tFkdYyfH3hnca PHHu9J29O5Lvud1ZE0MqexSMuyHv+ZKJ0qJsbyKDhHX4hRaFTyOh+4RmV+f2I8zCbPeE U9mH3NdU6Lz43vvUFm3C2bzlnR6uYHhvVUfiafagQy2p5iNZvw2acG4mQBAbinOuf5pe SDg/LlGh8fo7nEkzSnL+FA9b1OEP5/4b1b4HsHFGkznJPzseh0Dgk55ooGhXmf0Wni/b XSCBzX/4T0jooWQtPGG2f09fCqQWPZiea999VMPspDiwKh16r0x3SYDVTni62SCnl7tb UXuw== 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=Lq4Zzyz8VsSVuPUOlwH4fLYXK+dtYL2+G3cCG7Ayg6Y=; b=RbMXgmC30dmrgfpoUuOW36OZVB2udzEQAEe7XvVkm6B6rpvSuapdP0UXYaBvbwBQ1v WM/qGEakaVSfo0p+6WrEZ7r5jgUIRLyoC0jdk2FJ1rEuhZ4wJHSLVr02ZWC/Q385oAC1 R/Uy3hzLwPeTwY2HCBTCdUbtqucgssCK1hQvBn1hbqTje4hfgERSWFOeHNBBhXD07K+G 66aI8wqbAzzLgLbrlFYVoBgP29K/Vw74+NErKVrtDWKFK9rg+euxkDuTua/KAgpWDC7w m2DSB0cZaX5yft+ix9bnea0oiv/eAsD/ZTv2xGoXUtj4cvYhC9TpXwWA0P15runQF81M 8H5Q== X-Gm-Message-State: AElRT7H3PZT2cb+7CYVv7b0xrQeMK/PQ85fwqWr9lbjchWFm6ELWcqmU qmLVw8+W06/Ntvm6jTXDP9gvxQ== X-Google-Smtp-Source: AIpwx4+XDYVSyyJL9mGO8NwrY4qvAfriTxMB+XVKg1OrZ+hi8i1uI2Nh/yvVWT2XpbuVDGEfEn5UZg== X-Received: by 10.101.76.207 with SMTP id n15mr12271334pgt.313.1522847656471; Wed, 04 Apr 2018 06:14:16 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Wed, 4 Apr 2018 18:43:58 +0530 Message-Id: <20180404131358.15398-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Apr 2018 13:14:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Apr 2018 13:14:17 +0000 (UTC) for IP:'209.85.160.48' DOMAIN:'mail-pl0-f48.google.com' HELO:'mail-pl0-f48.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.139 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.160.48 mail-pl0-f48.google.com 209.85.160.48 mail-pl0-f48.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v3] rest: add support for series DELETE in the REST API, and a corresponding unit test 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 04 Apr 2018 13:14:24 +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" rest: Imporoved series DELETE in the REST API - Fixed the char limit in line to make code more readable - overrode perform_destroy function so that that endpoint accepts any messa= ge id and not just the series head - wrote tests for the same Message-Id: <20180331122557.44970-1-shubhamjain7495@gmail.com> rest: Added permission class - Added permission to deletion and restricted it to avoid public deletion. - Added a corresponding unit test to it. - Also overrode perform_destroy instead of destory to perform series deleti= on. --- api/rest.py | 7 ++++++- tests/test_rest.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/api/rest.py b/api/rest.py index 7c131a4..6aa744d 100644 --- a/api/rest.py +++ b/api/rest.py @@ -229,9 +229,11 @@ class SeriesViewSet(BaseMessageViewSet): queryset =3D Message.objects.filter(is_series_head=3DTrue).order_by('-= last_reply_date') filter_backends =3D (PatchewSearchFilter,) search_fields =3D (SEARCH_PARAM,) + permission_classes =3D (IsAdminUserOrReadOnly,) + =20 class ProjectSeriesViewSet(ProjectMessagesViewSetMixin, - SeriesViewSet): + SeriesViewSet, mixins.DestroyModelMixin): def collect_patches(self, series): if series.is_patch: patches =3D [series] @@ -265,6 +267,9 @@ class ProjectSeriesViewSet(ProjectMessagesViewSetMixin, self.collect_replies(i, series.replies) return series =20 + def perform_destroy(self, instance): + Message.objects.delete_subthread(instance) + # Messages =20 # TODO: add POST endpoint connected to email plugin? diff --git a/tests/test_rest.py b/tests/test_rest.py index 28ca10b..5b22067 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -218,6 +218,31 @@ class RestTest(PatchewTestCase): resp =3D self.api_client.get(self.REST_BASE + 'projects/12345/seri= es/?q=3Dproject:QEMU') self.assertEqual(resp.data['count'], 0) =20 + def test_series_delete(self): + test_message_id =3D '1469192015-16487-1-git-send-email-berrange@re= dhat.com' + series =3D self.apply_and_retrieve('0004-multiple-patch-reviewed.m= box.gz',self.p.id, + test_message_id) =20 + message =3D series.data['message'] + resp_before =3D self.api_client.get(self.REST_BASE + 'projects/' += str(self.p.id)=20 + + '/series/' + test_message_id += '/') + resp_reply_before =3D self.api_client.get(message + 'replies/') + resp_without_login =3D self.api_client.delete(self.REST_BASE + 'pr= ojects/' + str(self.p.id)=20 + + '/series/' + test_message_id + '/') + self.api_client.login(username=3Dself.user, password=3Dself.passwo= rd) =20 + resp =3D self.api_client.delete(self.REST_BASE + 'projects/' + str= (self.p.id)=20 + + '/series/' + test_message_id + '/') + self.api_client.logout() + resp_after =3D self.api_client.get(self.REST_BASE + 'projects/' + = str(self.p.id)=20 + + '/series/' + test_message_id + = '/') + resp_reply_after =3D self.api_client.get(message + 'replies/') + =20 + self.assertEqual(resp_before.status_code, 200) + self.assertEqual(resp_reply_before.status_code, 200) + self.assertEqual(resp_without_login.status_code, 403) + self.assertEqual(resp.status_code, 204) + self.assertEqual(resp_after.status_code, 404) + self.assertEqual(resp_reply_after.status_code, 404) + def test_message(self): series =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', self.p.id, '20160628014747.20971-= 1-famz@redhat.com') --=20 2.14.3 (Apple Git-98) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel