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 ` 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) }