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

41 lines
782 B
Go

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
}