Files
CollabTable/SharedCode/backend/auth/roles.go
T
Gabriel20xx 6eb8f4ad60
Docker / Docker Build & Push (push) Failing after 1m19s
Lint / Lint (push) Successful in 15s
Tests / Go backend (push) Successful in 19s
Tests / Dashboard checks (push) Successful in 18s
Vendor SharedCode locally
2026-08-06 15:52:56 +02:00

35 lines
996 B
Go

package auth
// Role is the shared account-management role used by the web applications.
type Role string
const (
RoleSuperAdmin Role = "superadmin"
RoleAdmin Role = "admin"
RoleUser Role = "user"
)
// NormalizeRole keeps persisted role values inside the shared contract.
func NormalizeRole(value string) Role {
switch Role(value) {
case RoleSuperAdmin:
return RoleSuperAdmin
case RoleAdmin:
return RoleAdmin
default:
return RoleUser
}
}
// CanManageUsers is the common authorization gate for account CRUD.
func CanManageUsers(role string) bool {
role = string(NormalizeRole(role))
return role == string(RoleSuperAdmin) || role == string(RoleAdmin)
}
// CanAssignRole prevents an administrator from creating or promoting another
// administrator. Only the first-created superadmin can delegate admin access.
func CanAssignRole(actorRole, targetRole string) bool {
return NormalizeRole(actorRole) == RoleSuperAdmin && NormalizeRole(targetRole) != RoleSuperAdmin
}