Skip to content

feat(api): list all packages for site administrators - #38968

Open
lunny wants to merge 3 commits into
go-gitea:mainfrom
lunny:feature/admin-packages-api
Open

feat(api): list all packages for site administrators#38968
lunny wants to merge 3 commits into
go-gitea:mainfrom
lunny:feature/admin-packages-api

Conversation

@lunny

@lunny lunny commented Aug 18, 2026

Copy link
Copy Markdown
Member

Add GET /admin/packages so site administrators can review packages across every owner without querying each owner separately.

It returns the same package version representation as GET /packages/{owner} and supports page, limit, type, and q filters.


Assisted by Codet(DeepSeek)

Add GET /admin/packages so admins can review packages across every owner
instead of querying each owner separately. It returns the same package
version representation as GET /packages/{owner} and supports page, limit,
type, and q filters.

Assisted-by: Codet:unknown
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 18, 2026
@github-actions github-actions Bot added topic/api Concerns mainly the API type/feature Completely new functionality. Can only be merged if feature freeze is not active. labels Aug 18, 2026
Comment thread routers/api/v1/admin/packages.go Outdated

@bircni bircni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:

  • Tests cover the unique behavior (admin sees another owner’s package, non-admin is forbidden) but not q/type, pagination, or X-Total-Count/Link headers. --> same as for others
  • The swagger type enum omits arch, same as GET /packages/{owner}.

Comment thread tests/integration/api_admin_packages_test.go Outdated
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Aug 18, 2026
Co-authored-by: bircni <bircni@icloud.com>
Signed-off-by: bircni <bircni@icloud.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new site-admin API endpoint to list package versions across the entire instance (GET /api/v1/admin/packages), aligning the response shape and query filters with the existing owner-scoped packages listing API.

Changes:

  • Adds GET /admin/packages under the existing admin API route group (site-admin + admin-scope protected).
  • Implements the handler to search package versions with pagination and type/q filters and returns api.Package payloads.
  • Adds an integration test and updates generated Swagger/OpenAPI specs for the new endpoint.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/integration/api_admin_packages_test.go Adds integration coverage for listing packages as admin and forbidding non-admin access.
templates/swagger/v1-swagger.generated.json Documents GET /admin/packages in Swagger v2 output.
templates/swagger/v1-openapi3.generated.json Documents GET /admin/packages in OpenAPI v3 output.
routers/api/v1/api.go Registers the new admin route GET /admin/packages.
routers/api/v1/admin/packages.go Implements the admin packages listing handler and its Swagger annotation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/integration/api_admin_packages_test.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
Comment on lines +53 to +67
func TestAPIAdminListPackagesForbidden(t *testing.T) {
defer tests.PrepareTestEnv(t)()

token := getUserToken(t, "user2", auth_model.AccessTokenScopeReadAdmin)
req := NewRequest(t, "GET", "/api/v1/admin/packages").
AddTokenAuth(token)
MakeRequest(t, req, http.StatusForbidden)
}

func TestAPIAdminListPackagesNotLoggedIn(t *testing.T) {
defer tests.PrepareTestEnv(t)()

req := NewRequest(t, "GET", "/api/v1/admin/packages")
MakeRequest(t, req, http.StatusUnauthorized)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to test every endpoint under /admin path?

Does it really make sense?

If there are bugs, isn't the middleware's problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 1 This PR needs approval from one additional maintainer to be merged. topic/api Concerns mainly the API type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants