gitforge/routers/api/v1/permissions/helpers.go
forgejo-backport-action fb0ab1e5fa [v16.0/forgejo] chore(refactor): remove GetX redundant accessors and use X in services/context/api.go (#13217)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/13215

Followup of the refactor adding setter/getter to APIContext  https://codeberg.org/forgejo/forgejo/pulls/13143

- Only has an impact on the getters used by `routers/api/v1/permissions`
- When GetX and X both exist, remove GetX
- When GetX exists and X does not, rename GetX to X
- GetOrg is an exception as it would conflict with Org and is renamed Organization. This is due to APIContext having its own Org structure that includes an Organization.

Co-authored-by: limiting-factor <limiting-factor@posteo.com>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13217
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
2026-06-27 22:44:01 +02:00

28 lines
598 B
Go

// Copyright 2026 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package permissions
import (
"slices"
"forgejo.org/models/unit"
)
func IsUserSiteAdmin(ctx Context) bool {
if !ctx.Reducer().AllowAdminOverride() {
return false
}
return ctx.IsSigned() && ctx.Doer().IsAdmin
}
func IsUserRepoAdmin(ctx Context) bool {
if !ctx.Reducer().AllowAdminOverride() {
return false
}
return ctx.Permission().IsAdmin()
}
func IsUserRepoWriter(ctx Context, unitTypes []unit.Type) bool {
return slices.ContainsFunc(unitTypes, ctx.Permission().CanWrite)
}