2022-09-28 09:01:17 +02:00
|
|
|
package acl
|
|
|
|
|
|
|
|
// Predefined grants to simplify configuration.
|
|
|
|
var (
|
2022-09-30 00:42:19 +02:00
|
|
|
GrantFullAccess = Grant{FullAccess: true, AccessAll: true, AccessLibrary: true, ActionCreate: true, ActionUpdate: true, ActionDelete: true, ActionDownload: true, ActionShare: true, ActionRate: true, ActionReact: true, ActionManage: true, ActionSubscribe: true}
|
2022-10-02 11:38:30 +02:00
|
|
|
GrantSearchShared = Grant{AccessShared: true, ActionSearch: true, ActionView: true, ActionDownload: true}
|
2022-09-28 09:01:17 +02:00
|
|
|
GrantSubscribeAll = Grant{AccessAll: true, ActionSubscribe: true}
|
|
|
|
GrantSubscribeOwn = Grant{AccessOwn: true, ActionSubscribe: true}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Grant represents permissions granted or denied.
|
|
|
|
type Grant map[Permission]bool
|
|
|
|
|
|
|
|
// Allow checks whether the permission is granted.
|
|
|
|
func (grant Grant) Allow(perm Permission) bool {
|
|
|
|
if result, ok := grant[perm]; ok {
|
|
|
|
return result
|
|
|
|
} else if result, ok = grant[FullAccess]; ok {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|