Files
stpweb/backend/services/permissions.go
T
adamfandClaude Opus 5.5 4530cb8dc4
Test and deploy / test (push) Successful in 28s
Test and deploy / deploy (push) Successful in 31s
Trim comments to the non-obvious why
Drop narration, history and restated-code comments across the repo,
keep short ones for security boundaries, upstream quirks and ordering
constraints, and record the convention in CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 20:49:03 +00:00

34 lines
814 B
Go

package services
import (
"slices"
"adam-french.co.uk/backend/models"
)
// Grantable per-service permissions for non-admins; admins pass every check.
// To add one: an entry below, then `import permission_gate <key>` on its
// route in caddy/routes.caddy.
type PermissionType struct {
Key string
Label string
Path string
}
// Removed keys are inert: the validate endpoint 404s them.
var PermissionTypes = []PermissionType{
{Key: "receipt", Label: "Receipt printer", Path: "/receipt/"},
}
func ValidPermission(key string) bool {
return slices.ContainsFunc(PermissionTypes, func(p PermissionType) bool {
return p.Key == key
})
}
// HasPermission reads the row, not the token.
func HasPermission(user *models.User, key string) bool {
return user.Admin || slices.Contains(user.Permissions, key)
}