From nobody Wed May 14 16:11:57 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=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534581598419488.90214853993507; Sat, 18 Aug 2018 01:39:58 -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 3DA53308A953; Sat, 18 Aug 2018 08:39:57 +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 277AF101F94C; Sat, 18 Aug 2018 08:39:57 +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 186DF4BB78; Sat, 18 Aug 2018 08:39:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8dtC6013229 for ; Sat, 18 Aug 2018 04:39:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 918BB17DFB; Sat, 18 Aug 2018 08:39:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8646D608E5 for ; Sat, 18 Aug 2018 08:39:53 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) (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 8B99B3DE3D for ; Sat, 18 Aug 2018 08:39:52 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id i134-v6so3076010wmf.0 for ; Sat, 18 Aug 2018 01:39:52 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=2bvch3jeGdg3kMKv1GTLzRgVLdheS1DBdveTdYPxmWI=; b=OdvbIXnzDWN37HBPYHERq5ov3zofzYC+q5nWgynIawysE0oN75QFC8paPvQJYulBtO DMzpSVfCcTsedr1c6nRqY7IhNxYBWHysfd7MPL83/yJDlLGgH8LrsiHzDArsIQ0b64eq b2GBmZat7u0StIV7aZeO/X5qtj28Kbf1KIMsOYZVdJIC1hql2QJJ/iheIBq0p754GNS0 rDoaEzQi7zMCObNa2eEMmQuyMKyCUc4405vbw41brHaBDO/pMB43fMG2grq+izrl8qg4 QiHyLNPbfe60j82WppyBCFehcbnfcTMlZgjdx/aHrorD3Nwnxn6VsBwE3Led8966JChA KKsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=2bvch3jeGdg3kMKv1GTLzRgVLdheS1DBdveTdYPxmWI=; b=bAhQBUStYOAYN2BxzC4Vk4S+L+7ny7P7x5tSQxkHFEwmjiyP3HHyFP/WDl00PaVOzg duAPiGBTBAiD6PkjpbhkD+nE0P+oDGB7bir8KgzLG+E2TAR8NggpK+hiisgfsablI9Od aPLeTTuYYDyBmddr91hdvHBCyxQ+/sdaE1GfymMnO641PBRX0IiiTfOX7mgtVoOs2GvN Nk928dmskc0c807f2oyUQjivMw6i3qp2+QG2hjv5us1mRMVuEHJYWcqeK4HIXrqA9mXF 6/84aFgIajbzv2lR5Julzl2R9BKAVX1lTvhjZLgiHIOrY/gXP/iwquiIhxgzdEP8qzPH CIqw== X-Gm-Message-State: AOUpUlGULNeJGlQ4m7OYD0d/rHJWLOEBL6kIK4soDOt9s8spnosJ4fC2 hrUXNP2W1RduMu1jCNeIxLjd+3lv X-Google-Smtp-Source: AA+uWPxkMtbQpDDwhwh+rMShesi3xusAVtPBN+LbZN2wNbsdGdlzh4yTeBFlQNDgopAzwdcI11Eg9g== X-Received: by 2002:a1c:2d54:: with SMTP id t81-v6mr22066792wmt.31.1534581591032; Sat, 18 Aug 2018 01:39:51 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:40 +0200 Message-Id: <20180818083944.19692-6-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 18 Aug 2018 08:39:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 18 Aug 2018 08:39:52 +0000 (UTC) for IP:'74.125.82.66' DOMAIN:'mail-wm0-f66.google.com' HELO:'mail-wm0-f66.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.028 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.66 mail-wm0-f66.google.com 74.125.82.66 mail-wm0-f66.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 5/9] rest: simplify PatchewPermission 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.41]); Sat, 18 Aug 2018 08:39:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Because has_permission is always invoked before has_object_permission, and both must pass for the request to be allowed, it is not necessary to check obj.project.maintained_by for messages. Signed-off-by: Paolo Bonzini --- api/rest.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/api/rest.py b/api/rest.py index 646d6ad..2b0b611 100644 --- a/api/rest.py +++ b/api/rest.py @@ -48,9 +48,6 @@ class PatchewPermission(permissions.BasePermission): def has_project_permission(self, request, view, obj): return obj.maintained_by(request.user) =20 - def has_message_permission(self, request, view, obj): - return obj.project.maintained_by(request.user) - def has_group_permission(self, request, view): for grp in request.user.groups.all(): if grp.name in self.allowed_groups: @@ -68,11 +65,12 @@ class PatchewPermission(permissions.BasePermission): self.has_project_permission(request, view, view.project)) =20 def has_object_permission(self, request, view, obj): + # For non-project objects, has_project_permission has been evaluat= ed + # already in has_permission, based on the primary key included in = the + # URL. return self.has_generic_permission(request, view) or \ - (isinstance(obj, Message) and \ - self.has_message_permission(request, view, obj)) or \ - (isinstance(obj, Project) and \ - self.has_project_permission(request, view, obj)) + not isinstance(obj, Project) or \ + self.has_project_permission(request, view, obj) =20 class ImportPermission(PatchewPermission): allowed_groups =3D ('importers',) --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel