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]>
34 lines
814 B
Go
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)
|
|
}
|