:p
atchew
Login
One bug in permission code prevents patchew-importer-next from doing project update. Fam Zheng (2): api: Expose project properties to importers tests: Add test for project update api/models.py | 4 ++++ api/views.py | 4 ++-- tests/patchewtest.py | 10 ++++++++++ tests/test_git.py | 8 +------- tests/test_import.py | 10 +++++++++- 5 files changed, 26 insertions(+), 10 deletions(-) -- 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel
Importers need it for project update. Introduce and use Project.properties_visible() method to fix the permission problem. Signed-off-by: Fam Zheng <famz@redhat.com> --- 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 XXXXXXX..XXXXXXX 100644 --- a/api/models.py +++ b/api/models.py @@ -XXX,XX +XXX,XX @@ class Project(models.Model): return True return False + def properties_visible(self, user): + return self.maintained_by(user) or \ + user.groups.filter(name='importers').exists() + def recognizes(self, m): """Test if @m is considered a message in this project""" addr_ok = False diff --git a/api/views.py b/api/views.py index XXXXXXX..XXXXXXX 100644 --- a/api/views.py +++ b/api/views.py @@ -XXX,XX +XXX,XX @@ class ListProjectView(APIView): "git": p.git, "description": p.description, } - if p.maintained_by(request.user): + if p.properties_visible(request.user): ret["properties"] = p.get_properties() return ret @@ -XXX,XX +XXX,XX @@ class GetProjectPropertiesView(APIView): def handle(self, request, project): po = Project.objects.get(name=project) - 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() -- 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel
Signed-off-by: Fam Zheng <famz@redhat.com> --- 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 XXXXXXX..XXXXXXX 100644 --- a/tests/patchewtest.py +++ b/tests/patchewtest.py @@ -XXX,XX +XXX,XX @@ class PatchewTestCase(django.test.LiveServerTestCase): self.assertEqual(uri, '%sprojects/%d/series/%s/' % (self.REST_BASE, project_id, msgid)) return response + def create_git_repo(self, name="test-repo"): + repo = os.path.join(self.get_tmpdir(), name) + os.mkdir(repo) + subprocess.check_output(["git", "init"], cwd=repo) + subprocess.check_output(["touch", "foo"], cwd=repo) + subprocess.check_output(["git", "add", "foo"], cwd=repo) + subprocess.check_output(["git", "commit", "-m", "initial commit"], + cwd=repo) + return repo + def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--debug", "-d", action="store_true", diff --git a/tests/test_git.py b/tests/test_git.py index XXXXXXX..XXXXXXX 100755 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -XXX,XX +XXX,XX @@ class GitTest(PatchewTestCase): def setUp(self): self.create_superuser() self.cli_login() - self.repo = os.path.join(self.get_tmpdir(), "repo") - os.mkdir(self.repo) - subprocess.check_output(["git", "init"], cwd=self.repo) - subprocess.check_output(["touch", "foo"], cwd=self.repo) - subprocess.check_output(["git", "add", "foo"], cwd=self.repo) - subprocess.check_output(["git", "commit", "-m", "initial commit"], - cwd=self.repo) + self.repo = self.create_git_repo() self.p = self.add_project("QEMU", "qemu-devel@nongnu.org", git_repo=self.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 XXXXXXX..XXXXXXX 100755 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -XXX,XX +XXX,XX @@ 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 class ImportTest(PatchewTestCase): @@ -XXX,XX +XXX,XX @@ class UnprivilegedImportTest(ImportTest): self.cli_login("someuser", "somepass") self.check_import_should_fail() + def test_project_update(self): + p = Project.objects.all()[0] + + repo = self.create_git_repo() + p.git = repo + p.save() + self.check_cli(["project", "update"]) + if __name__ == '__main__': main() -- 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel
v2: Fixing by reverting. [Paolo] One bug in permission code prevents patchew-importer-next from doing project update. Fam Zheng (2): Revert "unify permissions for project properties" tests: Add test for project update api/views.py | 25 ++++++++++++------------- tests/patchewtest.py | 10 ++++++++++ tests/test_git.py | 8 +------- tests/test_import.py | 10 +++++++++- 4 files changed, 32 insertions(+), 21 deletions(-) -- 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel
This reverts commit d023d5e60a0a15f6f81835f85c9233a96a87ef00. The commit made project properties invisible to non-priviledged users including importers, who need the information for doing project updates. Signed-off-by: Fam Zheng <famz@redhat.com> --- api/views.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/api/views.py b/api/views.py index XXXXXXX..XXXXXXX 100644 --- a/api/views.py +++ b/api/views.py @@ -XXX,XX +XXX,XX @@ class VersionView(APIView): def handle(self, request): return settings.VERSION +def prepare_project(p): + ret = { + "name": p.name, + "mailing_list": p.mailing_list, + "url": p.url, + "git": p.git, + "description": p.description, + "properties": p.get_properties(), + } + return ret + class ListProjectView(APIView): name = "get-projects" def handle(self, request, name=None): - def prepare_project(p): - ret = { - "name": p.name, - "mailing_list": p.mailing_list, - "url": p.url, - "git": p.git, - "description": p.description, - } - if p.maintained_by(request.user): - ret["properties"] = p.get_properties() - return ret - r = [prepare_project(x) for x in Project.objects.all() \ if name == None or name == x.name] return r @@ -XXX,XX +XXX,XX @@ class AddProjectView(APILoginRequiredView): description=description) p.save() -class GetProjectPropertiesView(APIView): +class GetProjectPropertiesView(APILoginRequiredView): name = "get-project-properties" def handle(self, request, project): -- 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel
Signed-off-by: Fam Zheng <famz@redhat.com> --- 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 XXXXXXX..XXXXXXX 100644 --- a/tests/patchewtest.py +++ b/tests/patchewtest.py @@ -XXX,XX +XXX,XX @@ class PatchewTestCase(django.test.LiveServerTestCase): self.assertEqual(uri, '%sprojects/%d/series/%s/' % (self.REST_BASE, project_id, msgid)) return response + def create_git_repo(self, name="test-repo"): + repo = os.path.join(self.get_tmpdir(), name) + os.mkdir(repo) + subprocess.check_output(["git", "init"], cwd=repo) + subprocess.check_output(["touch", "foo"], cwd=repo) + subprocess.check_output(["git", "add", "foo"], cwd=repo) + subprocess.check_output(["git", "commit", "-m", "initial commit"], + cwd=repo) + return repo + def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--debug", "-d", action="store_true", diff --git a/tests/test_git.py b/tests/test_git.py index XXXXXXX..XXXXXXX 100755 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -XXX,XX +XXX,XX @@ class GitTest(PatchewTestCase): def setUp(self): self.create_superuser() self.cli_login() - self.repo = os.path.join(self.get_tmpdir(), "repo") - os.mkdir(self.repo) - subprocess.check_output(["git", "init"], cwd=self.repo) - subprocess.check_output(["touch", "foo"], cwd=self.repo) - subprocess.check_output(["git", "add", "foo"], cwd=self.repo) - subprocess.check_output(["git", "commit", "-m", "initial commit"], - cwd=self.repo) + self.repo = self.create_git_repo() self.p = self.add_project("QEMU", "qemu-devel@nongnu.org", git_repo=self.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 XXXXXXX..XXXXXXX 100755 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -XXX,XX +XXX,XX @@ 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 class ImportTest(PatchewTestCase): @@ -XXX,XX +XXX,XX @@ class UnprivilegedImportTest(ImportTest): self.cli_login("someuser", "somepass") self.check_import_should_fail() + def test_project_update(self): + p = Project.objects.all()[0] + + repo = self.create_git_repo() + p.git = repo + p.save() + self.check_cli(["project", "update"]) + if __name__ == '__main__': main() -- 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel