Access was admin or nothing, so letting a friend print receipts meant making them a full admin. Users now carry a list of permissions (User.Permissions, a JSON column), each a key from the registry in services/permissions.go; admins pass every check. The only key so far is `receipt`. GET /auth/validate/:permission answers like /auth/validate-admin (200/403/401, with the same refresh-token fallback, now shared) plus 404 for an unknown key, and reads the user row rather than the token, so a grant or revoke applies on the next request. On 200 it returns the username in X-Auth-User. nginx gets a permission gate beside the admin gate: a location sets $auth_permission and auth_requests /internal/auth/validate. /receipt/ moves onto it, forwarding X-Remote-User to the receipt server. 403 now goes to /no-access rather than back to the login page. The variable must not be given a server-level default: the subrequest re-runs the server rewrite phase and would blank it. The admin panel's Manage Users tab ticks permissions per user (setUserPermissions, permissionTypes). The login page is no longer admin-only in wording or destination: a non-admin lands on /account, which lists the services they can open; /no-access is the same view with a notice. /auth/validate-admin and every other admin-gated service are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
40 lines
1.1 KiB
GraphQL
40 lines
1.1 KiB
GraphQL
type User {
|
|
id: ID!
|
|
createdAt: Time!
|
|
updatedAt: Time!
|
|
username: String!
|
|
admin: Boolean!
|
|
# Keys of the gated services this user may use (see PermissionType). Admins
|
|
# pass every permission check whatever this holds.
|
|
permissions: [String!]!
|
|
}
|
|
|
|
# One grantable service, from services.PermissionTypes: `key` is what is
|
|
# stored and what nginx gates on, `label` and `path` are for display.
|
|
type PermissionType {
|
|
key: String!
|
|
label: String!
|
|
path: String!
|
|
}
|
|
|
|
input CreateUserInput {
|
|
username: String!
|
|
password: String!
|
|
}
|
|
|
|
extend type Query {
|
|
users: [User!]! @admin
|
|
user(id: ID!): User @admin
|
|
# @signedIn rather than @admin: /account lists a non-admin's own services
|
|
# from it. The list itself is not a secret.
|
|
permissionTypes: [PermissionType!]! @signedIn
|
|
}
|
|
|
|
extend type Mutation {
|
|
createUser(input: CreateUserInput!): User! @admin
|
|
deleteUser(id: ID!): User! @admin
|
|
setUserAdmin(id: ID!, admin: Boolean!): User! @admin
|
|
# Replaces the user's whole permission list; unknown keys are rejected.
|
|
setUserPermissions(id: ID!, permissions: [String!]!): User! @admin
|
|
}
|