From 9be11ba00cdd847c924a9d5830ae1526651202c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Thu, 8 Jul 2021 14:37:38 +0200 Subject: [PATCH] [feature] transition the package_roles method onto the restful API These changes adds the `package_roles` as results of the return of the `admin.views.project` restful API. The `package_roles` method was available into the xmlrpc, unfortunately these informations are missing into the restful API [1]. These changes adds the creation of an equivalent into the restful API. [1] https://github.com/pypa/warehouse/issues/9700 --- tests/unit/admin/views/test_projects.py | 1 + warehouse/admin/views/projects.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/tests/unit/admin/views/test_projects.py b/tests/unit/admin/views/test_projects.py index 4aea98f28373..e6ad9d2fd363 100644 --- a/tests/unit/admin/views/test_projects.py +++ b/tests/unit/admin/views/test_projects.py @@ -99,6 +99,7 @@ def test_gets_project(self, db_request): "project": project, "releases": [], "maintainers": roles, + "package_roles": [], "journal": journals[:30], "ONE_MB": views.ONE_MB, "MAX_FILESIZE": views.MAX_FILESIZE, diff --git a/warehouse/admin/views/projects.py b/warehouse/admin/views/projects.py index f829814a384f..04fa5a205502 100644 --- a/warehouse/admin/views/projects.py +++ b/warehouse/admin/views/projects.py @@ -111,6 +111,16 @@ def project_detail(project, request): ) ] maintainers = sorted(maintainers, key=lambda x: (x.role_name, x.user.username)) + package_roles = [ + role + for role in ( + request.db.query(Role) + .join(User, Project) + .filter(Project.normalized_name == project) + .order_by(Role.role_name.desc(), User.username) + .all() + ) + ] journal = [ entry for entry in ( @@ -126,6 +136,7 @@ def project_detail(project, request): "project": project, "releases": releases, "maintainers": maintainers, + "package_roles": package_roles, "journal": journal, "ONE_MB": ONE_MB, "MAX_FILESIZE": MAX_FILESIZE,