Files
RenewCMS/internal/domain/role/roleBuiltIn.go
T

49 lines
1.1 KiB
Go

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(),
},
}
}