mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-07-25 19:07:59 +00:00
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/13143 The details of the refactor are in [a separate branch](https://codeberg.org/limiting-factor/forgejo/commits/branch/wip-api-context-accessors-save) which details how it was done. This pull request contains a squash of those commits rebased on top of the current Forgejo branch, which involved conflict resolution. Given the magnitude of the change, there is a high chance that a large number of future pull requests merged in Forgejo will create conflicts. They will be dealt with in the same way as chore: refactor orgAssignment to two separate middlewares (#13155). ## Review The only risk I can think of is a getter/setter implementation being incorrectly implemented. This is probably where a detailed review is most needed, in the `services/context/api.go` file. To not increase the size of the pull request, the `GetX()` accessors were preserved although they are redundant with `X()`. They will be removed in a followup pull request. ## Backporting strategy. Cherry-picking the commit to v15 has a significant amount of conflicts in 8 files out of 111. ``` unmerged routers/api/v1/activitypub/repository.go unmerged routers/api/v1/admin/user.go unmerged routers/api/v1/api.go unmerged routers/api/v1/org/team.go unmerged routers/api/v1/repo/action.go unmerged routers/api/v1/repo/pull.go unmerged routers/api/v1/user/follower.go unmerged services/context/api.go ``` Instead of resolving them, I think it is easier and safer to repeat the [refactor steps](https://codeberg.org/limiting-factor/forgejo/commits/branch/wip-api-context-accessors-save) in v15. I also think it is worth the effort since it will avoid trivial backport conflicts on over 100 files. ## Context This is a followup pull request discussed originally at https://codeberg.org/forgejo/forgejo/pulls/12512 Co-authored-by: limiting-factor <limiting-factor@posteo.com> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13213 Reviewed-by: limiting-factor <limiting-factor@noreply.codeberg.org> Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
136 lines
3.7 KiB
Go
136 lines
3.7 KiB
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"forgejo.org/routers/api/v1/shared"
|
|
"forgejo.org/services/context"
|
|
)
|
|
|
|
// GetQuota returns the quota information for the authenticated user
|
|
func GetQuota(ctx *context.APIContext) {
|
|
// swagger:operation GET /user/quota user userGetQuota
|
|
// ---
|
|
// summary: Get quota information for the authenticated user
|
|
// produces:
|
|
// - application/json
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/QuotaInfo"
|
|
// "401":
|
|
// "$ref": "#/responses/unauthorized"
|
|
// "403":
|
|
// "$ref": "#/responses/forbidden"
|
|
|
|
shared.GetQuota(ctx, ctx.Doer().ID)
|
|
}
|
|
|
|
// CheckQuota returns whether the authenticated user is over the subject quota
|
|
func CheckQuota(ctx *context.APIContext) {
|
|
// swagger:operation GET /user/quota/check user userCheckQuota
|
|
// ---
|
|
// summary: Check if the authenticated user is over quota for a given subject
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: subject
|
|
// in: query
|
|
// description: subject of the quota
|
|
// type: string
|
|
// required: true
|
|
// responses:
|
|
// "200":
|
|
// description: Returns true if the action is accepted.
|
|
// schema:
|
|
// type: boolean
|
|
// "401":
|
|
// "$ref": "#/responses/unauthorized"
|
|
// "403":
|
|
// "$ref": "#/responses/forbidden"
|
|
// "422":
|
|
// "$ref": "#/responses/validationError"
|
|
|
|
shared.CheckQuota(ctx, ctx.Doer().ID)
|
|
}
|
|
|
|
// ListQuotaAttachments lists attachments affecting the authenticated user's quota
|
|
func ListQuotaAttachments(ctx *context.APIContext) {
|
|
// swagger:operation GET /user/quota/attachments user userListQuotaAttachments
|
|
// ---
|
|
// summary: List the attachments affecting the authenticated user's quota
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: page
|
|
// in: query
|
|
// description: page number of results to return (1-based)
|
|
// type: integer
|
|
// - name: limit
|
|
// in: query
|
|
// description: page size of results
|
|
// type: integer
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/QuotaUsedAttachmentList"
|
|
// "401":
|
|
// "$ref": "#/responses/unauthorized"
|
|
// "403":
|
|
// "$ref": "#/responses/forbidden"
|
|
|
|
shared.ListQuotaAttachments(ctx, ctx.Doer().ID)
|
|
}
|
|
|
|
// ListQuotaPackages lists packages affecting the authenticated user's quota
|
|
func ListQuotaPackages(ctx *context.APIContext) {
|
|
// swagger:operation GET /user/quota/packages user userListQuotaPackages
|
|
// ---
|
|
// summary: List the packages affecting the authenticated user's quota
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: page
|
|
// in: query
|
|
// description: page number of results to return (1-based)
|
|
// type: integer
|
|
// - name: limit
|
|
// in: query
|
|
// description: page size of results
|
|
// type: integer
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/QuotaUsedPackageList"
|
|
// "401":
|
|
// "$ref": "#/responses/unauthorized"
|
|
// "403":
|
|
// "$ref": "#/responses/forbidden"
|
|
|
|
shared.ListQuotaPackages(ctx, ctx.Doer().ID)
|
|
}
|
|
|
|
// ListQuotaArtifacts lists artifacts affecting the authenticated user's quota
|
|
func ListQuotaArtifacts(ctx *context.APIContext) {
|
|
// swagger:operation GET /user/quota/artifacts user userListQuotaArtifacts
|
|
// ---
|
|
// summary: List the artifacts affecting the authenticated user's quota
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: page
|
|
// in: query
|
|
// description: page number of results to return (1-based)
|
|
// type: integer
|
|
// - name: limit
|
|
// in: query
|
|
// description: page size of results
|
|
// type: integer
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/QuotaUsedArtifactList"
|
|
// "401":
|
|
// "$ref": "#/responses/unauthorized"
|
|
// "403":
|
|
// "$ref": "#/responses/forbidden"
|
|
|
|
shared.ListQuotaArtifacts(ctx, ctx.Doer().ID)
|
|
}
|