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:
@@ -29,7 +29,7 @@ Use cases:
|
||||
- Member token scopes: `pact.FrontendTokenScope` and `pact.HasFrontendTokenScopes`, the frontend counterpart of `pact.HasTokenScopes`, so a plugin declares scopes for the user plugin's member personal API tokens; the admin token catalog never reads them. `pact.FrontendTokenScope.Implies` is only `""`, `read` or `write`, for a later OAuth MCP check; empty means the scope is not implied, and the route middleware is still what enforces a member scope. The plugin that owns member tokens publishes the compiled list as `pact.MemberTokenScopeCatalog` (`pact.MemberTokenScopeCatalog.MemberTokenScopes`). `pact.ValidTokenScopeName` is the one scope-name rule both catalogs apply.
|
||||
- Frontend permission codes: `pact.FrontendPermission` and `pact.HasFrontendPermissions`, the frontend counterpart of `pact.HasPermissions`, so a plugin guarding a route with a permission code also declares that code for the user plugin's permission editors.
|
||||
- MCP declarations, free of any MCP SDK: `pact.HasMCP` with `pact.MCP`, `pact.MCPTool` and `pact.MCPPrompt` bind tools and prompts to the plugin's own token-guarded routes; `pact.MCPGuard` and `pact.MCPGuards` let the owner of a route guard publish how its routes are guarded and dispatched; `pact.MCPTokenVerifier`, `pact.MCPPersonalTokenResolver` and `pact.MCPLinkedBackendResolver` are the services the MCP endpoint looks up; `pact.MCPAdvertisedScopes` (`pact.MCPAdvertisedScopes.MCPScopesSupported`) is the scope list that verifier publishes for protected-resource metadata, separate from `pact.MCPTokenVerifier` so that interface stays `MCPVerifyToken` and `MCPResource`; `pact.MCPSubjectChanged` is the event that refreshes a session's tool list. An in-process tool call carries a `pact.MCPCall`, stored with `pact.WithMCPCall` and read with `pact.MCPCallFrom` (absent on a plain HTTP request).
|
||||
- My account contributions: `pact.HasAccountContributions` with `pact.AccountContribution` and `pact.AccountAction`, so a plugin adds a section with a status line and buttons to the administrator's own account page, run for the signed-in administrator only.
|
||||
- My account contributions: `pact.HasAccountContributions` with `pact.AccountContribution` and `pact.AccountAction`, so a plugin adds a section with a status line and buttons to the administrator's own account page, run for the signed-in administrator only; a section can also list the administrator's rows (`pact.AccountItem`) with per-row buttons (`pact.AccountItemAction`).
|
||||
- Admin controller contracts: `pact.AdminController`, `pact.HasAdminControllers`, `pact.AdminAssets` (embedded Winter-shaped admin YAML), `pact.AdminPermissioned` and `pact.AdminRecordSource`.
|
||||
- Admin extension contracts, so a plugin extends the compiled admin SPA without a Node build: `pact.AdminClientAssets` (per-controller JS and CSS from the plugin's embedded `assets/` tree, Winter's `addJs`/`addCss`), `pact.HasAdminActions` with `pact.AdminAction`, `pact.AdminActionInput` and `pact.AdminActionResult` (named toolbar and widget actions whose routes, CSRF check, permissions and record scoping the framework owns), `pact.HasAdminBulkActions` with `pact.AdminBulkAction`, `pact.AdminBulkActionInput` and `pact.AdminBulkActionResult` (named actions on the rows selected in a list, which receive records the framework loaded through the list scope, never ids; a `Detached` action runs outside the framework transaction), `pact.HasAdminRecordActions` with `pact.AdminRecordAction`, `pact.AdminRecordActionInput` and `pact.AdminRecordActionResult` (named actions on one record, each with an `Applies` rule for the record's state), `pact.HasAdminActionExtensions` with `pact.AdminActionExtension` (a plugin adds record actions to any admin controller by controller ID, one it does not own included; they are offered on that controller's preview screen after the owner's) and `pact.AdminFormExtension` (a plugin places fields and tabs in another controller's form, before or after the owner's, and loads and saves their values itself inside the record's save transaction), and `pact.AdminPartialData` (the curated view model a partial template renders).
|
||||
- Plugin field types: `pact.HasFormFieldTypes` returns `pact.FormFieldType` entries, admin form field types any controller's `fields.yaml` uses by a short alias (`type: notes`). A type names its custom element, its scripts and styles, its own option keys and its Go funcs: `Decode` turns a submitted `pact.FormFieldValue` into a `pact.FormFieldDecoded` (the value to store plus optional `pact.FormFieldNotice` messages for the administrator, such as what a sanitizer removed) or refuses it with a `pact.FormFieldError`; `Load` serves the stored value to the element, `ListValue` formats a list column, `Upload` stores a file from a `pact.FormFieldUpload` and answers a `pact.FormFieldUploadResult`, and `RequestOptions` adds options that change per request (a site setting the element follows) to the served form schema. The admin framework owns the routes, permissions, record scope, locale storage of a translatable type and the localization of notices.
|
||||
@@ -144,9 +144,13 @@ func (p *BlogPlugin) Schedule() []pact.ScheduledCommand {
|
||||
| `pact.AdminFormErrors` | A `Save` refusal: field name to messages (phrase keys or text). The save answers 422 with them on the fields and rolls back. |
|
||||
| `pact.AdminFormZoneTabs` | The `zone:` value of the form's tab zone, the default and the only zone rendered so far; `pact.AdminFormZoneOutside` and `pact.AdminFormZoneSecondary` are reserved and stop the boot ("is not supported yet"). |
|
||||
| `pact.HasAccountContributions` | Implemented by a plugin that adds sections to the admin's My account page. |
|
||||
| `pact.AccountContribution` | One My account section: `Name` (an identifier unique across plugins), `Label`, `Description`, an optional pure-read `Status` func for the signed-in administrator and its `Actions`. A non-identifier or taken name, an empty label, a duplicate or non-identifier action name, a nil `Run` or an empty action label stops the boot. |
|
||||
| `pact.AccountContribution` | One My account section: `Name` (an identifier unique across plugins), `Label`, `Description`, an optional pure-read `Status` func for the signed-in administrator and its `Actions`. `pact.AccountContribution.Items`, when set, is a pure read of the signed-in administrator's rows (`pact.AccountItem`), `pact.AccountContribution.ItemActions` are each row's buttons and `pact.AccountContribution.ItemsEmpty` is the line shown with no rows (empty means the admin's own); a nil `Items` leaves the section as it was. A non-identifier or taken name, an empty label, a duplicate or non-identifier action or item action name, a nil `Run`, an empty action label or item actions without `Items` stops the boot. |
|
||||
| `pact.AccountAction` | One button of a section: name, label, optional `Confirm` text, `Danger`, extra `Permissions`, an optional pure-read `Applies` rule and the Go `Run` function, which acts for the signed-in administrator only. |
|
||||
| `pact.AccountActionInput` | What an account action receives: `AdminID`, the signed-in administrator, and nothing else. |
|
||||
| `pact.AccountItem` | One row of a section: `ID` (unique within the section; the item action route names it), `Title`, optional `Subtitle` and `Meta` lines, all shown as text. |
|
||||
| `pact.AccountItemAction` | One button of every row: name, label, optional `Confirm` text (`:title` is filled with the row's title by the admin), `Danger`, extra `Permissions` and the Go `Run` function, which acts for the signed-in administrator on one row inside a transaction, and only for an item ID that administrator's own `Items` listed. |
|
||||
| `pact.AccountItemActionInput` | What an item action receives: `AdminID` and `ItemID`. |
|
||||
| `pact.ErrAccountItemNotFound` | What an item action's `Run` answers when its row is gone; the admin API answers 404. |
|
||||
| `pact.AccountActionResult` | What an account action returns: a `Message` for the toast and an optional `URL` the admin opens in a new tab. |
|
||||
| `pact.HasMCP` | Implemented by a plugin that declares MCP tools and prompts for the framework's MCP endpoint. |
|
||||
| `pact.MCP` | The declaration: `Tools` and `Prompts` (resources are a later field of the same struct). |
|
||||
|
||||
@@ -3,6 +3,7 @@ package pact
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
@@ -607,18 +608,70 @@ type HasAccountContributions interface {
|
||||
// signed-in administrator (an empty string shows none). Actions are the
|
||||
// section's buttons.
|
||||
//
|
||||
// Items, when set, adds a list of rows under the status line: a pure read
|
||||
// scoped to the signed-in administrator that answers that administrator's
|
||||
// rows (connections, devices, keys). ItemActions are the buttons of each row;
|
||||
// the framework runs one only for an item ID the administrator's own Items
|
||||
// listed. ItemsEmpty (a phrase key or text) is the line shown when Items
|
||||
// answers no rows; empty means the framework's own empty line. A nil Items
|
||||
// keeps the section exactly as it is without these fields.
|
||||
//
|
||||
// The admin compiles contributions at boot, only when it is active. A name
|
||||
// that is not an identifier, a name another plugin already contributed, an
|
||||
// empty Label, an action whose name is not an identifier or repeats within
|
||||
// the section, a nil Run or an empty action Label stops the boot.
|
||||
// empty Label, an action or item action whose name is not an identifier or
|
||||
// repeats within the section, a nil Run, an empty action Label or item
|
||||
// actions without Items stops the boot.
|
||||
type AccountContribution struct {
|
||||
Name string
|
||||
Label string
|
||||
Description string
|
||||
Status func(ctx context.Context, adminID uint) (string, error) `json:"-"`
|
||||
Actions []AccountAction
|
||||
Items func(ctx context.Context, adminID uint) ([]AccountItem, error) `json:"-"`
|
||||
ItemActions []AccountItemAction
|
||||
ItemsEmpty string
|
||||
}
|
||||
|
||||
// AccountItem is one row of an AccountContribution's Items: an ID unique
|
||||
// within the section (the item action route names it), a Title, an optional
|
||||
// Subtitle and optional Meta entries (short lines such as dates). All are
|
||||
// shown as text, never as markup.
|
||||
type AccountItem struct {
|
||||
ID string
|
||||
Title string
|
||||
Subtitle string
|
||||
Meta []string
|
||||
}
|
||||
|
||||
// AccountItemAction is one button of every row of an AccountContribution.
|
||||
// Label and Confirm are phrase keys or text; Confirm may contain :title,
|
||||
// which the admin fills with the item's Title, and Danger selects the
|
||||
// confirm dialog's danger variant. Permissions are extra backend permission
|
||||
// codes the administrator needs. Run acts for the signed-in administrator on
|
||||
// one item, inside a transaction (cabana.TxFromContext reads it), and only
|
||||
// after the framework found the item among the administrator's own Items;
|
||||
// it answers ErrAccountItemNotFound when the item is gone meanwhile.
|
||||
type AccountItemAction struct {
|
||||
Name string
|
||||
Label string
|
||||
Confirm string
|
||||
Danger bool
|
||||
Permissions []string
|
||||
Run func(ctx context.Context, in AccountItemActionInput) (AccountActionResult, error) `json:"-"`
|
||||
}
|
||||
|
||||
// AccountItemActionInput is what the framework hands an AccountItemAction:
|
||||
// the id of the signed-in administrator and the ID of the item, which that
|
||||
// administrator's Items listed.
|
||||
type AccountItemActionInput struct {
|
||||
AdminID uint
|
||||
ItemID string
|
||||
}
|
||||
|
||||
// ErrAccountItemNotFound is what an AccountItemAction's Run answers when its
|
||||
// item no longer exists; the admin API answers 404.
|
||||
var ErrAccountItemNotFound = errors.New("pact: account item not found")
|
||||
|
||||
// AccountAction is one button of an AccountContribution. Confirm, when set,
|
||||
// is the confirmation text the admin shows first (Danger selects its danger
|
||||
// variant). Permissions are extra backend permission codes the administrator
|
||||
|
||||
Reference in New Issue
Block a user