added perm checks to season pages

This commit is contained in:
2026-02-09 19:56:42 +11:00
parent 0b3301f921
commit aaf532b835
6 changed files with 83 additions and 107 deletions

View File

@@ -21,3 +21,44 @@ type PermissionCache struct {
Roles map[roles.Role]bool
HasWildcard bool
}
// HasPermission returns true if the cache contains the provided permission
func (p *PermissionCache) HasPermission(perm permissions.Permission) bool {
if p.HasWildcard {
return true
}
_, exists := p.Permissions[perm]
return exists
}
// HasAnyPermission returns true if the cache contains any of the provided permissions
func (p *PermissionCache) HasAnyPermission(perms []permissions.Permission) bool {
if p.HasWildcard {
return true
}
for _, perm := range perms {
_, exists := p.Permissions[perm]
if exists {
return true
}
}
return false
}
// HasAllPermissions returns true only if more than one permission is provided and the cache
// contains all the provided permissions
func (p *PermissionCache) HasAllPermissions(perms []permissions.Permission) bool {
if p.HasWildcard {
return true
}
if len(perms) == 0 {
return false
}
for _, perm := range perms {
_, exists := p.Permissions[perm]
if !exists {
return false
}
}
return true
}