feat: more role backend and admin/writer roles additions and adjustments

This commit is contained in:
Florian Sylvain committed 2026-10-26 18:15:26 +01:00
1 parent 8c6c6456da
commit de142f6c5f
131 files changed
+2663 -435

No files matched your search

+2
View File
@@ -11,6 +11,8 @@ var (
ErrRoleConflict = errors.New("role was modified concurrently")
ErrInvalidScope = errors.New("invalid scope for permission")
ErrOwnerOnlyGrant = errors.New("owner-only permission granted to a non-owner role")
ErrMissingPermission = errors.New("missing permission")
)
type Scope string
+40
View File
@@ -0,0 +1,40 @@
package role
type MissingPermissionError struct {
Key string
}
func (e MissingPermissionError) Error() string {
return ErrMissingPermission.Error() + ": " + e.Key
}
func (e MissingPermissionError) Is(target error) bool {
return target == ErrMissingPermission
}
type GrantSet map[string]Scope
func NewGrantSet(grants []Grant) GrantSet {
set := make(GrantSet, len(grants))
for _, grant := range grants {
set[grant.Key] = grant.Scope
}
return set
}
func (g GrantSet) Scope(key string) Scope {
scope, present := g[key]
if !present {
return ScopeNone
}
return scope
}
func (g GrantSet) Holds(key string) bool {
scope := g.Scope(key)
return scope == ScopeOwn || scope == ScopeAll
}
func (g GrantSet) HoldsAll(key string) bool {
return g.Scope(key) == ScopeAll
}
+11
View File
@@ -0,0 +1,11 @@
package role
const (
KeyActivityView = "activity.view"
KeyActivityExport = "activity.export"
KeyAPIKeysView = "apikeys.view"
KeyAPIKeysRevoke = "apikeys.revoke"
KeyAuthorsEdit = "authors.edit"
KeyUsersView = "users.view"
KeyApplyUpdates = "system.apply_updates"
)