@@ -1,3 +1,4 @@
|
||||
import { createOperationKey } from '@/lib/operation-key';
|
||||
import { useState } from 'react';
|
||||
import { Management, button, control } from '@/pages/management/shared';
|
||||
import { profileJson } from '@/lib/profile-json';
|
||||
@@ -17,6 +18,7 @@ type Plan = {
|
||||
holders: number[];
|
||||
version: number | null;
|
||||
rule: string;
|
||||
pending: {approval_id:string;confirmation_url:string;expires_at:string} | null;
|
||||
};
|
||||
};
|
||||
export default function Installation(initial: Plan) {
|
||||
@@ -27,6 +29,9 @@ export default function Installation(initial: Plan) {
|
||||
const [second, setSecond] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [message, setMessage] = useState('');
|
||||
const [confirmationUrl, setConfirmationUrl] = useState<string | null>(null);
|
||||
const [installationKey] = useState(createOperationKey);
|
||||
const [bootstrapKey] = useState(createOperationKey);
|
||||
async function run(bootstrap = false) {
|
||||
setBusy(true);
|
||||
setMessage('');
|
||||
@@ -37,7 +42,7 @@ export default function Installation(initial: Plan) {
|
||||
hash: plan.hash,
|
||||
confirm: confirmed,
|
||||
reason,
|
||||
idempotency_key: crypto.randomUUID(),
|
||||
idempotency_key: bootstrap ? bootstrapKey : installationKey,
|
||||
...(bootstrap
|
||||
? {
|
||||
first_user_id: Number(first),
|
||||
@@ -48,11 +53,12 @@ export default function Installation(initial: Plan) {
|
||||
);
|
||||
setMessage(
|
||||
bootstrap
|
||||
? 'Dupla inicializada. Inicie uma nova sessão como um dos titulares designados; MFA permanece obrigatório.'
|
||||
? 'Pedido registado, sem atribuir privilégios. O segundo titular deve autenticar-se com MFA e confirmar pelo endereço abaixo.'
|
||||
: result.changed
|
||||
? 'Schema instalado. Perfis ainda não disponibilizados; nenhuma conta ou atribuição criada.'
|
||||
: 'Schema já instalado. Nenhuma reinstalação ou duplicação.',
|
||||
);
|
||||
if (bootstrap) setConfirmationUrl(result.confirmation_url as string);
|
||||
if (!bootstrap)
|
||||
setPlan(
|
||||
(await profileJson(
|
||||
@@ -141,6 +147,7 @@ export default function Installation(initial: Plan) {
|
||||
<section className="space-y-3 rounded border p-4">
|
||||
<h2>Inicialização separada dos dois superutilizadores</h2>
|
||||
<p>{plan.bootstrap.rule}</p>
|
||||
{plan.bootstrap.pending && <p>Pedido pendente até {plan.bootstrap.pending.expires_at}. <a className="underline" href={plan.bootstrap.pending.confirmation_url}>Recuperar pedido de confirmação</a>. Nenhum privilégio foi atribuído pelo pedido.</p>}
|
||||
{plan.bootstrap.initialized ? (
|
||||
<p>
|
||||
Dupla já inicializada:{' '}
|
||||
@@ -176,6 +183,7 @@ export default function Installation(initial: Plan) {
|
||||
busy ||
|
||||
!confirmed ||
|
||||
!plan.installed ||
|
||||
!!plan.bootstrap.pending ||
|
||||
!first ||
|
||||
!second ||
|
||||
first === second ||
|
||||
@@ -183,12 +191,13 @@ export default function Installation(initial: Plan) {
|
||||
}
|
||||
onClick={() => void run(true)}
|
||||
>
|
||||
Inicializar apenas estas duas contas
|
||||
Pedir confirmação ao segundo titular
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
<p role="status">{message}</p>
|
||||
{confirmationUrl && <p>Endereço para o segundo titular: <a className="underline" href={confirmationUrl}>{confirmationUrl}</a>. O primeiro titular pode consultar, mas não confirmar.</p>}
|
||||
</Management>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user