feat(36-02): add shared scope picker module and wire ConnectView
This commit is contained in:
291
admin/src/app/scopeCatalog.ts
Normal file
291
admin/src/app/scopeCatalog.ts
Normal file
@@ -0,0 +1,291 @@
|
|||||||
|
// Pure domain logic for the 3-tier access selector and grouped ScopePicker
|
||||||
|
// shared by ConnectView and ApiTokenCreateDialog (Phase 36 UI-SPEC C1).
|
||||||
|
import type { AdminAPITokenScope } from '../api/types'
|
||||||
|
|
||||||
|
export type AccessTier = 'full' | 'read_only' | 'custom'
|
||||||
|
export type ScopeFilter = 'all' | 'selected' | 'read_only'
|
||||||
|
|
||||||
|
export interface ScopeGroup {
|
||||||
|
key: string
|
||||||
|
pluginId: string
|
||||||
|
label: string
|
||||||
|
scopes: AdminAPITokenScope[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CustomScopeSelection {
|
||||||
|
adminRead: boolean
|
||||||
|
scopes: ReadonlySet<string>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ScopeSummaryChip {
|
||||||
|
key: string
|
||||||
|
name: string
|
||||||
|
label: string
|
||||||
|
kind: 'admin_read' | 'write' | 'read_only'
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PartitionedCatalog {
|
||||||
|
fullScope: AdminAPITokenScope | null
|
||||||
|
adminReadScope: AdminAPITokenScope | null
|
||||||
|
pluginScopes: AdminAPITokenScope[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SummaryModel {
|
||||||
|
chips: ScopeSummaryChip[]
|
||||||
|
visible: ScopeSummaryChip[]
|
||||||
|
overflowCount: number
|
||||||
|
selectedWriteCount: number
|
||||||
|
selectedPluginCount: number
|
||||||
|
distinctPluginCount: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InitialScopeState {
|
||||||
|
tier: AccessTier
|
||||||
|
custom: {
|
||||||
|
adminRead: boolean
|
||||||
|
scopes: Set<string>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Splits a scope catalog into framework tiers (*, admin:read) and plugin scopes. */
|
||||||
|
export function partitionCatalog(catalog: readonly AdminAPITokenScope[]): PartitionedCatalog {
|
||||||
|
let fullScope: AdminAPITokenScope | null = null
|
||||||
|
let adminReadScope: AdminAPITokenScope | null = null
|
||||||
|
const pluginScopes: AdminAPITokenScope[] = []
|
||||||
|
|
||||||
|
for (const scope of catalog) {
|
||||||
|
if (scope.name === '*') {
|
||||||
|
fullScope ??= scope
|
||||||
|
} else if (scope.name === 'admin:read') {
|
||||||
|
adminReadScope ??= scope
|
||||||
|
} else {
|
||||||
|
pluginScopes.push(scope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { fullScope, adminReadScope, pluginScopes }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups plugin scopes into flat sections keyed by (plugin_id, group) so two
|
||||||
|
* plugins never collide even when they resolve to the same translated label
|
||||||
|
* (D-17). Intra-group order preserves the server catalog order; groups sort
|
||||||
|
* alphabetically by label using locale-aware collation, tie-broken on plugin_id.
|
||||||
|
*/
|
||||||
|
export function groupPluginScopes(
|
||||||
|
pluginScopes: readonly AdminAPITokenScope[],
|
||||||
|
locale: string,
|
||||||
|
fallbackGroupLabel: string,
|
||||||
|
): ScopeGroup[] {
|
||||||
|
const byKey = new Map<string, ScopeGroup>()
|
||||||
|
|
||||||
|
for (const scope of pluginScopes) {
|
||||||
|
const key = `${scope.plugin_id}\0${scope.group}`
|
||||||
|
let group = byKey.get(key)
|
||||||
|
if (!group) {
|
||||||
|
const label = scope.group.trim() || scope.plugin_id.trim() || fallbackGroupLabel
|
||||||
|
group = {
|
||||||
|
key,
|
||||||
|
pluginId: scope.plugin_id,
|
||||||
|
label,
|
||||||
|
scopes: [],
|
||||||
|
}
|
||||||
|
byKey.set(key, group)
|
||||||
|
}
|
||||||
|
group.scopes.push(scope)
|
||||||
|
}
|
||||||
|
|
||||||
|
let collator: Intl.Collator
|
||||||
|
try {
|
||||||
|
collator = new Intl.Collator(locale || undefined, { sensitivity: 'base' })
|
||||||
|
} catch {
|
||||||
|
collator = new Intl.Collator(undefined, { sensitivity: 'base' })
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...byKey.values()].sort((a, b) => {
|
||||||
|
const byLabel = collator.compare(a.label, b.label)
|
||||||
|
if (byLabel !== 0) {
|
||||||
|
return byLabel
|
||||||
|
}
|
||||||
|
const byPlugin = a.pluginId.localeCompare(b.pluginId)
|
||||||
|
if (byPlugin !== 0) {
|
||||||
|
return byPlugin
|
||||||
|
}
|
||||||
|
return a.key.localeCompare(b.key)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Case-insensitive substring search across scope code, label, description, plugin_id, and group label. */
|
||||||
|
export function matchesScopeQuery(scope: AdminAPITokenScope, groupLabel: string, query: string): boolean {
|
||||||
|
const normalized = query.trim().toLowerCase()
|
||||||
|
if (normalized === '') {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
scope.name.toLowerCase().includes(normalized) ||
|
||||||
|
scope.label.toLowerCase().includes(normalized) ||
|
||||||
|
scope.description.toLowerCase().includes(normalized) ||
|
||||||
|
scope.plugin_id.toLowerCase().includes(normalized) ||
|
||||||
|
groupLabel.toLowerCase().includes(normalized)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** True when a plugin scope is ticked directly or covered via the opt-in admin:read toggle (D-04). */
|
||||||
|
export function isEffectivelySelected(scope: AdminAPITokenScope, selection: CustomScopeSelection): boolean {
|
||||||
|
return selection.scopes.has(scope.name) || (selection.adminRead && scope.read_only)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smart accordion expand defaults (D-07):
|
||||||
|
* - Searching: expand every matching group.
|
||||||
|
* - Small catalog (<= 3 groups or <= 12 plugin scopes): expand all groups.
|
||||||
|
* - Larger catalog: expand only groups with at least one effectively selected scope.
|
||||||
|
*/
|
||||||
|
export function computeDefaultExpanded(
|
||||||
|
groups: readonly ScopeGroup[],
|
||||||
|
totalPluginScopes: number,
|
||||||
|
selection: CustomScopeSelection,
|
||||||
|
searching: boolean,
|
||||||
|
): Set<string> {
|
||||||
|
if (searching || groups.length <= 3 || totalPluginScopes <= 12) {
|
||||||
|
return new Set(groups.map((group) => group.key))
|
||||||
|
}
|
||||||
|
const expanded = new Set<string>()
|
||||||
|
for (const group of groups) {
|
||||||
|
if (group.scopes.some((scope) => isEffectivelySelected(scope, selection))) {
|
||||||
|
expanded.add(group.key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expanded
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the elevated-first Custom summary model (D-06):
|
||||||
|
* 1. admin:read chip (if enabled and present in catalog)
|
||||||
|
* 2. Selected write scopes (non-read_only) in catalog order
|
||||||
|
* 3. Selected read-only scopes in catalog order, only when admin:read is OFF
|
||||||
|
*/
|
||||||
|
export function buildSummaryModel(
|
||||||
|
catalog: readonly AdminAPITokenScope[],
|
||||||
|
selection: CustomScopeSelection,
|
||||||
|
maxVisible = 6,
|
||||||
|
): SummaryModel {
|
||||||
|
const { adminReadScope, pluginScopes } = partitionCatalog(catalog)
|
||||||
|
const adminReadActive = selection.adminRead && adminReadScope !== null
|
||||||
|
const chips: ScopeSummaryChip[] = []
|
||||||
|
|
||||||
|
if (adminReadActive) {
|
||||||
|
chips.push({
|
||||||
|
key: 'admin:read',
|
||||||
|
name: 'admin:read',
|
||||||
|
label: 'admin:read',
|
||||||
|
kind: 'admin_read',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedWrites: AdminAPITokenScope[] = []
|
||||||
|
const selectedReads: AdminAPITokenScope[] = []
|
||||||
|
for (const scope of pluginScopes) {
|
||||||
|
if (!selection.scopes.has(scope.name)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (!scope.read_only) {
|
||||||
|
selectedWrites.push(scope)
|
||||||
|
} else if (!adminReadActive) {
|
||||||
|
selectedReads.push(scope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const scope of selectedWrites) {
|
||||||
|
chips.push({
|
||||||
|
key: scope.name,
|
||||||
|
name: scope.name,
|
||||||
|
label: scope.label,
|
||||||
|
kind: 'write',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for (const scope of selectedReads) {
|
||||||
|
chips.push({
|
||||||
|
key: scope.name,
|
||||||
|
name: scope.name,
|
||||||
|
label: scope.label,
|
||||||
|
kind: 'read_only',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const countedScopes = adminReadActive ? selectedWrites : [...selectedWrites, ...selectedReads]
|
||||||
|
const pluginKeys = new Set<string>()
|
||||||
|
for (const scope of countedScopes) {
|
||||||
|
pluginKeys.add(scope.plugin_id || scope.group || scope.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
const cap = Math.max(0, maxVisible)
|
||||||
|
const visible = chips.slice(0, cap)
|
||||||
|
const overflowCount = Math.max(0, chips.length - cap)
|
||||||
|
|
||||||
|
return {
|
||||||
|
chips,
|
||||||
|
visible,
|
||||||
|
overflowCount,
|
||||||
|
selectedWriteCount: selectedWrites.length,
|
||||||
|
selectedPluginCount: countedScopes.length,
|
||||||
|
distinctPluginCount: pluginKeys.size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializes the active tier/custom selection into the exact scope list submitted
|
||||||
|
* to POST /mcp/consent/{request} or POST /account/tokens (D-04, T-36-04).
|
||||||
|
*/
|
||||||
|
export function computeSubmittedScopes(
|
||||||
|
tier: AccessTier,
|
||||||
|
catalog: readonly AdminAPITokenScope[],
|
||||||
|
custom: CustomScopeSelection,
|
||||||
|
): string[] {
|
||||||
|
const { fullScope, adminReadScope, pluginScopes } = partitionCatalog(catalog)
|
||||||
|
if (tier === 'full') {
|
||||||
|
return fullScope ? ['*'] : []
|
||||||
|
}
|
||||||
|
if (tier === 'read_only') {
|
||||||
|
return adminReadScope ? ['admin:read'] : []
|
||||||
|
}
|
||||||
|
if (custom.adminRead && adminReadScope) {
|
||||||
|
return [
|
||||||
|
'admin:read',
|
||||||
|
...pluginScopes.filter((scope) => !scope.read_only && custom.scopes.has(scope.name)).map((scope) => scope.name),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
return pluginScopes.filter((scope) => custom.scopes.has(scope.name)).map((scope) => scope.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Resolves the initial tier and Custom selection for ConnectView (D-03) or ApiTokenCreateDialog (D-08). */
|
||||||
|
export function resolveInitialState(
|
||||||
|
catalog: readonly AdminAPITokenScope[],
|
||||||
|
mode: 'connect' | 'token',
|
||||||
|
): InitialScopeState {
|
||||||
|
const { fullScope, adminReadScope, pluginScopes } = partitionCatalog(catalog)
|
||||||
|
|
||||||
|
if (mode === 'connect') {
|
||||||
|
if (adminReadScope !== null) {
|
||||||
|
return { tier: 'read_only', custom: { adminRead: false, scopes: new Set() } }
|
||||||
|
}
|
||||||
|
if (pluginScopes.length > 0) {
|
||||||
|
return {
|
||||||
|
tier: 'custom',
|
||||||
|
custom: { adminRead: false, scopes: new Set(pluginScopes.map((scope) => scope.name)) },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fullScope !== null) {
|
||||||
|
return { tier: 'full', custom: { adminRead: false, scopes: new Set() } }
|
||||||
|
}
|
||||||
|
return { tier: 'read_only', custom: { adminRead: false, scopes: new Set() } }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (adminReadScope !== null) {
|
||||||
|
return { tier: 'read_only', custom: { adminRead: false, scopes: new Set() } }
|
||||||
|
}
|
||||||
|
if (fullScope !== null) {
|
||||||
|
return { tier: 'full', custom: { adminRead: false, scopes: new Set() } }
|
||||||
|
}
|
||||||
|
return { tier: 'custom', custom: { adminRead: false, scopes: new Set() } }
|
||||||
|
}
|
||||||
210
admin/src/components/scopes/ScopeAccessControl.vue
Normal file
210
admin/src/components/scopes/ScopeAccessControl.vue
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { RadioGroupItem, RadioGroupRoot } from 'reka-ui'
|
||||||
|
import { Info, Lock, SlidersHorizontal } from '@lucide/vue'
|
||||||
|
import type { AdminAPITokenScope } from '../../api/types'
|
||||||
|
import {
|
||||||
|
buildSummaryModel,
|
||||||
|
partitionCatalog,
|
||||||
|
type AccessTier,
|
||||||
|
type CustomScopeSelection,
|
||||||
|
} from '../../app/scopeCatalog'
|
||||||
|
import { t, tc } from '../../app/i18n'
|
||||||
|
|
||||||
|
// Shared 3-tier access selector + compact effective-access summary box
|
||||||
|
// (Phase 36 UI-SPEC C2). Uses only semantic Direction C v2 Tailwind utilities
|
||||||
|
// so ApiTokenCreateDialog inherits light/dark automatically while ConnectView
|
||||||
|
// pins light-literal tokens via .connect-light-surface.
|
||||||
|
const props = defineProps<{
|
||||||
|
catalog: readonly AdminAPITokenScope[]
|
||||||
|
availableTiers: readonly AccessTier[]
|
||||||
|
tier: AccessTier
|
||||||
|
custom: CustomScopeSelection
|
||||||
|
disabled?: boolean
|
||||||
|
invalid?: boolean
|
||||||
|
idPrefix: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:tier': [tier: AccessTier]
|
||||||
|
customize: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const TIER_LABELS: Record<AccessTier, string> = {
|
||||||
|
full: 'backend::lang.api_tokens.tier_full',
|
||||||
|
read_only: 'backend::lang.api_tokens.tier_read_only',
|
||||||
|
custom: 'backend::lang.api_tokens.tier_custom',
|
||||||
|
}
|
||||||
|
|
||||||
|
const rootEl = ref<HTMLElement | null>(null)
|
||||||
|
const customizeButton = ref<HTMLButtonElement | null>(null)
|
||||||
|
|
||||||
|
const partitioned = computed(() => partitionCatalog(props.catalog))
|
||||||
|
const fullScope = computed(() => partitioned.value.fullScope)
|
||||||
|
const adminReadScope = computed(() => partitioned.value.adminReadScope)
|
||||||
|
const summary = computed(() => buildSummaryModel(props.catalog, props.custom))
|
||||||
|
const adminReadActive = computed(() => props.custom.adminRead && adminReadScope.value !== null)
|
||||||
|
|
||||||
|
const customSubtitle = computed(() => {
|
||||||
|
if (!adminReadActive.value && summary.value.selectedPluginCount === 0) {
|
||||||
|
return t('backend::lang.api_tokens.scope_summary_empty')
|
||||||
|
}
|
||||||
|
if (adminReadActive.value && summary.value.selectedWriteCount === 0) {
|
||||||
|
return t('backend::lang.api_tokens.scope_summary_admin_read_only')
|
||||||
|
}
|
||||||
|
if (adminReadActive.value) {
|
||||||
|
return t('backend::lang.api_tokens.scope_summary_admin_read_plus', {
|
||||||
|
scopes: tc('backend::lang.api_tokens.scope_write_count', summary.value.selectedWriteCount),
|
||||||
|
plugins: tc('backend::lang.api_tokens.scope_plugin_count', summary.value.distinctPluginCount),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return t('backend::lang.api_tokens.scope_summary_line', {
|
||||||
|
scopes: tc('backend::lang.api_tokens.scope_count', summary.value.selectedPluginCount),
|
||||||
|
plugins: tc('backend::lang.api_tokens.scope_plugin_count', summary.value.distinctPluginCount),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function onTierUpdate(value: unknown): void {
|
||||||
|
if (value === 'full' || value === 'read_only' || value === 'custom') {
|
||||||
|
emit('update:tier', value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function focusPrimaryControl(): void {
|
||||||
|
if (customizeButton.value) {
|
||||||
|
customizeButton.value.focus()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const checked = rootEl.value?.querySelector<HTMLElement>('[data-access-tier][data-state="checked"]')
|
||||||
|
if (checked) {
|
||||||
|
checked.focus()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rootEl.value?.querySelector<HTMLElement>('[data-access-tier]')?.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ focusPrimaryControl })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div ref="rootEl" class="flex min-w-0 flex-col gap-1.5">
|
||||||
|
<span :id="`${idPrefix}-access-label`" class="font-semibold text-text">{{
|
||||||
|
t('backend::lang.api_tokens.access_level')
|
||||||
|
}}</span>
|
||||||
|
|
||||||
|
<RadioGroupRoot
|
||||||
|
v-if="availableTiers.length > 1"
|
||||||
|
:model-value="tier"
|
||||||
|
orientation="horizontal"
|
||||||
|
:disabled="disabled"
|
||||||
|
:aria-labelledby="`${idPrefix}-access-label`"
|
||||||
|
data-access-tiers
|
||||||
|
:class="availableTiers.length === 3 ? 'grid-cols-3' : 'grid-cols-2'"
|
||||||
|
class="grid gap-1 rounded-inner border border-border bg-subtle p-1"
|
||||||
|
@update:model-value="onTierUpdate"
|
||||||
|
>
|
||||||
|
<RadioGroupItem
|
||||||
|
v-for="item in availableTiers"
|
||||||
|
:key="item"
|
||||||
|
:value="item"
|
||||||
|
:data-access-tier="item"
|
||||||
|
class="inline-flex min-h-[38px] items-center justify-center rounded-tab px-2 py-2 text-center text-[13px] text-muted transition-colors duration-150 ease-out hover:text-text data-[state=checked]:bg-surface data-[state=checked]:text-text data-[state=checked]:shadow-tab data-[state=checked]:font-semibold disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
>
|
||||||
|
{{ t(TIER_LABELS[item]) }}
|
||||||
|
</RadioGroupItem>
|
||||||
|
</RadioGroupRoot>
|
||||||
|
|
||||||
|
<div
|
||||||
|
data-scope-summary
|
||||||
|
role="region"
|
||||||
|
:aria-labelledby="`${idPrefix}-access-label`"
|
||||||
|
:aria-invalid="invalid ? 'true' : undefined"
|
||||||
|
:class="invalid ? 'border-danger' : 'border-border'"
|
||||||
|
class="flex flex-col gap-2 rounded-inner border bg-subtle p-4"
|
||||||
|
>
|
||||||
|
<template v-if="tier === 'full' && fullScope">
|
||||||
|
<div class="flex flex-wrap items-center gap-1">
|
||||||
|
<span class="font-semibold text-text">{{ fullScope.label }}</span>
|
||||||
|
<span class="font-mono text-[13px] text-muted">*</span>
|
||||||
|
</div>
|
||||||
|
<p class="text-[13px] text-muted [overflow-wrap:anywhere]">{{ fullScope.description }}</p>
|
||||||
|
<p data-scope-all-note class="flex items-center gap-2 text-[13px] text-muted">
|
||||||
|
<Info :size="14" class="shrink-0" aria-hidden="true" />
|
||||||
|
<span>{{ t('backend::lang.api_tokens.scope_all_includes') }}</span>
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else-if="tier === 'read_only' && adminReadScope">
|
||||||
|
<div class="flex flex-wrap items-center gap-1">
|
||||||
|
<span class="font-semibold text-text">{{ adminReadScope.label }}</span>
|
||||||
|
<span class="font-mono text-[13px] text-muted">admin:read</span>
|
||||||
|
<span
|
||||||
|
class="inline-flex h-6 items-center rounded-pill border border-border bg-surface px-2.5 text-[13px] font-semibold whitespace-nowrap text-muted"
|
||||||
|
>{{ t('backend::lang.api_tokens.read_only') }}</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<p class="text-[13px] text-muted [overflow-wrap:anywhere]">{{ adminReadScope.description }}</p>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else-if="tier === 'custom'">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<p data-scope-summary-count class="text-[13px] text-muted tabular-nums [overflow-wrap:anywhere]">
|
||||||
|
{{ customSubtitle }}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
ref="customizeButton"
|
||||||
|
type="button"
|
||||||
|
data-action="customize-scopes"
|
||||||
|
:disabled="disabled"
|
||||||
|
class="inline-flex h-[38px] shrink-0 items-center justify-center gap-2 rounded-control border border-border-strong bg-surface px-4 text-[14px] font-semibold whitespace-nowrap text-text transition-colors duration-150 ease-out hover:bg-hover disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
@click="emit('customize')"
|
||||||
|
>
|
||||||
|
<SlidersHorizontal :size="16" aria-hidden="true" />
|
||||||
|
<span>{{ t('backend::lang.api_tokens.scope_customize') }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="summary.visible.length > 0" data-scope-summary-chips class="flex flex-wrap gap-2">
|
||||||
|
<template v-for="chip in summary.visible" :key="chip.key">
|
||||||
|
<span
|
||||||
|
v-if="chip.kind === 'admin_read'"
|
||||||
|
data-summary-chip="admin:read"
|
||||||
|
:title="adminReadScope?.label"
|
||||||
|
class="inline-flex h-6 items-center gap-1 rounded-pill border border-border-strong bg-surface px-2 font-mono text-[13px] font-semibold whitespace-nowrap text-text"
|
||||||
|
>
|
||||||
|
<Lock :size="14" class="shrink-0 text-muted" aria-hidden="true" />
|
||||||
|
<span>admin:read</span>
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-else-if="chip.kind === 'write'"
|
||||||
|
:data-summary-chip="chip.name"
|
||||||
|
:title="chip.name"
|
||||||
|
class="inline-flex h-6 max-w-full items-center rounded-pill border border-border-strong bg-surface px-2 text-[13px] font-semibold text-text"
|
||||||
|
>
|
||||||
|
<span class="truncate">{{ chip.label }}</span>
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
:data-summary-chip="chip.name"
|
||||||
|
:title="chip.name"
|
||||||
|
class="inline-flex h-6 max-w-full items-center rounded-pill border border-border bg-surface px-2 text-[13px] font-normal text-muted"
|
||||||
|
>
|
||||||
|
<span class="truncate">{{ chip.label }}</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="summary.overflowCount > 0"
|
||||||
|
type="button"
|
||||||
|
data-action="customize-scopes-more"
|
||||||
|
:disabled="disabled"
|
||||||
|
class="inline-flex h-6 items-center rounded-pill border border-dashed border-border-strong bg-surface px-2 text-[13px] font-semibold tabular-nums whitespace-nowrap text-text hover:bg-hover disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
@click="emit('customize')"
|
||||||
|
>
|
||||||
|
{{ t('backend::lang.api_tokens.scope_more', { count: summary.overflowCount }) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
529
admin/src/components/scopes/ScopePicker.vue
Normal file
529
admin/src/components/scopes/ScopePicker.vue
Normal file
@@ -0,0 +1,529 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, nextTick, onMounted, ref } from 'vue'
|
||||||
|
import { ChevronDown, ChevronRight, Lock, Search, X } from '@lucide/vue'
|
||||||
|
import type { AdminAPITokenScope } from '../../api/types'
|
||||||
|
import {
|
||||||
|
buildSummaryModel,
|
||||||
|
computeDefaultExpanded,
|
||||||
|
groupPluginScopes,
|
||||||
|
isEffectivelySelected,
|
||||||
|
matchesScopeQuery,
|
||||||
|
partitionCatalog,
|
||||||
|
type CustomScopeSelection,
|
||||||
|
type ScopeFilter,
|
||||||
|
type ScopeGroup,
|
||||||
|
} from '../../app/scopeCatalog'
|
||||||
|
import { currentLocale, t, tc } from '../../app/i18n'
|
||||||
|
import { controlClass } from '../form/control'
|
||||||
|
|
||||||
|
// Surface-agnostic sticky-header / flat-accordion / sticky-footer scope picker
|
||||||
|
// (Phase 36 UI-SPEC C3). Hosted inside ConnectView's light-literal modal and
|
||||||
|
// ApiTokenCreateDialog's fixed-width swapped view.
|
||||||
|
const props = defineProps<{
|
||||||
|
catalog: readonly AdminAPITokenScope[]
|
||||||
|
draftAdminRead: boolean
|
||||||
|
draftScopes: ReadonlySet<string>
|
||||||
|
cancelLabel: string
|
||||||
|
disabled?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:draftAdminRead': [value: boolean]
|
||||||
|
'update:draftScopes': [value: Set<string>]
|
||||||
|
apply: []
|
||||||
|
cancel: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
interface VisibleScopeGroup {
|
||||||
|
key: string
|
||||||
|
panelId: string
|
||||||
|
label: string
|
||||||
|
allScopes: AdminAPITokenScope[]
|
||||||
|
visibleScopes: AdminAPITokenScope[]
|
||||||
|
selectedCount: number
|
||||||
|
canRead: boolean
|
||||||
|
canAll: boolean
|
||||||
|
canClear: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = ref('')
|
||||||
|
const filter = ref<ScopeFilter>('all')
|
||||||
|
const expanded = ref<Set<string>>(new Set())
|
||||||
|
const searchInput = ref<HTMLInputElement | null>(null)
|
||||||
|
|
||||||
|
const partitioned = computed(() => partitionCatalog(props.catalog))
|
||||||
|
const hasAdminRead = computed(() => partitioned.value.adminReadScope !== null)
|
||||||
|
const pluginScopes = computed(() => partitioned.value.pluginScopes)
|
||||||
|
const adminReadActive = computed(() => props.draftAdminRead && hasAdminRead.value)
|
||||||
|
|
||||||
|
const draftSelection = computed<CustomScopeSelection>(() => ({
|
||||||
|
adminRead: adminReadActive.value,
|
||||||
|
scopes: props.draftScopes,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const allGroups = computed<ScopeGroup[]>(() =>
|
||||||
|
groupPluginScopes(pluginScopes.value, currentLocale.value, t('backend::lang.permissioneditor.other')),
|
||||||
|
)
|
||||||
|
|
||||||
|
const isSearching = computed(() => query.value.trim() !== '')
|
||||||
|
|
||||||
|
const allCount = computed(() => pluginScopes.value.length)
|
||||||
|
const selectedCount = computed(
|
||||||
|
() => pluginScopes.value.filter((scope) => isEffectivelySelected(scope, draftSelection.value)).length,
|
||||||
|
)
|
||||||
|
const readOnlyCount = computed(() => pluginScopes.value.filter((scope) => scope.read_only).length)
|
||||||
|
|
||||||
|
const filterOptions = computed(() => [
|
||||||
|
{
|
||||||
|
id: 'all' as const,
|
||||||
|
label: t('backend::lang.api_tokens.scope_filter_all', { count: allCount.value }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'selected' as const,
|
||||||
|
label: t('backend::lang.api_tokens.scope_filter_selected', { count: selectedCount.value }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'read_only' as const,
|
||||||
|
label: t('backend::lang.api_tokens.scope_filter_read_only', { count: readOnlyCount.value }),
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
function isLocked(scope: AdminAPITokenScope): boolean {
|
||||||
|
return adminReadActive.value && scope.read_only
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEffectiveSelected(scope: AdminAPITokenScope): boolean {
|
||||||
|
return isEffectivelySelected(scope, draftSelection.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const visibleGroups = computed<VisibleScopeGroup[]>(() => {
|
||||||
|
const result: VisibleScopeGroup[] = []
|
||||||
|
allGroups.value.forEach((group, index) => {
|
||||||
|
const visibleScopes = group.scopes.filter((scope) => {
|
||||||
|
if (filter.value === 'selected' && !isEffectiveSelected(scope)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (filter.value === 'read_only' && !scope.read_only) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (isSearching.value && !matchesScopeQuery(scope, group.label, query.value)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
if (visibleScopes.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const readOnlyScopes = group.scopes.filter((scope) => scope.read_only)
|
||||||
|
const allReadOnlySelected = readOnlyScopes.every((scope) => props.draftScopes.has(scope.name))
|
||||||
|
const unlockedScopes = group.scopes.filter((scope) => !isLocked(scope))
|
||||||
|
const allUnlockedSelected = unlockedScopes.every((scope) => props.draftScopes.has(scope.name))
|
||||||
|
const unlockedSelected = unlockedScopes.filter((scope) => props.draftScopes.has(scope.name))
|
||||||
|
|
||||||
|
result.push({
|
||||||
|
key: group.key,
|
||||||
|
panelId: `scope-group-panel-${index}`,
|
||||||
|
label: group.label,
|
||||||
|
allScopes: group.scopes,
|
||||||
|
visibleScopes,
|
||||||
|
selectedCount: group.scopes.filter((scope) => isEffectiveSelected(scope)).length,
|
||||||
|
canRead: !props.disabled && !adminReadActive.value && readOnlyScopes.length > 0 && !allReadOnlySelected,
|
||||||
|
canAll: !props.disabled && unlockedScopes.length > 0 && !allUnlockedSelected,
|
||||||
|
canClear: !props.disabled && unlockedSelected.length > 0,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
})
|
||||||
|
|
||||||
|
const draftSummary = computed(() => buildSummaryModel(props.catalog, draftSelection.value))
|
||||||
|
const canApply = computed(() => adminReadActive.value || draftSummary.value.selectedPluginCount > 0)
|
||||||
|
|
||||||
|
const footerSummary = computed(() => {
|
||||||
|
if (!canApply.value) {
|
||||||
|
return t('backend::lang.api_tokens.scope_picker_none_selected')
|
||||||
|
}
|
||||||
|
if (adminReadActive.value && draftSummary.value.selectedWriteCount === 0) {
|
||||||
|
return t('backend::lang.api_tokens.scope_summary_admin_read_only')
|
||||||
|
}
|
||||||
|
if (adminReadActive.value) {
|
||||||
|
return t('backend::lang.api_tokens.scope_picker_selected_admin_read', {
|
||||||
|
scopes: tc('backend::lang.api_tokens.scope_write_count', draftSummary.value.selectedWriteCount),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return t('backend::lang.api_tokens.scope_picker_selected', {
|
||||||
|
scopes: tc('backend::lang.api_tokens.scope_count', draftSummary.value.selectedPluginCount),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const emptyState = computed(() => {
|
||||||
|
if (isSearching.value) {
|
||||||
|
return {
|
||||||
|
kind: 'search' as const,
|
||||||
|
title: t('backend::lang.api_tokens.scope_empty_search_title'),
|
||||||
|
body: t('backend::lang.api_tokens.scope_empty_search_body', { query: query.value.trim() }),
|
||||||
|
actionLabel: t('backend::lang.api_tokens.scope_search_clear'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filter.value === 'selected') {
|
||||||
|
return {
|
||||||
|
kind: 'filter' as const,
|
||||||
|
title: t('backend::lang.api_tokens.scope_empty_selected_title'),
|
||||||
|
body: t('backend::lang.api_tokens.scope_empty_selected_body'),
|
||||||
|
actionLabel: t('backend::lang.api_tokens.scope_filter_reset'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
kind: 'filter' as const,
|
||||||
|
title: t('backend::lang.api_tokens.scope_empty_readonly_title'),
|
||||||
|
body: t('backend::lang.api_tokens.scope_empty_readonly_body'),
|
||||||
|
actionLabel: t('backend::lang.api_tokens.scope_filter_reset'),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function isGroupExpanded(key: string): boolean {
|
||||||
|
return isSearching.value || expanded.value.has(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleGroup(key: string): void {
|
||||||
|
if (isSearching.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const next = new Set(expanded.value)
|
||||||
|
if (next.has(key)) {
|
||||||
|
next.delete(key)
|
||||||
|
} else {
|
||||||
|
next.add(key)
|
||||||
|
}
|
||||||
|
expanded.value = next
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleScope(name: string, on: boolean): void {
|
||||||
|
const next = new Set(props.draftScopes)
|
||||||
|
if (on) {
|
||||||
|
next.add(name)
|
||||||
|
} else {
|
||||||
|
next.delete(name)
|
||||||
|
}
|
||||||
|
emit('update:draftScopes', next)
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectGroupRead(group: VisibleScopeGroup): void {
|
||||||
|
if (!group.canRead) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const next = new Set(props.draftScopes)
|
||||||
|
for (const scope of group.allScopes) {
|
||||||
|
if (scope.read_only) {
|
||||||
|
next.add(scope.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit('update:draftScopes', next)
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectGroupAll(group: VisibleScopeGroup): void {
|
||||||
|
if (!group.canAll) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const next = new Set(props.draftScopes)
|
||||||
|
for (const scope of group.allScopes) {
|
||||||
|
if (!isLocked(scope)) {
|
||||||
|
next.add(scope.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit('update:draftScopes', next)
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearGroup(group: VisibleScopeGroup): void {
|
||||||
|
if (!group.canClear) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const next = new Set(props.draftScopes)
|
||||||
|
for (const scope of group.allScopes) {
|
||||||
|
if (!isLocked(scope)) {
|
||||||
|
next.delete(scope.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit('update:draftScopes', next)
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearSearch(): void {
|
||||||
|
query.value = ''
|
||||||
|
void nextTick(() => {
|
||||||
|
searchInput.value?.focus()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetFilter(): void {
|
||||||
|
filter.value = 'all'
|
||||||
|
}
|
||||||
|
|
||||||
|
function focusSearch(): void {
|
||||||
|
searchInput.value?.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
expanded.value = computeDefaultExpanded(
|
||||||
|
allGroups.value,
|
||||||
|
pluginScopes.value.length,
|
||||||
|
draftSelection.value,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
defineExpose({ focusSearch })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div data-scope-picker class="flex min-h-0 flex-1 flex-col">
|
||||||
|
<!-- Sticky search, filter pills, and opt-in admin:read toggle -->
|
||||||
|
<div class="flex shrink-0 flex-col gap-2 border-b border-border bg-surface p-4">
|
||||||
|
<div class="relative flex items-center">
|
||||||
|
<Search :size="16" class="pointer-events-none absolute left-3 text-muted" aria-hidden="true" />
|
||||||
|
<input
|
||||||
|
ref="searchInput"
|
||||||
|
v-model="query"
|
||||||
|
type="search"
|
||||||
|
data-scope-search
|
||||||
|
autocomplete="off"
|
||||||
|
:aria-label="t('backend::lang.api_tokens.scope_search_label')"
|
||||||
|
:placeholder="t('backend::lang.api_tokens.scope_search_placeholder')"
|
||||||
|
:class="controlClass(false)"
|
||||||
|
class="h-input pl-10 pr-10"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
v-if="query !== ''"
|
||||||
|
type="button"
|
||||||
|
data-action="clear-scope-search"
|
||||||
|
:aria-label="t('backend::lang.api_tokens.scope_search_clear')"
|
||||||
|
class="absolute right-2 flex size-8 items-center justify-center rounded-tab text-muted hover:bg-hover hover:text-text"
|
||||||
|
@click="clearSearch"
|
||||||
|
>
|
||||||
|
<X :size="16" aria-hidden="true" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
role="group"
|
||||||
|
:aria-label="t('backend::lang.api_tokens.scope_filter_label')"
|
||||||
|
class="inline-flex flex-wrap gap-1 self-start rounded-inner border border-border bg-subtle p-1"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
v-for="option in filterOptions"
|
||||||
|
:key="option.id"
|
||||||
|
type="button"
|
||||||
|
:data-scope-filter="option.id"
|
||||||
|
:aria-pressed="filter === option.id"
|
||||||
|
:class="
|
||||||
|
filter === option.id
|
||||||
|
? 'bg-surface font-semibold text-text shadow-tab'
|
||||||
|
: 'text-muted hover:text-text'
|
||||||
|
"
|
||||||
|
class="inline-flex h-8 items-center rounded-tab px-4 text-[13px] tabular-nums whitespace-nowrap transition-colors duration-150 ease-out"
|
||||||
|
@click="filter = option.id"
|
||||||
|
>
|
||||||
|
{{ option.label }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="hasAdminRead"
|
||||||
|
data-admin-read-toggle
|
||||||
|
class="rounded-inner border border-border bg-subtle px-4 py-2"
|
||||||
|
>
|
||||||
|
<label class="flex min-h-[44px] cursor-pointer items-start gap-3 py-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
data-admin-read-checkbox
|
||||||
|
class="mt-0.5 size-5 shrink-0 rounded-[6px] accent-primary"
|
||||||
|
:checked="draftAdminRead"
|
||||||
|
:disabled="disabled"
|
||||||
|
@change="emit('update:draftAdminRead', ($event.target as HTMLInputElement).checked)"
|
||||||
|
/>
|
||||||
|
<span class="flex min-w-0 flex-col">
|
||||||
|
<span class="flex flex-wrap items-center gap-1">
|
||||||
|
<span class="font-semibold text-text">{{
|
||||||
|
t('backend::lang.api_tokens.scope_also_admin_read')
|
||||||
|
}}</span>
|
||||||
|
<span class="font-mono text-[13px] text-muted">admin:read</span>
|
||||||
|
</span>
|
||||||
|
<span class="text-[13px] text-muted [overflow-wrap:anywhere]">{{
|
||||||
|
t('backend::lang.api_tokens.scope_also_admin_read_hint')
|
||||||
|
}}</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Scrollable accordion body -->
|
||||||
|
<div class="min-h-0 flex-1 overflow-y-auto p-4">
|
||||||
|
<div
|
||||||
|
v-if="visibleGroups.length === 0"
|
||||||
|
data-scope-picker-empty
|
||||||
|
class="flex flex-col items-center gap-2 rounded-inner border border-dashed border-border-strong px-6 py-8 text-center"
|
||||||
|
>
|
||||||
|
<p class="font-semibold text-text">{{ emptyState.title }}</p>
|
||||||
|
<p class="text-[13px] text-muted [overflow-wrap:anywhere]">{{ emptyState.body }}</p>
|
||||||
|
<button
|
||||||
|
v-if="emptyState.kind === 'search'"
|
||||||
|
type="button"
|
||||||
|
data-action="reset-scope-search"
|
||||||
|
class="mt-2 inline-flex h-[38px] items-center justify-center rounded-control border border-border-strong bg-surface px-4 font-semibold text-text transition-colors duration-150 ease-out hover:bg-hover"
|
||||||
|
@click="clearSearch"
|
||||||
|
>
|
||||||
|
{{ emptyState.actionLabel }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-else
|
||||||
|
type="button"
|
||||||
|
data-action="reset-scope-filter"
|
||||||
|
class="mt-2 inline-flex h-[38px] items-center justify-center rounded-control border border-border-strong bg-surface px-4 font-semibold text-text transition-colors duration-150 ease-out hover:bg-hover"
|
||||||
|
@click="resetFilter"
|
||||||
|
>
|
||||||
|
{{ emptyState.actionLabel }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<section
|
||||||
|
v-for="group in visibleGroups"
|
||||||
|
:key="group.key"
|
||||||
|
data-scope-group
|
||||||
|
class="overflow-hidden rounded-inner border border-border bg-surface"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2 bg-subtle px-4 py-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-scope-group-toggle
|
||||||
|
:aria-expanded="isGroupExpanded(group.key)"
|
||||||
|
:aria-controls="group.panelId"
|
||||||
|
class="flex min-h-[38px] min-w-0 flex-1 items-center gap-2 text-left"
|
||||||
|
@click="toggleGroup(group.key)"
|
||||||
|
>
|
||||||
|
<ChevronDown
|
||||||
|
v-if="isGroupExpanded(group.key)"
|
||||||
|
:size="16"
|
||||||
|
class="shrink-0 text-muted"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<ChevronRight v-else :size="16" class="shrink-0 text-muted" aria-hidden="true" />
|
||||||
|
<span class="font-semibold text-text [overflow-wrap:anywhere]">{{ group.label }}</span>
|
||||||
|
<span
|
||||||
|
data-scope-group-count
|
||||||
|
:class="group.selectedCount > 0 ? 'border-border-strong text-text' : 'border-border text-muted'"
|
||||||
|
class="inline-flex h-6 shrink-0 items-center rounded-pill border bg-surface px-2 text-[13px] font-semibold tabular-nums"
|
||||||
|
>
|
||||||
|
{{ group.selectedCount }}/{{ group.allScopes.length }}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="flex shrink-0 items-center gap-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-group-action="read"
|
||||||
|
:disabled="!group.canRead"
|
||||||
|
:aria-label="t('backend::lang.api_tokens.group_select_read_named', { group: group.label })"
|
||||||
|
class="inline-flex h-8 items-center rounded-tab px-2 text-[13px] font-semibold text-muted transition-colors duration-150 ease-out hover:bg-hover hover:text-text disabled:cursor-not-allowed disabled:opacity-40"
|
||||||
|
@click="selectGroupRead(group)"
|
||||||
|
>
|
||||||
|
{{ t('backend::lang.api_tokens.group_select_read') }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-group-action="all"
|
||||||
|
:disabled="!group.canAll"
|
||||||
|
:aria-label="t('backend::lang.api_tokens.group_select_all_named', { group: group.label })"
|
||||||
|
class="inline-flex h-8 items-center rounded-tab px-2 text-[13px] font-semibold text-muted transition-colors duration-150 ease-out hover:bg-hover hover:text-text disabled:cursor-not-allowed disabled:opacity-40"
|
||||||
|
@click="selectGroupAll(group)"
|
||||||
|
>
|
||||||
|
{{ t('backend::lang.api_tokens.group_select_all') }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-group-action="clear"
|
||||||
|
:disabled="!group.canClear"
|
||||||
|
:aria-label="t('backend::lang.api_tokens.group_clear_named', { group: group.label })"
|
||||||
|
class="inline-flex h-8 items-center rounded-tab px-2 text-[13px] font-semibold text-muted transition-colors duration-150 ease-out hover:bg-hover hover:text-text disabled:cursor-not-allowed disabled:opacity-40"
|
||||||
|
@click="clearGroup(group)"
|
||||||
|
>
|
||||||
|
{{ t('backend::lang.api_tokens.group_clear') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-show="isGroupExpanded(group.key)"
|
||||||
|
:id="group.panelId"
|
||||||
|
role="group"
|
||||||
|
:aria-label="group.label"
|
||||||
|
>
|
||||||
|
<label
|
||||||
|
v-for="scope in group.visibleScopes"
|
||||||
|
:key="scope.name"
|
||||||
|
:data-scope="scope.name"
|
||||||
|
:class="isLocked(scope) ? 'cursor-not-allowed bg-subtle' : 'cursor-pointer hover:bg-hover'"
|
||||||
|
class="flex min-h-[56px] items-start gap-3 border-t border-border px-4 py-3"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
class="mt-0.5 size-5 shrink-0 rounded-[6px] accent-primary"
|
||||||
|
:checked="isEffectiveSelected(scope)"
|
||||||
|
:disabled="disabled || isLocked(scope)"
|
||||||
|
@change="toggleScope(scope.name, ($event.target as HTMLInputElement).checked)"
|
||||||
|
/>
|
||||||
|
<span class="flex min-w-0 flex-1 flex-col">
|
||||||
|
<span class="flex flex-wrap items-center gap-1">
|
||||||
|
<span class="font-semibold text-text [overflow-wrap:anywhere]">{{ scope.label }}</span>
|
||||||
|
<span class="font-mono text-[13px] text-muted [overflow-wrap:anywhere]">{{
|
||||||
|
scope.name
|
||||||
|
}}</span>
|
||||||
|
<span
|
||||||
|
v-if="scope.read_only && adminReadActive"
|
||||||
|
data-via-admin-read
|
||||||
|
class="inline-flex h-6 items-center gap-1 rounded-pill border border-border-strong bg-surface px-2 text-[13px] font-semibold whitespace-nowrap text-muted"
|
||||||
|
>
|
||||||
|
<Lock :size="14" aria-hidden="true" />
|
||||||
|
<span>{{ t('backend::lang.api_tokens.via_admin_read') }}</span>
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-else-if="scope.read_only"
|
||||||
|
class="inline-flex h-6 items-center rounded-pill bg-subtle px-2.5 text-[13px] font-semibold whitespace-nowrap text-muted"
|
||||||
|
>{{ t('backend::lang.api_tokens.read_only') }}</span
|
||||||
|
>
|
||||||
|
</span>
|
||||||
|
<span class="text-[13px] text-muted [overflow-wrap:anywhere]">{{ scope.description }}</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Sticky footer -->
|
||||||
|
<div class="flex shrink-0 flex-wrap items-center justify-between gap-2 border-t border-border bg-surface p-4">
|
||||||
|
<p data-scope-picker-summary class="text-[13px] text-muted tabular-nums" aria-live="polite">
|
||||||
|
{{ footerSummary }}
|
||||||
|
</p>
|
||||||
|
<div class="flex items-center gap-2 max-sm:w-full">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-action="scope-picker-discard"
|
||||||
|
:disabled="disabled"
|
||||||
|
class="inline-flex h-button items-center justify-center gap-2 rounded-control border border-border-strong bg-surface px-4 font-semibold whitespace-nowrap text-text transition-colors duration-150 ease-out hover:bg-hover disabled:cursor-not-allowed disabled:opacity-60 max-sm:flex-1"
|
||||||
|
@click="emit('cancel')"
|
||||||
|
>
|
||||||
|
{{ cancelLabel }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-action="scope-picker-apply"
|
||||||
|
:disabled="disabled || !canApply"
|
||||||
|
class="inline-flex h-button items-center justify-center gap-2 rounded-control bg-primary px-4 font-semibold whitespace-nowrap text-on-primary transition-colors duration-150 ease-out hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60 max-sm:flex-1"
|
||||||
|
@click="emit('apply')"
|
||||||
|
>
|
||||||
|
{{ t('backend::lang.api_tokens.scope_picker_apply') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
107
admin/src/components/scopes/useScopeSelection.ts
Normal file
107
admin/src/components/scopes/useScopeSelection.ts
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
// Reactive 3-tier access state, tier memory, auto-open empty Custom, and
|
||||||
|
// draft-until-apply lifecycle for ConnectView and ApiTokenCreateDialog
|
||||||
|
// (Phase 36 D-03, D-09, D-11).
|
||||||
|
import { computed, ref, type Ref } from 'vue'
|
||||||
|
import type { AdminAPITokenScope } from '../../api/types'
|
||||||
|
import {
|
||||||
|
buildSummaryModel,
|
||||||
|
computeSubmittedScopes,
|
||||||
|
partitionCatalog,
|
||||||
|
resolveInitialState,
|
||||||
|
type AccessTier,
|
||||||
|
} from '../../app/scopeCatalog'
|
||||||
|
|
||||||
|
export function useScopeSelection(catalog: Ref<readonly AdminAPITokenScope[]>, mode: 'connect' | 'token') {
|
||||||
|
const initial = resolveInitialState(catalog.value, mode)
|
||||||
|
const tier = ref<AccessTier>(initial.tier)
|
||||||
|
const custom = ref<{ adminRead: boolean; scopes: Set<string> }>(initial.custom)
|
||||||
|
const pickerOpen = ref(false)
|
||||||
|
const draftAdminRead = ref(false)
|
||||||
|
const draftScopes = ref<Set<string>>(new Set())
|
||||||
|
let autoOpenedFrom: AccessTier | null = null
|
||||||
|
|
||||||
|
const partitioned = computed(() => partitionCatalog(catalog.value))
|
||||||
|
|
||||||
|
const availableTiers = computed<AccessTier[]>(() => {
|
||||||
|
const tiers: AccessTier[] = []
|
||||||
|
if (partitioned.value.fullScope !== null) {
|
||||||
|
tiers.push('full')
|
||||||
|
}
|
||||||
|
if (partitioned.value.adminReadScope !== null) {
|
||||||
|
tiers.push('read_only')
|
||||||
|
}
|
||||||
|
if (partitioned.value.pluginScopes.length > 0) {
|
||||||
|
tiers.push('custom')
|
||||||
|
}
|
||||||
|
return tiers
|
||||||
|
})
|
||||||
|
|
||||||
|
const submittedScopes = computed(() => computeSubmittedScopes(tier.value, catalog.value, custom.value))
|
||||||
|
const summary = computed(() => buildSummaryModel(catalog.value, custom.value))
|
||||||
|
const canSubmitScopes = computed(() => submittedScopes.value.length > 0)
|
||||||
|
|
||||||
|
function reset(nextCatalog?: readonly AdminAPITokenScope[]): void {
|
||||||
|
const state = resolveInitialState(nextCatalog ?? catalog.value, mode)
|
||||||
|
tier.value = state.tier
|
||||||
|
custom.value = state.custom
|
||||||
|
pickerOpen.value = false
|
||||||
|
draftAdminRead.value = false
|
||||||
|
draftScopes.value = new Set()
|
||||||
|
autoOpenedFrom = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function openPicker(): void {
|
||||||
|
draftAdminRead.value = custom.value.adminRead
|
||||||
|
draftScopes.value = new Set(custom.value.scopes)
|
||||||
|
pickerOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectTier(next: AccessTier): void {
|
||||||
|
if (next === tier.value || !availableTiers.value.includes(next)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const previous = tier.value
|
||||||
|
tier.value = next
|
||||||
|
if (next === 'custom' && !custom.value.adminRead && custom.value.scopes.size === 0) {
|
||||||
|
autoOpenedFrom = previous
|
||||||
|
openPicker()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyPicker(): void {
|
||||||
|
custom.value = {
|
||||||
|
adminRead: draftAdminRead.value,
|
||||||
|
scopes: new Set(draftScopes.value),
|
||||||
|
}
|
||||||
|
tier.value = 'custom'
|
||||||
|
autoOpenedFrom = null
|
||||||
|
pickerOpen.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function discardPicker(): void {
|
||||||
|
draftAdminRead.value = custom.value.adminRead
|
||||||
|
draftScopes.value = new Set(custom.value.scopes)
|
||||||
|
pickerOpen.value = false
|
||||||
|
if (autoOpenedFrom !== null) {
|
||||||
|
tier.value = autoOpenedFrom
|
||||||
|
autoOpenedFrom = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
availableTiers,
|
||||||
|
tier,
|
||||||
|
custom,
|
||||||
|
pickerOpen,
|
||||||
|
draftAdminRead,
|
||||||
|
draftScopes,
|
||||||
|
submittedScopes,
|
||||||
|
summary,
|
||||||
|
canSubmitScopes,
|
||||||
|
reset,
|
||||||
|
selectTier,
|
||||||
|
openPicker,
|
||||||
|
applyPicker,
|
||||||
|
discardPicker,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -528,6 +528,49 @@
|
|||||||
.summer-diff__ctx {
|
.summer-diff__ctx {
|
||||||
color: var(--c-text);
|
color: var(--c-text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Standalone light-literal surface for ConnectView card and portaled
|
||||||
|
Customize modal (Phase 36 D-12): re-declares both --c-* and --color-*
|
||||||
|
aliases so Tailwind v4 @theme utilities stay light even under
|
||||||
|
<html class="dark">. */
|
||||||
|
.connect-light-surface {
|
||||||
|
color-scheme: light;
|
||||||
|
--c-bg: #f4f6f9;
|
||||||
|
--c-surface: #ffffff;
|
||||||
|
--c-subtle: #f3f5f8;
|
||||||
|
--c-border: #e6e9ef;
|
||||||
|
--c-border-strong: #d2d8e2;
|
||||||
|
--c-text: #141b2d;
|
||||||
|
--c-muted: #566175;
|
||||||
|
--c-placeholder: #6b7588;
|
||||||
|
--c-primary: #22304d;
|
||||||
|
--c-on-primary: #ffffff;
|
||||||
|
--c-danger: #c62828;
|
||||||
|
--c-danger-soft: #fdf0f0;
|
||||||
|
--c-ring: rgba(252, 196, 40, 0.55);
|
||||||
|
--c-hover: #f1f3f7;
|
||||||
|
--c-sel: #fdf3cf;
|
||||||
|
--c-skel: #eceff4;
|
||||||
|
--c-overlay: rgba(20, 27, 45, 0.5);
|
||||||
|
|
||||||
|
--color-bg: var(--c-bg);
|
||||||
|
--color-surface: var(--c-surface);
|
||||||
|
--color-subtle: var(--c-subtle);
|
||||||
|
--color-border: var(--c-border);
|
||||||
|
--color-border-strong: var(--c-border-strong);
|
||||||
|
--color-text: var(--c-text);
|
||||||
|
--color-muted: var(--c-muted);
|
||||||
|
--color-placeholder: var(--c-placeholder);
|
||||||
|
--color-primary: var(--c-primary);
|
||||||
|
--color-on-primary: var(--c-on-primary);
|
||||||
|
--color-danger: var(--c-danger);
|
||||||
|
--color-danger-soft: var(--c-danger-soft);
|
||||||
|
--color-ring: var(--c-ring);
|
||||||
|
--color-hover: var(--c-hover);
|
||||||
|
--color-sel: var(--c-sel);
|
||||||
|
--color-skel: var(--c-skel);
|
||||||
|
--color-overlay: var(--c-overlay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
|||||||
@@ -1,20 +1,33 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
||||||
import { RouterLink, useRoute, useRouter } from 'vue-router'
|
import { RouterLink, useRoute, useRouter } from 'vue-router'
|
||||||
import { Bot, CircleAlert, Clock, Info, LoaderCircle, Sun } from '@lucide/vue'
|
import {
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogOverlay,
|
||||||
|
DialogPortal,
|
||||||
|
DialogRoot,
|
||||||
|
DialogTitle,
|
||||||
|
} from 'reka-ui'
|
||||||
|
import { Bot, CircleAlert, Clock, Info, LoaderCircle, Sun, X } from '@lucide/vue'
|
||||||
import { api } from '../api/client'
|
import { api } from '../api/client'
|
||||||
import type { MCPConsent } from '../api/types'
|
import type { MCPConsent } from '../api/types'
|
||||||
import { t } from '../app/i18n'
|
import { t } from '../app/i18n'
|
||||||
|
import type { AccessTier } from '../app/scopeCatalog'
|
||||||
|
import ScopeAccessControl from '../components/scopes/ScopeAccessControl.vue'
|
||||||
|
import ScopePicker from '../components/scopes/ScopePicker.vue'
|
||||||
|
import { useScopeSelection } from '../components/scopes/useScopeSelection'
|
||||||
import { currentUser, expireSession, logout } from '../state/useAuth'
|
import { currentUser, expireSession, logout } from '../state/useAuth'
|
||||||
|
|
||||||
// The MCP consent card (32.2 UI-SPEC C1). A standalone screen in the login
|
// The MCP consent card (32.2 UI-SPEC C1 + Phase 36 UI-SPEC C4). A standalone
|
||||||
// flow: the same navy page and white card as LoginView, with light literal
|
// screen in the login flow: the same navy page and white card as LoginView,
|
||||||
// colours inside the card so it looks the same in light and dark mode. The
|
// pinned to light-literal colours via .connect-light-surface so both the card
|
||||||
// decision is posted with fetch and the browser then leaves for the
|
// and the portaled Customize scopes modal look the same in light and dark mode.
|
||||||
|
// The decision is posted with fetch and the browser then leaves for the
|
||||||
// server-issued redirect_uri with window.location.assign: never the router,
|
// server-issued redirect_uri with window.location.assign: never the router,
|
||||||
// never safeRedirect, never a native form POST (CSP form-action 'self').
|
// never safeRedirect, never a native form POST (CSP form-action 'self').
|
||||||
// Nothing is posted without a click, even for a client allowed before, and
|
// Nothing is posted without a click, even for a client allowed before, and
|
||||||
// neither button gets initial focus or a hotkey (T-32.2-12).
|
// neither Allow nor Deny gets initial focus or a hotkey (T-32.2-12, T-36-05).
|
||||||
|
|
||||||
type State = 'loading' | 'ready' | 'expired' | 'load_error' | 'returning'
|
type State = 'loading' | 'ready' | 'expired' | 'load_error' | 'returning'
|
||||||
type InlineError = 'scopes_required' | 'decide_failed'
|
type InlineError = 'scopes_required' | 'decide_failed'
|
||||||
@@ -22,7 +35,8 @@ type InlineError = 'scopes_required' | 'decide_failed'
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const CARD = 'flex flex-col gap-[18px] rounded-card bg-white p-8 text-[#141b2d] shadow-login'
|
const CARD =
|
||||||
|
'connect-light-surface flex flex-col gap-[18px] rounded-card bg-white p-8 text-[#141b2d] shadow-login'
|
||||||
const HEADING = 'text-[22px] font-bold tracking-[-0.02em] [overflow-wrap:anywhere]'
|
const HEADING = 'text-[22px] font-bold tracking-[-0.02em] [overflow-wrap:anywhere]'
|
||||||
const ALERT = 'flex items-center gap-2.5 rounded-control bg-[#fdf0f0] px-3.5 py-3 text-[#c62828]'
|
const ALERT = 'flex items-center gap-2.5 rounded-control bg-[#fdf0f0] px-3.5 py-3 text-[#c62828]'
|
||||||
const SECONDARY_BUTTON =
|
const SECONDARY_BUTTON =
|
||||||
@@ -30,7 +44,6 @@ const SECONDARY_BUTTON =
|
|||||||
|
|
||||||
const state = ref<State>('loading')
|
const state = ref<State>('loading')
|
||||||
const consent = ref<MCPConsent | null>(null)
|
const consent = ref<MCPConsent | null>(null)
|
||||||
const checked = ref<Set<string>>(new Set())
|
|
||||||
const offline = ref(true)
|
const offline = ref(true)
|
||||||
const busy = ref<'allow' | 'deny' | null>(null)
|
const busy = ref<'allow' | 'deny' | null>(null)
|
||||||
const switching = ref(false)
|
const switching = ref(false)
|
||||||
@@ -38,6 +51,8 @@ const inlineError = ref<InlineError | null>(null)
|
|||||||
const returnUri = ref('')
|
const returnUri = ref('')
|
||||||
const heading = ref<HTMLElement | null>(null)
|
const heading = ref<HTMLElement | null>(null)
|
||||||
const alertBlock = ref<HTMLElement | null>(null)
|
const alertBlock = ref<HTMLElement | null>(null)
|
||||||
|
const scopeAccessRef = ref<InstanceType<typeof ScopeAccessControl> | null>(null)
|
||||||
|
const scopePickerRef = ref<InstanceType<typeof ScopePicker> | null>(null)
|
||||||
let loadSeq = 0
|
let loadSeq = 0
|
||||||
let settled = false
|
let settled = false
|
||||||
|
|
||||||
@@ -48,15 +63,25 @@ const requestId = computed(() => {
|
|||||||
|
|
||||||
const scopes = computed(() => consent.value?.scopes ?? [])
|
const scopes = computed(() => consent.value?.scopes ?? [])
|
||||||
const grantable = computed(() => scopes.value.length > 0)
|
const grantable = computed(() => scopes.value.length > 0)
|
||||||
const starChecked = computed(() => checked.value.has('*'))
|
|
||||||
const selected = computed(() => {
|
const {
|
||||||
if (starChecked.value) {
|
availableTiers,
|
||||||
return ['*']
|
tier,
|
||||||
}
|
custom,
|
||||||
return scopes.value.map((scope) => scope.name).filter((name) => checked.value.has(name))
|
pickerOpen,
|
||||||
})
|
draftAdminRead,
|
||||||
|
draftScopes,
|
||||||
|
submittedScopes,
|
||||||
|
canSubmitScopes,
|
||||||
|
reset: resetScopeSelection,
|
||||||
|
selectTier,
|
||||||
|
openPicker,
|
||||||
|
applyPicker,
|
||||||
|
discardPicker,
|
||||||
|
} = useScopeSelection(scopes, 'connect')
|
||||||
|
|
||||||
const locked = computed(() => busy.value !== null || switching.value)
|
const locked = computed(() => busy.value !== null || switching.value)
|
||||||
const canAllow = computed(() => !locked.value && grantable.value && selected.value.length > 0)
|
const canAllow = computed(() => !locked.value && grantable.value && canSubmitScopes.value)
|
||||||
|
|
||||||
const clientName = computed(() => consent.value?.client.name || consent.value?.client.id || '')
|
const clientName = computed(() => consent.value?.client.name || consent.value?.client.id || '')
|
||||||
const redirectHost = computed(() => consent.value?.client.redirect_host ?? '')
|
const redirectHost = computed(() => consent.value?.client.redirect_host ?? '')
|
||||||
@@ -114,20 +139,12 @@ const returnLink = computed(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/** Every shown scope starts ticked except *, unless * is the only one. */
|
|
||||||
function initialTicks(view: MCPConsent): Set<string> {
|
|
||||||
const names = view.scopes.map((scope) => scope.name)
|
|
||||||
if (names.length === 1 && names[0] === '*') {
|
|
||||||
return new Set(names)
|
|
||||||
}
|
|
||||||
return new Set(names.filter((name) => name !== '*'))
|
|
||||||
}
|
|
||||||
|
|
||||||
async function load(): Promise<void> {
|
async function load(): Promise<void> {
|
||||||
const seq = ++loadSeq
|
const seq = ++loadSeq
|
||||||
state.value = 'loading'
|
state.value = 'loading'
|
||||||
inlineError.value = null
|
inlineError.value = null
|
||||||
consent.value = null
|
consent.value = null
|
||||||
|
resetScopeSelection([])
|
||||||
returnUri.value = ''
|
returnUri.value = ''
|
||||||
const id = requestId.value
|
const id = requestId.value
|
||||||
if (id === '') {
|
if (id === '') {
|
||||||
@@ -149,7 +166,7 @@ async function load(): Promise<void> {
|
|||||||
if (result.data) {
|
if (result.data) {
|
||||||
const view = result.data.data
|
const view = result.data.data
|
||||||
consent.value = view
|
consent.value = view
|
||||||
checked.value = initialTicks(view)
|
resetScopeSelection(view.scopes)
|
||||||
offline.value = true
|
offline.value = true
|
||||||
state.value = 'ready'
|
state.value = 'ready'
|
||||||
return
|
return
|
||||||
@@ -162,30 +179,56 @@ async function load(): Promise<void> {
|
|||||||
state.value = status === 404 ? 'expired' : 'load_error'
|
state.value = status === 404 ? 'expired' : 'load_error'
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleScope(name: string, on: boolean): void {
|
function onSelectTier(next: AccessTier): void {
|
||||||
const next = new Set(checked.value)
|
if (locked.value) {
|
||||||
if (name === '*') {
|
return
|
||||||
if (on) {
|
|
||||||
next.clear()
|
|
||||||
next.add('*')
|
|
||||||
} else {
|
|
||||||
next.delete('*')
|
|
||||||
}
|
|
||||||
} else if (!starChecked.value) {
|
|
||||||
if (on) {
|
|
||||||
next.add(name)
|
|
||||||
} else {
|
|
||||||
next.delete(name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
checked.value = next
|
selectTier(next)
|
||||||
if (inlineError.value === 'scopes_required') {
|
if (inlineError.value === 'scopes_required') {
|
||||||
inlineError.value = null
|
inlineError.value = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function scopeDisabled(name: string): boolean {
|
function onOpenPicker(): void {
|
||||||
return starChecked.value && name !== '*'
|
if (locked.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
openPicker()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onApplyPicker(): void {
|
||||||
|
applyPicker()
|
||||||
|
if (inlineError.value === 'scopes_required') {
|
||||||
|
inlineError.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPickerOpenChange(open: boolean): void {
|
||||||
|
if (!open) {
|
||||||
|
discardPicker()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPickerOpenAutoFocus(event: Event): void {
|
||||||
|
event.preventDefault()
|
||||||
|
if (scopePickerRef.value) {
|
||||||
|
scopePickerRef.value.focusSearch()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
void nextTick(() => {
|
||||||
|
scopePickerRef.value?.focusSearch()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPickerCloseAutoFocus(event: Event): void {
|
||||||
|
event.preventDefault()
|
||||||
|
if (scopeAccessRef.value) {
|
||||||
|
scopeAccessRef.value.focusPrimaryControl()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
void nextTick(() => {
|
||||||
|
scopeAccessRef.value?.focusPrimaryControl()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Schemes a consent redirect never uses: script, inline content and local files. */
|
/** Schemes a consent redirect never uses: script, inline content and local files. */
|
||||||
@@ -254,7 +297,7 @@ async function decide(decision: 'allow' | 'deny'): Promise<void> {
|
|||||||
decision === 'allow'
|
decision === 'allow'
|
||||||
? {
|
? {
|
||||||
decision,
|
decision,
|
||||||
scopes: selected.value,
|
scopes: submittedScopes.value,
|
||||||
offline_access: consent.value.offline_access ? offline.value : false,
|
offline_access: consent.value.offline_access ? offline.value : false,
|
||||||
}
|
}
|
||||||
: { decision, scopes: [], offline_access: false },
|
: { decision, scopes: [], offline_access: false },
|
||||||
@@ -363,14 +406,11 @@ watch(requestId, () => {
|
|||||||
<span class="h-3 w-56 rounded-[6px] bg-[#eceff4]" />
|
<span class="h-3 w-56 rounded-[6px] bg-[#eceff4]" />
|
||||||
<span class="h-3 w-40 rounded-[6px] bg-[#eceff4]" />
|
<span class="h-3 w-40 rounded-[6px] bg-[#eceff4]" />
|
||||||
</div>
|
</div>
|
||||||
<div class="overflow-hidden rounded-inner border border-[#e6e9ef]" aria-hidden="true">
|
<div class="flex flex-col gap-2" aria-hidden="true">
|
||||||
<div
|
<span class="h-10 rounded-inner bg-[#eceff4]" />
|
||||||
v-for="index in 3"
|
<div class="flex flex-col gap-2 rounded-inner border border-[#e6e9ef] bg-[#f3f5f8] p-4">
|
||||||
:key="index"
|
<span class="h-3 w-48 rounded-[6px] bg-[#eceff4]" />
|
||||||
class="flex min-h-[56px] items-center gap-3 border-t border-[#e6e9ef] px-4 py-3 first:border-t-0"
|
<span class="h-3 w-32 rounded-[6px] bg-[#eceff4]" />
|
||||||
>
|
|
||||||
<span class="size-5 shrink-0 rounded-[6px] bg-[#eceff4]" />
|
|
||||||
<span class="h-3 w-40 rounded-[6px] bg-[#eceff4]" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -483,47 +523,18 @@ watch(requestId, () => {
|
|||||||
|
|
||||||
<fieldset v-else :disabled="locked" class="flex min-w-0 flex-col gap-[18px]">
|
<fieldset v-else :disabled="locked" class="flex min-w-0 flex-col gap-[18px]">
|
||||||
<div class="flex min-w-0 flex-col gap-1.5">
|
<div class="flex min-w-0 flex-col gap-1.5">
|
||||||
<span id="connect-scopes-label" class="font-semibold">{{ t('backend::lang.api_tokens.scopes') }}</span>
|
<ScopeAccessControl
|
||||||
<div
|
ref="scopeAccessRef"
|
||||||
role="group"
|
id-prefix="connect"
|
||||||
aria-labelledby="connect-scopes-label"
|
:catalog="scopes"
|
||||||
data-scope-picker
|
:available-tiers="availableTiers"
|
||||||
:aria-invalid="inlineError === 'scopes_required' ? 'true' : undefined"
|
:tier="tier"
|
||||||
:class="inlineError === 'scopes_required' ? 'border-[#c62828]' : 'border-[#e6e9ef]'"
|
:custom="custom"
|
||||||
class="overflow-hidden rounded-inner border"
|
:disabled="locked"
|
||||||
>
|
:invalid="inlineError === 'scopes_required'"
|
||||||
<label
|
@update:tier="onSelectTier"
|
||||||
v-for="scope in scopes"
|
@customize="onOpenPicker"
|
||||||
:key="scope.name"
|
/>
|
||||||
:data-scope="scope.name"
|
|
||||||
:class="scopeDisabled(scope.name) ? 'cursor-not-allowed opacity-60' : 'cursor-pointer'"
|
|
||||||
class="flex min-h-[56px] items-start gap-3 border-t border-[#e6e9ef] px-4 py-3 first:border-t-0"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
class="mt-0.5 size-5 shrink-0 rounded-[6px] accent-[#22304d]"
|
|
||||||
:checked="checked.has(scope.name)"
|
|
||||||
:disabled="scopeDisabled(scope.name)"
|
|
||||||
@change="toggleScope(scope.name, ($event.target as HTMLInputElement).checked)"
|
|
||||||
/>
|
|
||||||
<span class="flex min-w-0 flex-col">
|
|
||||||
<span class="flex flex-wrap items-center gap-1">
|
|
||||||
<span class="font-semibold [overflow-wrap:anywhere]">{{ scope.label }}</span>
|
|
||||||
<span class="font-mono text-[13px] text-[#566175] [overflow-wrap:anywhere]">{{ scope.name }}</span>
|
|
||||||
<span
|
|
||||||
v-if="scope.read_only"
|
|
||||||
class="inline-flex h-6 items-center rounded-pill bg-[#f3f5f8] px-2.5 text-[13px] font-semibold whitespace-nowrap text-[#566175]"
|
|
||||||
>{{ t('backend::lang.api_tokens.read_only') }}</span
|
|
||||||
>
|
|
||||||
</span>
|
|
||||||
<span class="text-[13px] text-[#566175] [overflow-wrap:anywhere]">{{ scope.description }}</span>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<p v-if="starChecked" data-scope-all-note class="flex items-center gap-2 text-[13px] text-[#566175]">
|
|
||||||
<Info :size="14" class="shrink-0" aria-hidden="true" />
|
|
||||||
<span>{{ t('backend::lang.api_tokens.scope_all_includes') }}</span>
|
|
||||||
</p>
|
|
||||||
<div
|
<div
|
||||||
v-if="inlineError === 'scopes_required'"
|
v-if="inlineError === 'scopes_required'"
|
||||||
ref="alertBlock"
|
ref="alertBlock"
|
||||||
@@ -587,5 +598,50 @@ watch(requestId, () => {
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Customize scopes modal (D-10, D-11, D-12): light-literal surface even in dark mode. -->
|
||||||
|
<DialogRoot :open="pickerOpen" @update:open="onPickerOpenChange">
|
||||||
|
<DialogPortal>
|
||||||
|
<DialogOverlay data-dialog-overlay class="connect-light-surface fixed inset-0 z-40 bg-overlay" />
|
||||||
|
<DialogContent
|
||||||
|
data-scope-picker-dialog
|
||||||
|
data-dialog-content
|
||||||
|
aria-modal="true"
|
||||||
|
class="connect-light-surface fixed inset-0 z-50 flex h-[100dvh] w-full flex-col overflow-hidden bg-surface text-text sm:inset-auto sm:top-1/2 sm:left-1/2 sm:h-auto sm:max-h-[85dvh] sm:w-[calc(100%-32px)] sm:max-w-[640px] sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-modal sm:shadow-pop"
|
||||||
|
@open-auto-focus="onPickerOpenAutoFocus"
|
||||||
|
@close-auto-focus="onPickerCloseAutoFocus"
|
||||||
|
>
|
||||||
|
<div class="flex shrink-0 items-start gap-4 border-b border-border bg-surface p-4">
|
||||||
|
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
||||||
|
<DialogTitle class="text-[20px] font-bold tracking-[-0.01em] text-text">{{
|
||||||
|
t('backend::lang.api_tokens.scope_picker_title')
|
||||||
|
}}</DialogTitle>
|
||||||
|
<DialogDescription class="text-[13px] text-muted [overflow-wrap:anywhere]">{{
|
||||||
|
t('backend::lang.mcp_connect.scope_picker_description', { client: clientName })
|
||||||
|
}}</DialogDescription>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-action="close-scope-picker"
|
||||||
|
:aria-label="t('backend::lang.form.close')"
|
||||||
|
class="flex size-[34px] shrink-0 items-center justify-center rounded-tab bg-subtle text-muted hover:bg-hover hover:text-text"
|
||||||
|
@click="discardPicker"
|
||||||
|
>
|
||||||
|
<X :size="16" aria-hidden="true" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<ScopePicker
|
||||||
|
ref="scopePickerRef"
|
||||||
|
:catalog="scopes"
|
||||||
|
v-model:draft-admin-read="draftAdminRead"
|
||||||
|
v-model:draft-scopes="draftScopes"
|
||||||
|
:cancel-label="t('backend::lang.api_tokens.scope_picker_discard')"
|
||||||
|
:disabled="locked"
|
||||||
|
@apply="onApplyPicker"
|
||||||
|
@cancel="discardPicker"
|
||||||
|
/>
|
||||||
|
</DialogContent>
|
||||||
|
</DialogPortal>
|
||||||
|
</DialogRoot>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user