feat(32.2-02): My account item rows with per-row actions; connect screen docs
- AccountContributions renders a section's items as list rows (title,
subtitle, meta joined with ' · ') with one button per item action, or
the dashed empty block; sections without items render as before
- item actions confirm with :title filled as text, post to
/account/contribution-items/{name}/{item}/actions/{action}, reload and
focus the section heading; 404 toasts item_gone and reloads
- myaccount.items_empty, item_gone, item_action_named in en and pl
- docs/backend/admin-spa.md: the /connect screen and My account item rows
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { nextTick, onMounted, ref } from 'vue'
|
||||
import { Ban } from '@lucide/vue'
|
||||
import { api } from '../../api/client'
|
||||
import type { AccountContribution, AccountContributionAction } from '../../api/types'
|
||||
import { t } from '../../app/i18n'
|
||||
import type { AccountContribution, AccountContributionAction, AccountItem } from '../../api/types'
|
||||
import { interpolate, t } from '../../app/i18n'
|
||||
import Button from '../ui/Button.vue'
|
||||
import type { useConfirm } from '../ui/confirm'
|
||||
import { showToast } from '../../state/useToasts'
|
||||
@@ -13,6 +14,9 @@ import { showToast } from '../../state/useToasts'
|
||||
// applies to them; labels, descriptions, statuses and messages arrive
|
||||
// translated and render as text. Nothing renders while the list is empty.
|
||||
// Shares AccountView's useConfirm() so ConfirmDialog stays at z-[90].
|
||||
// A section with an Items function also lists the admin's rows, each with
|
||||
// its item actions (32.2 UI-SPEC C3); a section without one sends items null
|
||||
// and renders exactly as before.
|
||||
const props = defineProps<{
|
||||
confirm: ReturnType<typeof useConfirm>
|
||||
}>()
|
||||
@@ -96,6 +100,82 @@ async function post(section: AccountContribution, action: AccountContributionAct
|
||||
}
|
||||
}
|
||||
|
||||
/** The section's rows, or null for a section without an Items function. */
|
||||
function itemsOf(section: AccountContribution): AccountItem[] | null {
|
||||
return Array.isArray(section.items) ? section.items : null
|
||||
}
|
||||
|
||||
/** After an item action the row may be gone: focus moves to its section heading. */
|
||||
async function focusSection(name: string): Promise<void> {
|
||||
await nextTick()
|
||||
const card = document.querySelector<HTMLElement>(`[data-account-contribution="${CSS.escape(name)}"]`)
|
||||
card?.querySelector<HTMLElement>('h2')?.focus()
|
||||
}
|
||||
|
||||
async function postItem(section: AccountContribution, item: AccountItem, action: AccountContributionAction): Promise<void> {
|
||||
running.value = `${section.name}/${item.id}/${action.name}`
|
||||
try {
|
||||
const result = await api.POST('/account/contribution-items/{name}/{item}/actions/{action}', {
|
||||
params: { path: { name: section.name, item: item.id, action: action.name } },
|
||||
})
|
||||
if (result.data) {
|
||||
const answer = result.data.data
|
||||
showToast(answer.message || t('backend::lang.form.action_done'))
|
||||
const url = safeUrl(answer.url ?? '')
|
||||
if (url) {
|
||||
links.value = { ...links.value, [section.name]: url }
|
||||
window.open(url, '_blank', 'noopener')
|
||||
}
|
||||
await load()
|
||||
await focusSection(section.name)
|
||||
return
|
||||
}
|
||||
const status = result.response.status
|
||||
if (status === 404) {
|
||||
showToast(t('backend::lang.myaccount.item_gone'), 'danger')
|
||||
await load()
|
||||
await focusSection(section.name)
|
||||
return
|
||||
}
|
||||
if (status === 409) {
|
||||
showToast(t('backend::lang.myaccount.action_stale'), 'danger')
|
||||
await load()
|
||||
await focusSection(section.name)
|
||||
return
|
||||
}
|
||||
if (status === 403) {
|
||||
showToast(result.error?.error.message || t('backend::lang.list.action_forbidden'), 'danger')
|
||||
return
|
||||
}
|
||||
showToast(result.error?.error.message || t('backend::lang.extension.action_failed'), 'danger')
|
||||
} catch {
|
||||
showToast(t('backend::lang.extension.action_failed'), 'danger')
|
||||
} finally {
|
||||
running.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
async function runItem(section: AccountContribution, item: AccountItem, action: AccountContributionAction): Promise<void> {
|
||||
if (running.value) {
|
||||
return
|
||||
}
|
||||
if (!action.confirm && !action.danger) {
|
||||
await postItem(section, item, action)
|
||||
return
|
||||
}
|
||||
// :title is filled with the row's title as text, never as HTML.
|
||||
await props.confirm.ask(
|
||||
{
|
||||
message: action.confirm
|
||||
? interpolate(action.confirm, { title: item.title })
|
||||
: t('backend::lang.myaccount.action_confirm', { action: action.label }),
|
||||
confirmLabel: action.label,
|
||||
danger: action.danger,
|
||||
},
|
||||
() => postItem(section, item, action),
|
||||
)
|
||||
}
|
||||
|
||||
async function run(section: AccountContribution, action: AccountContributionAction): Promise<void> {
|
||||
if (running.value) {
|
||||
return
|
||||
@@ -127,13 +207,61 @@ onMounted(() => {
|
||||
class="flex flex-col gap-4 rounded-card border border-border bg-surface p-7 shadow-card"
|
||||
>
|
||||
<div class="flex flex-col gap-1">
|
||||
<h2 class="text-[18px] font-bold">{{ section.label }}</h2>
|
||||
<h2 tabindex="-1" class="text-[18px] font-bold">{{ section.label }}</h2>
|
||||
<p v-if="section.description" class="max-w-[640px] text-[13px] text-muted">{{ section.description }}</p>
|
||||
</div>
|
||||
<p v-if="section.status" data-account-contribution-status class="font-medium">{{ section.status }}</p>
|
||||
<p v-if="section.error" data-account-contribution-error class="text-[13px] text-muted">
|
||||
{{ t('backend::lang.myaccount.section_error') }}
|
||||
</p>
|
||||
<template v-else-if="itemsOf(section) !== null">
|
||||
<div
|
||||
v-if="itemsOf(section)!.length > 0"
|
||||
role="list"
|
||||
data-account-items
|
||||
class="flex flex-col overflow-hidden rounded-inner border border-border"
|
||||
>
|
||||
<div
|
||||
v-for="item in itemsOf(section)!"
|
||||
:key="item.id"
|
||||
role="listitem"
|
||||
:data-account-item="item.id"
|
||||
class="flex items-start justify-between gap-4 border-t border-border px-4 py-3.5 first:border-t-0 max-sm:flex-col"
|
||||
>
|
||||
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
||||
<span class="font-semibold [overflow-wrap:anywhere]">{{ item.title }}</span>
|
||||
<span v-if="item.subtitle" class="text-[13px] text-muted [overflow-wrap:anywhere]">{{ item.subtitle }}</span>
|
||||
<span
|
||||
v-if="(item.meta ?? []).length > 0"
|
||||
class="text-[13px] text-muted tabular-nums [overflow-wrap:anywhere]"
|
||||
>{{ (item.meta ?? []).join(' · ') }}</span
|
||||
>
|
||||
</div>
|
||||
<div v-if="(section.item_actions ?? []).length > 0" class="flex flex-wrap gap-2 max-sm:self-start">
|
||||
<Button
|
||||
v-for="action in section.item_actions ?? []"
|
||||
:key="action.name"
|
||||
:variant="action.danger ? 'danger' : 'outline'"
|
||||
size="sm"
|
||||
:icon="action.danger ? Ban : undefined"
|
||||
:data-account-item-action="action.name"
|
||||
:aria-label="t('backend::lang.myaccount.item_action_named', { action: action.label, title: item.title })"
|
||||
:disabled="running !== ''"
|
||||
@click="runItem(section, item, action)"
|
||||
>
|
||||
{{ action.label }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
data-account-items-empty
|
||||
class="rounded-inner border border-dashed border-border-strong px-6 py-8 text-center"
|
||||
>
|
||||
<p class="text-[13px] text-muted">{{ section.items_empty || t('backend::lang.myaccount.items_empty') }}</p>
|
||||
</div>
|
||||
</template>
|
||||
<a
|
||||
v-if="safeUrl(links[section.name] ?? '')"
|
||||
data-account-contribution-url
|
||||
|
||||
121
admin/tests/smoke/account-items.smoke.test.ts
Normal file
121
admin/tests/smoke/account-items.smoke.test.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
// Smoke tests of My account item rows (Phase 32.2 UI-SPEC C3): a section
|
||||
// without Items renders as before, an empty Items list renders the dashed
|
||||
// empty block, and a danger item action confirms with :title filled and
|
||||
// posts the item route. Fixtures are neutral acme.* data.
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { enableAutoUnmount, flushPromises } from '@vue/test-utils'
|
||||
import { setBundle } from '../../src/app/i18n'
|
||||
import { toasts } from '../../src/state/useToasts'
|
||||
import { langFixture } from '../fixtures/typed'
|
||||
import { API, mountApp, profile, requestsTo, resetState, type Route } from '../helpers'
|
||||
|
||||
const CONTRIBUTIONS = `${API}/account/contributions`
|
||||
// openapi-fetch encodes each path parameter once.
|
||||
const REVOKE = `${API}/account/contribution-items/agents/client%3A1/actions/revoke`
|
||||
|
||||
const envelope = (data: unknown) => ({ body: { data, meta: {} } })
|
||||
|
||||
const plain = {
|
||||
name: 'site_link',
|
||||
label: 'Site account',
|
||||
description: '',
|
||||
status: 'Not linked',
|
||||
actions: [{ name: 'open', label: 'Link account', confirm: '', danger: false }],
|
||||
items: null,
|
||||
item_actions: null,
|
||||
items_empty: '',
|
||||
}
|
||||
|
||||
const agents = {
|
||||
name: 'agents',
|
||||
label: 'Connected agents',
|
||||
description: '',
|
||||
status: 'Connector address: https://example.test/mcp',
|
||||
actions: [],
|
||||
items: [
|
||||
{ id: 'client:1', title: 'Acme Agent', subtitle: 'Read the admin, Acme', meta: ['Connected 2026-11-01', 'Never used'] },
|
||||
],
|
||||
item_actions: [{ name: 'revoke', label: 'Revoke', confirm: 'Revoke the connection “:title”?', danger: true }],
|
||||
items_empty: '',
|
||||
}
|
||||
|
||||
async function openAccount(routes: Record<string, Route>) {
|
||||
return mountApp(
|
||||
'/account',
|
||||
{
|
||||
[`GET ${API}/auth/me`]: envelope(profile.data),
|
||||
[`GET ${API}/account/tokens`]: envelope([]),
|
||||
...routes,
|
||||
},
|
||||
{ attach: true },
|
||||
)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
resetState()
|
||||
setBundle(
|
||||
{
|
||||
...langFixture.data,
|
||||
'backend::lang.myaccount.items_empty': { other: 'Nothing here yet.' },
|
||||
'backend::lang.myaccount.item_action_named': { other: ':action: :title' },
|
||||
},
|
||||
'en',
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = ''
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
enableAutoUnmount(afterEach)
|
||||
|
||||
describe('My account item rows (UI-SPEC C3)', () => {
|
||||
it('a section without items renders no list and no empty block', async () => {
|
||||
const { wrapper } = await openAccount({ [`GET ${CONTRIBUTIONS}`]: envelope([plain]) })
|
||||
const card = wrapper.find('[data-account-contribution="site_link"]')
|
||||
expect(card.find('[data-account-contribution-status]').text()).toBe('Not linked')
|
||||
expect(card.find('[data-account-contribution-action="open"]').exists()).toBe(true)
|
||||
expect(card.find('[role="list"]').exists()).toBe(false)
|
||||
expect(card.find('[data-account-items-empty]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('a section with items [] renders the empty block under the status line', async () => {
|
||||
const { wrapper } = await openAccount({ [`GET ${CONTRIBUTIONS}`]: envelope([{ ...agents, items: [] }]) })
|
||||
const card = wrapper.find('[data-account-contribution="agents"]')
|
||||
expect(card.find('[data-account-contribution-status]').exists()).toBe(true)
|
||||
expect(card.find('[data-account-items-empty]').text()).toBe('Nothing here yet.')
|
||||
expect(card.find('[data-account-item]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('a danger item action confirms with :title filled and posts the item route', async () => {
|
||||
let loads = 0
|
||||
const { wrapper, calls } = await openAccount({
|
||||
[`GET ${CONTRIBUTIONS}`]: () => {
|
||||
loads++
|
||||
return envelope([loads === 1 ? agents : { ...agents, items: [] }])
|
||||
},
|
||||
[`POST ${REVOKE}`]: envelope({ message: 'Connection revoked', url: '' }),
|
||||
})
|
||||
const row = wrapper.find('[data-account-item="client:1"]')
|
||||
expect(row.attributes('role')).toBe('listitem')
|
||||
expect(row.text()).toContain('Acme Agent')
|
||||
expect(row.text()).toContain('Connected 2026-11-01 · Never used')
|
||||
const button = row.find('[data-account-item-action="revoke"]')
|
||||
expect(button.attributes('aria-label')).toBe('Revoke: Acme Agent')
|
||||
|
||||
await button.trigger('click')
|
||||
await flushPromises()
|
||||
const dialog = document.body.querySelector<HTMLElement>('[data-confirm-dialog]')
|
||||
expect(dialog?.textContent).toContain('Revoke the connection “Acme Agent”?')
|
||||
expect(requestsTo(calls, 'POST', REVOKE)).toHaveLength(0)
|
||||
|
||||
dialog!.querySelector<HTMLButtonElement>('[data-action="confirm"]')!.click()
|
||||
await flushPromises()
|
||||
expect(requestsTo(calls, 'POST', REVOKE)).toHaveLength(1)
|
||||
expect(toasts.value.map((toast) => toast.text)).toEqual(['Connection revoked'])
|
||||
expect(requestsTo(calls, 'GET', CONTRIBUTIONS)).toHaveLength(2)
|
||||
expect(wrapper.find('[data-account-items-empty]').exists()).toBe(true)
|
||||
expect(document.activeElement?.textContent).toBe('Connected agents')
|
||||
})
|
||||
})
|
||||
@@ -37,10 +37,20 @@ A form whose schema carries `preview` has a read-only record screen at `<control
|
||||
|
||||
The user menu in the top bar has a My account item that opens `<prefix>/account`. That screen edits the signed-in administrator's own first name, last name, email and subtitle, uploads and removes their avatar, shows the login read-only, changes the password when a new one is typed together with the current one, and manages personal API tokens (list, create with a show-once plaintext, revoke, show revoked). Server validation errors show on their fields, and a successful save updates the name and the avatar in the top bar without a reload. See [My account](users-and-permissions.md#my-account) and [API tokens](users-and-permissions.md#api-tokens).
|
||||
|
||||
A plugin section on My account can also list rows that belong to the signed-in administrator, such as connected agents. The section card then shows one row per item under its status line (title, subtitle and meta lines joined with " · ") with the section's item buttons on each row, or a dashed empty block with the section's `items_empty` line (else the admin's own "Nothing here yet."). A button with a confirmation or a danger variant asks first, with `:title` in the confirmation replaced by the row's title as text, and posts to `<prefix>/api/v1/account/contribution-items/{name}/{item}/actions/{action}`. While it runs every action button is disabled; afterwards the section reloads and focus returns to the section heading. A row that is gone meanwhile (404) shows a toast and reloads the section. A section without items looks exactly as before. See [My account](users-and-permissions.md#my-account).
|
||||
|
||||
The button at the top of the plugin rail switches the theme: each click moves from system (follow the browser's `prefers-color-scheme`) to light, to dark and back to system, and its icon and label name the current choice. The choice is saved for the signed-in administrator through `PUT <prefix>/api/v1/account/preferences` and comes back as `preferences.theme` in `GET .../auth/me`, so another browser shows the same theme after sign-in. The SPA also caches the last choice in `localStorage` (`summer-admin.theme`) and applies it before anything renders. When the save fails the previous theme returns with an error message. See [My account](users-and-permissions.md#my-account).
|
||||
|
||||
When the server offers more than one admin language (`meta.locales` of `GET .../lang`), the user menu lists them under Language, each named in its own language. Choosing one saves it as the administrator's `locale` preference, caches it in `localStorage` (`summer-admin.locale`) and reloads the page, so the strings, navigation, settings, schemas and validation messages all come back in that language, in any browser and whatever `Accept-Language` says. A form with unsaved changes asks before the reload.
|
||||
|
||||
## Connect screen
|
||||
|
||||
`<prefix>/connect?request=<id>` is the consent screen for MCP clients that connect as an administrator. The OAuth server hands the browser off to it when the application sets `wristband.Options.ConsentPath` to that path (see [Consent](../services/oauth-server.md#consent)). The screen is part of the framework SPA, not plugin code, and talks only to cabana's `GET` and `POST <prefix>/api/v1/mcp/consent/{request}`.
|
||||
|
||||
The route is standalone, without the navigation shell, and needs a session: an anonymous visitor goes to the login screen with the connect path as its redirect, signs in (with any second step the login asks for) and comes back to the same request. The login screen then says why the administrator is signing in.
|
||||
|
||||
The card names the client, the signed-in administrator (with a "Use another account" button that signs out of this browser and goes through login again) and the host the browser returns to, which is always shown in full. Below are the scopes the server offered, in catalog order: every one starts ticked except `*`, which starts ticked only when it is the only scope, and ticking `*` clears and disables the others, as on API token creation. A "Stay connected" box, ticked by default, appears only when the client asked for offline access. Nothing is sent until the administrator clicks Allow or Deny, even for a client allowed before, and neither button has initial focus or a shortcut. The answer's `redirect_uri` is opened with `window.location.assign`, never through the router or the login redirect check, and a `javascript:`, `data:` or `vbscript:` URI is refused as a failed answer. An unknown, expired or used request shows an expired card with a link to the admin; when the administrator holds none of the requested scopes only Deny is offered.
|
||||
|
||||
## Plugins screen
|
||||
|
||||
Settings → System → Plugins opens `<prefix>/system/plugins`, a read-only screen for administrators holding `backend.view_plugins` (`cabana.PermissionViewPlugins`; superusers always pass). Its Installed tab lists the plugins the binary was built with, from `GET <prefix>/api/v1/plugins`: the name and description from each plugin's `plugin.yaml` (only the ID for a plugin without one), the version and where the plugin came from (Go module, git submodule or the application itself), with the framework version the application was built with above the tabs. When the plugin registry knows a newer release that the framework version allows, the row shows an update badge and the `summer plugin:update <id>` command with a copy button. The Marketplace tab searches the registry by text and category and shows each plugin's `summer plugin:install <id>` command with a copy button; nothing is installed from the admin. With the registry disabled (`plugins.registry_url` empty) the Marketplace tab and the badges are hidden; when it does not answer, a notice says so and the Installed tab still lists every plugin. The settings entry carries a `path` instead of a controller, so the settings index, the settings panel and the breadcrumbs treat the screen like any other System entry. The SPA never calls the plugin registry itself; see [Publishing plugins](../plugins/marketplace.md#admin-plugins-screen).
|
||||
|
||||
@@ -405,6 +405,9 @@ myaccount:
|
||||
action_confirm: "Run “:action”?"
|
||||
action_stale: This action no longer applies. The page has been refreshed.
|
||||
section_error: This section could not be loaded.
|
||||
items_empty: Nothing here yet.
|
||||
item_gone: This entry no longer exists. The section has been refreshed.
|
||||
item_action_named: ":action: :title"
|
||||
richeditor:
|
||||
removed_elements:
|
||||
one: ":count element was removed: :names"
|
||||
|
||||
@@ -427,6 +427,9 @@ myaccount:
|
||||
action_confirm: "Wykonać „:action”?"
|
||||
action_stale: Ta akcja nie ma już zastosowania. Strona została odświeżona.
|
||||
section_error: Nie udało się wczytać tej sekcji.
|
||||
items_empty: Nic tu jeszcze nie ma.
|
||||
item_gone: Ten wpis już nie istnieje. Sekcja została odświeżona.
|
||||
item_action_named: ":action: :title"
|
||||
richeditor:
|
||||
removed_elements:
|
||||
one: "Usunięto :count element: :names"
|
||||
|
||||
Reference in New Issue
Block a user