Vendor SharedCode locally
This commit is contained in:
1 parent
a8c51b8484
commit
6eb8f4ad60
88 files changed
+9708
-275
No files matched your search
@@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user