Skip to content

Commit

Permalink
Provide a project's users via the JSON API
Browse files Browse the repository at this point in the history
Closes pypi#16999
  • Loading branch information
warsaw committed Oct 30, 2024
1 parent 4ae96f9 commit 694043d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/unit/legacy/api/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
JournalEntryFactory,
ProjectFactory,
ReleaseFactory,
RoleFactory,
)


Expand Down Expand Up @@ -210,7 +211,9 @@ def test_renders(self, pyramid_config, db_request, db_session):
)
for r in releases[1:]
]
user = UserFactory.create()
user = UserFactory.create(username="guido")
RoleFactory.create(user=user, project=project)

JournalEntryFactory.reset_sequence()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)

Expand Down Expand Up @@ -260,6 +263,7 @@ def test_renders(self, pyramid_config, db_request, db_session):
"requires_dist": None,
"requires_python": None,
"summary": None,
"users": ["guido"],
"yanked": False,
"yanked_reason": None,
"version": "3.0",
Expand Down Expand Up @@ -533,7 +537,14 @@ def test_detail_renders(self, pyramid_config, db_request, db_session):
)
for r in releases[1:]
]
user = UserFactory.create()

user = UserFactory.create(username="guido")
RoleFactory.create(user=user, project=project)
RoleFactory.create(user=UserFactory.create(username="dstufft"), project=project)
RoleFactory.create(
user=UserFactory.create(username="ewdurbin"), project=project
)

JournalEntryFactory.reset_sequence()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)

Expand Down Expand Up @@ -584,6 +595,7 @@ def test_detail_renders(self, pyramid_config, db_request, db_session):
"requires_dist": None,
"requires_python": None,
"summary": None,
"users": ["dstufft", "ewdurbin", "guido"],
"yanked": False,
"yanked_reason": None,
"version": "3.0",
Expand Down Expand Up @@ -625,7 +637,12 @@ def test_minimal_renders(self, pyramid_config, db_request):
size=200,
)

user = UserFactory.create()
user = UserFactory.create(username="dstufft")
RoleFactory.create(user=user, project=project)
RoleFactory.create(
user=UserFactory.create(username="ewdurbin"), project=project
)

JournalEntryFactory.reset_sequence()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)

Expand Down Expand Up @@ -676,6 +693,7 @@ def test_minimal_renders(self, pyramid_config, db_request):
"requires_dist": None,
"requires_python": None,
"summary": None,
"users": ["dstufft", "ewdurbin"],
"yanked": False,
"yanked_reason": None,
"version": "0.1",
Expand Down
16 changes: 16 additions & 0 deletions warehouse/legacy/api/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
Project,
Release,
ReleaseURL,
Role,
User,
)
from warehouse.utils.cors import _CORS_HEADERS

Expand Down Expand Up @@ -65,6 +67,19 @@ def _json_data(request, project, release, *, all_releases):
.filter(Release.project == project)
)

# Get all of the maintainers for this project.
maintainers = [
r.user
for r in (
request.db.query(Role)
.join(User)
.filter(Role.project == project)
.distinct(User.username)
.order_by(User.username)
.all()
)
]

# If we're not looking for all_releases, then we'll filter this further
# to just this release.
if not all_releases:
Expand Down Expand Up @@ -158,6 +173,7 @@ def _json_data(request, project, release, *, all_releases):
"author_email": release.author_email,
"maintainer": release.maintainer,
"maintainer_email": release.maintainer_email,
"users": sorted(user.username for user in maintainers),
"requires_python": release.requires_python,
"platform": release.platform,
"downloads": {"last_day": -1, "last_week": -1, "last_month": -1},
Expand Down

0 comments on commit 694043d

Please sign in to comment.