feat(ui): External-Agent-API + Besitzübertragung UI (UI-Backlog Module 15+16/16)
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
Modul 15 External-Agent (ai_assistant-Plugin, Manifest settings_page): - SettingsExternalAgents.tsx: Agentenliste mit curl-Snippets (run/status/stream), Copy-Buttons, Bearer-Token-Hinweis, Rate-Limit-Doku, Token-Link - api/externalAgent.ts (useAiAgents, buildCurlSnippets, curlCommand) - Manifest: settings_pages +external-agents (order 61, permission ai:read) - Komponenten-Map regeneriert (43) Modul 16 Ownership-Transfer (Core): - SettingsOwnership.tsx: Admin-Gate, From/To-User-Selects, 10 Entity-Type-Chips, ConfirmDialog, Ergebnis-Tabelle - api/ownership.ts (useTransferOwnership, OWNERSHIP_ENTITY_TYPES) - Route /settings/ownership + Nav-Eintrag i18n de/en +28 Keys. Vitest 12/12, tsc 0, Build OK, ruff OK, Manifest-Import OK
This commit is contained in:
@@ -53,6 +53,7 @@ export function SettingsPage() {
|
||||
{ to: '/settings/permission-templates', label: 'Berechtigungs-Vorlagen', icon: '\ud83d\udd11' },
|
||||
{ to: '/settings/policies', label: 'ABAC-Richtlinien', icon: '\ud83d\udee1\ufe0f' },
|
||||
{ to: '/settings/guests', label: 'Gäste', icon: '\ud83d\udc64' },
|
||||
{ to: '/settings/ownership', label: 'Besitzübertragung', icon: '\ud83d\udce4' },
|
||||
];
|
||||
|
||||
const existingPaths = new Set(hardcodedNavItems.map(item => item.to));
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* External Agents API settings page — integration guide for external
|
||||
* systems (UI-Backlog module 15/16).
|
||||
*
|
||||
* Backend: /api/v1/external/agent (ai_assistant plugin, external_api.py).
|
||||
* - POST /{agent_id}/run → run agent (Bearer auth, 10 req/min)
|
||||
* - GET /{agent_id}/status → agent status + run stats
|
||||
* - POST /{agent_id}/stream → SSE stream
|
||||
*
|
||||
* These endpoints are Bearer-token-only (no session cookies) — meant for
|
||||
* external systems (n8n, scripts, other apps). This page lists the
|
||||
* tenant's AI agents and renders copy-paste curl snippets per agent.
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Bot, Copy, Check, Inbox } from 'lucide-react';
|
||||
import {
|
||||
useAiAgents,
|
||||
buildCurlSnippets,
|
||||
curlCommand,
|
||||
type AIAgent,
|
||||
} from '@/api/externalAgent';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { EmptyState } from '@/components/ui/EmptyState';
|
||||
import { Skeleton } from '@/components/ui/Skeleton';
|
||||
|
||||
function CopyButton({ text, testId }: { text: string; testId: string }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const copy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
} catch {
|
||||
// clipboard API unavailable — user can select manually
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={copy}
|
||||
aria-label="copy"
|
||||
data-testid={testId}
|
||||
>
|
||||
{copied ? (
|
||||
<Check className="w-4 h-4 text-success-600" aria-hidden="true" />
|
||||
) : (
|
||||
<Copy className="w-4 h-4" aria-hidden="true" />
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function AgentCard({ agent }: { agent: AIAgent }) {
|
||||
const { t } = useTranslation();
|
||||
const snippets = buildCurlSnippets(agent.id);
|
||||
|
||||
return (
|
||||
<Card className="p-4" data-testid={`external-agent-card-${agent.id}`}>
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Bot className="w-4 h-4 text-primary-600 flex-shrink-0" aria-hidden="true" />
|
||||
<span className="text-sm font-medium text-secondary-900 dark:text-secondary-100">
|
||||
{agent.name}
|
||||
</span>
|
||||
<Badge variant={agent.is_active ? 'success' : 'secondary'} dot>
|
||||
{agent.is_active ? t('common.active') : t('common.inactive')}
|
||||
</Badge>
|
||||
</div>
|
||||
{agent.description && (
|
||||
<p className="text-xs text-secondary-500 dark:text-secondary-400 mb-3">
|
||||
{agent.description}
|
||||
</p>
|
||||
)}
|
||||
<div className="space-y-2">
|
||||
{snippets.map((snippet) => (
|
||||
<div
|
||||
key={snippet.description}
|
||||
className="bg-secondary-50 dark:bg-secondary-900/50 rounded-lg p-3"
|
||||
data-testid={`curl-snippet-${agent.id}-${snippet.description}`}
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2 mb-1">
|
||||
<span className="text-xs font-medium text-secondary-600 dark:text-secondary-300">
|
||||
{snippet.description}
|
||||
</span>
|
||||
<CopyButton
|
||||
text={curlCommand(snippet)}
|
||||
testId={`curl-copy-${agent.id}-${snippet.description}`}
|
||||
/>
|
||||
</div>
|
||||
<pre className="text-xs text-secondary-700 dark:text-secondary-200 overflow-x-auto whitespace-pre-wrap break-all">
|
||||
{curlCommand(snippet)}
|
||||
</pre>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function SettingsExternalAgentsPage() {
|
||||
const { t } = useTranslation();
|
||||
const { data: agents, isLoading } = useAiAgents();
|
||||
|
||||
const items = agents ?? [];
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-4xl mx-auto" data-testid="settings-external-agents-page">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<h1 className="text-2xl font-bold text-secondary-900">
|
||||
{t('settings.externalAgents')}
|
||||
</h1>
|
||||
</div>
|
||||
<p className="text-sm text-secondary-500 mb-4">{t('settings.externalAgentsHint')}</p>
|
||||
<div className="mb-6 rounded-lg bg-primary-50 dark:bg-primary-900/20 border border-primary-200 dark:border-primary-800 p-4">
|
||||
<p className="text-xs text-primary-800 dark:text-primary-200">
|
||||
{t('settings.externalAgentsAuthHint')}{' '}
|
||||
<Link
|
||||
to="/settings/api-tokens"
|
||||
className="font-medium underline underline-offset-2"
|
||||
>
|
||||
{t('settings.externalAgentsTokenLink')}
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div data-testid="external-agents-skeleton" className="space-y-3">
|
||||
<Skeleton className="h-28" />
|
||||
<Skeleton className="h-28" />
|
||||
</div>
|
||||
) : items.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<Inbox className="w-8 h-8 text-secondary-400" aria-hidden="true" />}
|
||||
title={t('settings.noExternalAgents')}
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{items.map((agent) => (
|
||||
<AgentCard key={agent.id} agent={agent} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/**
|
||||
* Ownership transfer settings page — admin bulk ownership transfer
|
||||
* (UI-Backlog module 16/16).
|
||||
*
|
||||
* Backend: POST /api/v1/ownership/transfer (require_admin).
|
||||
* Transfers all records (owner_id) from one user to another, optionally
|
||||
* scoped to selected entity types (10 known types). Use case: employee
|
||||
* leaves the company — their records move to the successor.
|
||||
*/
|
||||
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Lock } from 'lucide-react';
|
||||
import { asError } from '@/utils/errorTypes';
|
||||
import {
|
||||
useTransferOwnership,
|
||||
OWNERSHIP_ENTITY_TYPES,
|
||||
type OwnershipTransferResult,
|
||||
} from '@/api/ownership';
|
||||
import { useUsers, type UserResponse } from '@/api/users';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
import { Select } from '@/components/ui/Select';
|
||||
import { ConfirmDialog } from '@/components/ui/ConfirmDialog';
|
||||
import { Skeleton } from '@/components/ui/Skeleton';
|
||||
|
||||
export function SettingsOwnershipPage() {
|
||||
const { t } = useTranslation();
|
||||
const toast = useToast();
|
||||
const user = useAuthStore((state) => state.user);
|
||||
const isAdmin = user?.is_system_admin === true;
|
||||
|
||||
const { data: usersData, isLoading } = useUsers(1, 100);
|
||||
const transferMutation = useTransferOwnership();
|
||||
|
||||
const [fromId, setFromId] = useState('');
|
||||
const [toId, setToId] = useState('');
|
||||
const [selectedTypes, setSelectedTypes] = useState<Set<string>>(new Set());
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
const [result, setResult] = useState<OwnershipTransferResult | null>(null);
|
||||
|
||||
const users: UserResponse[] = usersData?.items ?? [];
|
||||
|
||||
const userOptions = useMemo(
|
||||
() => users.map((u) => ({ value: u.id, label: `${u.name} (${u.email})` })),
|
||||
[users],
|
||||
);
|
||||
|
||||
const fromUser = users.find((u) => u.id === fromId);
|
||||
const toUser = users.find((u) => u.id === toId);
|
||||
|
||||
if (!isAdmin) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[50vh]" role="alert">
|
||||
<div className="text-center">
|
||||
<Lock className="w-10 h-10 mx-auto text-secondary-400" aria-hidden="true" />
|
||||
<p className="mt-3 text-sm text-secondary-600" data-testid="ownership-admin-only">
|
||||
{t('settings.ownershipAdminOnly')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const toggleType = (entityType: string) => {
|
||||
setSelectedTypes((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(entityType)) {
|
||||
next.delete(entityType);
|
||||
} else {
|
||||
next.add(entityType);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
const handleTransfer = async () => {
|
||||
try {
|
||||
const payload = {
|
||||
from_user_id: fromId,
|
||||
to_user_id: toId,
|
||||
entity_types: selectedTypes.size > 0 ? Array.from(selectedTypes) : null,
|
||||
};
|
||||
const res = await transferMutation.mutateAsync(payload);
|
||||
setResult(res);
|
||||
toast.success(t('settings.ownershipTransferred'));
|
||||
setConfirmOpen(false);
|
||||
} catch (err: unknown) {
|
||||
const errObj = asError(err);
|
||||
toast.error(errObj.message || t('common.error'));
|
||||
setConfirmOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
const canSubmit = fromId && toId && fromId !== toId;
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-4xl mx-auto" data-testid="settings-ownership-page">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<h1 className="text-2xl font-bold text-secondary-900">{t('settings.ownership')}</h1>
|
||||
</div>
|
||||
<p className="text-sm text-secondary-500 mb-6">{t('settings.ownershipHint')}</p>
|
||||
|
||||
{isLoading ? (
|
||||
<div data-testid="ownership-skeleton" className="space-y-3">
|
||||
<Skeleton className="h-20" />
|
||||
<Skeleton className="h-20" />
|
||||
</div>
|
||||
) : (
|
||||
<Card className="p-5">
|
||||
<div className="space-y-5" data-testid="ownership-form">
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Select
|
||||
label={t('settings.ownershipFrom')}
|
||||
options={[{ value: '', label: '—' }, ...userOptions]}
|
||||
value={fromId}
|
||||
onChange={(e) => setFromId(e.target.value)}
|
||||
data-testid="ownership-from"
|
||||
/>
|
||||
<Select
|
||||
label={t('settings.ownershipTo')}
|
||||
options={[{ value: '', label: '—' }, ...userOptions]}
|
||||
value={toId}
|
||||
onChange={(e) => setToId(e.target.value)}
|
||||
data-testid="ownership-to"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-sm font-medium text-secondary-900 mb-2">
|
||||
{t('settings.ownershipEntityTypes')}{' '}
|
||||
<span className="text-secondary-500 font-normal">
|
||||
({t('settings.ownershipAllHint')})
|
||||
</span>
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{OWNERSHIP_ENTITY_TYPES.map((et) => (
|
||||
<button
|
||||
key={et}
|
||||
type="button"
|
||||
onClick={() => toggleType(et)}
|
||||
className={
|
||||
selectedTypes.has(et)
|
||||
? 'px-3 py-1.5 rounded-full text-sm font-medium bg-primary-100 text-primary-700 border border-primary-300'
|
||||
: 'px-3 py-1.5 rounded-full text-sm font-medium bg-secondary-100 text-secondary-700 border border-secondary-200 hover:bg-secondary-200'
|
||||
}
|
||||
aria-pressed={selectedTypes.has(et)}
|
||||
data-testid={`ownership-type-${et}`}
|
||||
>
|
||||
{t(`settings.ownershipType_${et}`, et)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
onClick={() => setConfirmOpen(true)}
|
||||
disabled={!canSubmit || transferMutation.isPending}
|
||||
data-testid="ownership-submit-btn"
|
||||
>
|
||||
{t('settings.ownershipTransfer')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{result && (
|
||||
<Card className="p-5 mt-6" data-testid="ownership-result">
|
||||
<h2 className="text-lg font-semibold text-secondary-900 mb-3">
|
||||
{t('settings.ownershipResult')}
|
||||
</h2>
|
||||
<div className="space-y-2">
|
||||
{Object.entries(result.results).map(([entityType, count]) => (
|
||||
<div key={entityType} className="flex items-center justify-between text-sm">
|
||||
<span className="text-secondary-700">
|
||||
{t(`settings.ownershipType_${entityType}`, entityType)}
|
||||
</span>
|
||||
<Badge variant={count > 0 ? 'success' : 'secondary'}>{count}</Badge>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={confirmOpen}
|
||||
title={t('settings.ownershipTransfer')}
|
||||
message={
|
||||
fromUser && toUser
|
||||
? `${t('settings.ownershipConfirm')}: ${fromUser.name} → ${toUser.name}? (${
|
||||
selectedTypes.size > 0
|
||||
? t('settings.ownershipSelectedTypes', { count: selectedTypes.size })
|
||||
: t('settings.ownershipAllTypes')
|
||||
})`
|
||||
: ''
|
||||
}
|
||||
variant="danger"
|
||||
onConfirm={handleTransfer}
|
||||
onCancel={() => setConfirmOpen(false)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user