From nobody Fri Apr 19 19:49:39 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; 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 1522174688051794.4368248384249; Tue, 27 Mar 2018 11:18:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B0D223E6C1; Tue, 27 Mar 2018 18:18:07 +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 10F57600D2; Tue, 27 Mar 2018 18:18:07 +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 0793A181BA02; Tue, 27 Mar 2018 18:18:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2RII57v013783 for ; Tue, 27 Mar 2018 14:18:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6EB4E2026985; Tue, 27 Mar 2018 18:18:05 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A5B52026E03 for ; Tue, 27 Mar 2018 18:18:04 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Wed, 28 Mar 2018 02:17:55 +0800 Message-Id: <20180327181756.23938-2-famz@redhat.com> In-Reply-To: <20180327181756.23938-1-famz@redhat.com> References: <20180327181756.23938-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 1/2] api: Expose project properties to importers 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 27 Mar 2018 18:18:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Importers need it for project update. Introduce and use Project.properties_visible() method to fix the permission problem. Signed-off-by: Fam Zheng --- api/models.py | 4 ++++ api/views.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/models.py b/api/models.py index a672bd4..955a91c 100644 --- a/api/models.py +++ b/api/models.py @@ -134,6 +134,10 @@ class Project(models.Model): return True return False =20 + def properties_visible(self, user): + return self.maintained_by(user) or \ + user.groups.filter(name=3D'importers').exists() + def recognizes(self, m): """Test if @m is considered a message in this project""" addr_ok =3D False diff --git a/api/views.py b/api/views.py index 2d84be8..122a4d9 100644 --- a/api/views.py +++ b/api/views.py @@ -85,7 +85,7 @@ class ListProjectView(APIView): "git": p.git, "description": p.description, } - if p.maintained_by(request.user): + if p.properties_visible(request.user): ret["properties"] =3D p.get_properties() return ret =20 @@ -111,7 +111,7 @@ class GetProjectPropertiesView(APIView): =20 def handle(self, request, project): po =3D Project.objects.get(name=3Dproject) - if not po.maintained_by(request.user): + if not po.properties_visible(request.user): raise PermissionDenied("Access denied to this project") return po.get_properties() =20 --=20 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Apr 19 19:49:39 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; 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 1522174689534262.4981447284198; Tue, 27 Mar 2018 11:18:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 95755C024FF0; Tue, 27 Mar 2018 18:18:08 +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 8B896600D2; Tue, 27 Mar 2018 18:18:08 +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 82D4A4CA96; Tue, 27 Mar 2018 18:18:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2RII7nV013799 for ; Tue, 27 Mar 2018 14:18:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 047252026985; Tue, 27 Mar 2018 18:18:07 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11BBE2026E03 for ; Tue, 27 Mar 2018 18:18:05 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Wed, 28 Mar 2018 02:17:56 +0800 Message-Id: <20180327181756.23938-3-famz@redhat.com> In-Reply-To: <20180327181756.23938-1-famz@redhat.com> References: <20180327181756.23938-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 2/2] tests: Add test for project update 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 27 Mar 2018 18:18:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng --- tests/patchewtest.py | 10 ++++++++++ tests/test_git.py | 8 +------- tests/test_import.py | 10 +++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/patchewtest.py b/tests/patchewtest.py index 1b0a867..7e51e70 100644 --- a/tests/patchewtest.py +++ b/tests/patchewtest.py @@ -134,6 +134,16 @@ class PatchewTestCase(django.test.LiveServerTestCase): self.assertEqual(uri, '%sprojects/%d/series/%s/' % (self.REST_= BASE, project_id, msgid)) return response =20 + def create_git_repo(self, name=3D"test-repo"): + repo =3D os.path.join(self.get_tmpdir(), name) + os.mkdir(repo) + subprocess.check_output(["git", "init"], cwd=3Drepo) + subprocess.check_output(["touch", "foo"], cwd=3Drepo) + subprocess.check_output(["git", "add", "foo"], cwd=3Drepo) + subprocess.check_output(["git", "commit", "-m", "initial commit"], + cwd=3Drepo) + return repo + def parse_args(): parser =3D argparse.ArgumentParser() parser.add_argument("--debug", "-d", action=3D"store_true", diff --git a/tests/test_git.py b/tests/test_git.py index c2c98ae..543f863 100755 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -21,13 +21,7 @@ class GitTest(PatchewTestCase): def setUp(self): self.create_superuser() self.cli_login() - self.repo =3D os.path.join(self.get_tmpdir(), "repo") - os.mkdir(self.repo) - subprocess.check_output(["git", "init"], cwd=3Dself.repo) - subprocess.check_output(["touch", "foo"], cwd=3Dself.repo) - subprocess.check_output(["git", "add", "foo"], cwd=3Dself.repo) - subprocess.check_output(["git", "commit", "-m", "initial commit"], - cwd=3Dself.repo) + self.repo =3D self.create_git_repo() self.p =3D self.add_project("QEMU", "qemu-devel@nongnu.org", git_r= epo=3Dself.repo) self.p.set_property("git.push_to", self.repo) self.p.set_property("git.public_repo", self.repo) diff --git a/tests/test_import.py b/tests/test_import.py index 23d0d43..3ad7592 100755 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -13,7 +13,7 @@ import os sys.path.append(os.path.dirname(__file__)) from patchewtest import PatchewTestCase, main import json -from api.models import Message +from api.models import Message, Project =20 class ImportTest(PatchewTestCase): =20 @@ -123,5 +123,13 @@ class UnprivilegedImportTest(ImportTest): self.cli_login("someuser", "somepass") self.check_import_should_fail() =20 + def test_project_update(self): + p =3D Project.objects.all()[0] + + repo =3D self.create_git_repo() + p.git =3D repo + p.save() + self.check_cli(["project", "update"]) + if __name__ =3D=3D '__main__': main() --=20 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel