mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-07-25 10:57:37 +00:00
**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>
28 lines
598 B
Go
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)
|
|
}
|