feat(32.2-01): per-item rows and item actions on My account contributions

- pact: AccountContribution.Items/ItemActions/ItemsEmpty, AccountItem,
  AccountItemAction, AccountItemActionInput, ErrAccountItemNotFound
- cabana: the list sends items (null without Items), permitted item actions
  and the empty line; boot refuses item actions without Items
- cabana: POST {api}/account/contribution-items/{name}/{item}/actions/{action}
  runs only for an item the administrator's own Items listed, in a transaction
  (path outside /account/contributions/ to avoid a ServeMux overlap)
- swag views; admin.json and schema.d.ts regenerated; route inventories
This commit is contained in:
Jakub Zych
2026-11-21 00:22:13 +01:00
parent 97d7ee0586
commit 3f7ce6020d
16 changed files with 706 additions and 30 deletions

View File

@@ -156,6 +156,8 @@ Every signed-in administrator can edit their own profile on the My account scree
- **Plugin sections:** a plugin can add its own card below the API tokens, for something only the signed-in administrator does for themselves, such as linking their site account. The plugin implements `pact.HasAccountContributions` and returns `pact.AccountContribution` entries: a name, a label and description, an optional status line computed for the administrator, and buttons (`pact.AccountAction`) with an optional confirmation (danger variant included), extra permissions and an `Applies` rule. The SPA loads them from `GET <prefix>/api/v1/account/contributions` and runs a button through `POST <prefix>/api/v1/account/contributions/{name}/actions/{action}`, which calls the action's `Run` with the signed-in administrator's id inside a transaction (`cabana.TxFromContext`) and shows the returned message; a returned URL is opened in a new tab and shown as a link. Only an absolute `http`/`https` URL or a same-origin path is passed on; the admin drops anything else. A section whose status fails to load is still listed, marked `error: true`, and My account shows it with an error line; an action whose `Applies` fails is left out and marks its section the same way, so a missing button is explained. The other sections are unaffected. Both routes refuse personal API tokens like the rest of My account, and a page without contributing plugins is unchanged.
A section can also list rows that belong to the signed-in administrator, such as connected agents: `pact.AccountContribution.Items` answers them (`pact.AccountItem`: an id, a title, an optional subtitle and meta lines), `pact.AccountContribution.ItemsEmpty` is the line shown when there are none, and `pact.AccountContribution.ItemActions` are the buttons of every row (`pact.AccountItemAction`; a `Confirm` text may hold `:title`, which the admin replaces with the row's title). The list carries `items` (an array, possibly empty), `item_actions` (those the administrator holds the permissions for) and `items_empty`; a section without `Items` sends `items` as null and looks as before. A row button posts to `POST <prefix>/api/v1/account/contribution-items/{name}/{item}/actions/{action}`: 404 for an unknown section or action, 403 without the action's permissions, and 404 when the section's `Items` does not list that item for the signed-in administrator, so nobody can act on another administrator's row by guessing its id. `Run` then gets the administrator's id and the item id inside a transaction; a row that is gone meanwhile answers `pact.ErrAccountItemNotFound` and the route 404.
Plugins that show an administrator, such as an author box, read the subtitle with `cabana.BackendUser.Subtitle` and the picture with `cabana.BackendUserAvatar`, which returns the avatar file (or nil) for an administrator id.
## Managing administrators