feat: roles system backend
This commit is contained in:
1 parent
44cca46d5e
commit
8c6c6456da
50 files changed
+2578
-22
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package role
|
||||
|
||||
const (
|
||||
OwnerName = "Owner"
|
||||
AdminName = "Admin"
|
||||
WriterName = "Writer"
|
||||
)
|
||||
|
||||
func allGrants(include func(Permission) bool) []Grant {
|
||||
grants := []Grant{}
|
||||
for _, permission := range catalogue {
|
||||
if include(permission) {
|
||||
grants = append(grants, Grant{Key: permission.Key, Scope: ScopeAll})
|
||||
}
|
||||
}
|
||||
return grants
|
||||
}
|
||||
|
||||
func writerGrants() []Grant {
|
||||
return []Grant{
|
||||
{Key: "content.read", Scope: ScopeAll},
|
||||
{Key: "content.create", Scope: ScopeAll},
|
||||
{Key: "content.update", Scope: ScopeAll},
|
||||
{Key: "schema.view", Scope: ScopeAll},
|
||||
{Key: "media.view", Scope: ScopeAll},
|
||||
{Key: "media.upload", Scope: ScopeAll},
|
||||
{Key: "authors.view", Scope: ScopeAll},
|
||||
{Key: "authors.edit", Scope: ScopeOwn},
|
||||
{Key: "activity.view", Scope: ScopeOwn},
|
||||
}
|
||||
}
|
||||
|
||||
func BuiltInRoles() []Role {
|
||||
return []Role{
|
||||
{
|
||||
Name: OwnerName, BuiltIn: true, Locked: true, Version: 1,
|
||||
Grants: allGrants(func(Permission) bool { return true }),
|
||||
},
|
||||
{
|
||||
Name: AdminName, BuiltIn: true, Version: 1,
|
||||
Grants: allGrants(func(p Permission) bool { return !p.OwnerOnly }),
|
||||
},
|
||||
{
|
||||
Name: WriterName, BuiltIn: true, Version: 1,
|
||||
Grants: writerGrants(),
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user