Mandats : origin→FK identité + nomination auto + boutons + tests intégration
- origin TEXT → origin_id UUID FK duniter_identities (migration e3f4a5b6c7d8) - GET /auth/identities?q= : recherche d'identités par nom/adresse - MandateCreate.nomination_mode : auto (auto-assign auteur), collective, postpone - Wizard new.vue : champ origine = picker identité, checkbox "Démarrer maintenant" - [id].vue : modal "Assigner" = search-picker (résout UUID vs adresse SS58), affiche origin_display_name + mandatee_display_name, inputs natifs (<input>/<textarea>) - Erreurs API visibles dans l'UI (plus de catch silencieux) - test_mandate_flows.py : 17 tests intégration SQLite réels (origin, nomination, assign, lifecycle, revocation, interactions croisées) — 241 tests total OK Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -152,9 +152,35 @@ const canGoToInfo = computed(() => {
|
||||
type MandateType = 'statutory' | 'functional'
|
||||
const mandateType = ref<MandateType>('functional')
|
||||
const title = ref('')
|
||||
const origin = ref('')
|
||||
const description = ref('')
|
||||
|
||||
// Origin : identité Duniter (non texte libre)
|
||||
interface IdentityResult { id: string; address: string; display_name: string | null }
|
||||
const originQuery = ref('')
|
||||
const originResults = ref<IdentityResult[]>([])
|
||||
const originId = ref<string | null>(null)
|
||||
const originSearching = ref(false)
|
||||
let originTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
async function searchOrigin(q: string) {
|
||||
if (q.length < 2) { originResults.value = []; return }
|
||||
originSearching.value = true
|
||||
try {
|
||||
originResults.value = await $api<IdentityResult[]>('/auth/identities', { query: { q } })
|
||||
} catch { originResults.value = [] } finally { originSearching.value = false }
|
||||
}
|
||||
function onOriginInput(q: string) {
|
||||
originQuery.value = q
|
||||
originId.value = null
|
||||
if (originTimer) clearTimeout(originTimer)
|
||||
originTimer = setTimeout(() => searchOrigin(q), 300)
|
||||
}
|
||||
function selectOrigin(r: IdentityResult) {
|
||||
originId.value = r.id
|
||||
originQuery.value = r.display_name || r.address
|
||||
originResults.value = []
|
||||
}
|
||||
|
||||
type DurationMode = 'relative' | 'dates'
|
||||
const durationMode = ref<DurationMode>('relative')
|
||||
const durationValue = ref(3)
|
||||
@@ -265,24 +291,31 @@ const nominationSummary = computed(() => {
|
||||
})
|
||||
|
||||
// ── Création ──────────────────────────────────────────────────────────────────
|
||||
const startImmediately = ref(true)
|
||||
const submitting = ref(false)
|
||||
const submitError = ref<string | null>(null)
|
||||
|
||||
const auth = useAuthStore()
|
||||
|
||||
async function createMandate() {
|
||||
submitting.value = true
|
||||
submitError.value = null
|
||||
try {
|
||||
const dates = computedDates()
|
||||
const nominationMode = nominationCase.value === 'self' ? 'auto' : 'collective'
|
||||
|
||||
const mandate = await mandates.create({
|
||||
title: title.value.trim(),
|
||||
origin: origin.value.trim() || null,
|
||||
origin_id: originId.value,
|
||||
description: description.value.trim() || null,
|
||||
mandate_type: mandateType.value,
|
||||
nomination_mode: nominationMode,
|
||||
starts_at: dates.starts_at,
|
||||
ends_at: dates.ends_at,
|
||||
})
|
||||
if (!mandate) throw new Error('Erreur création mandat')
|
||||
|
||||
// Créer les étapes
|
||||
for (let i = 0; i < stepsToCreate.value.length; i++) {
|
||||
const s = stepsToCreate.value[i]!
|
||||
await $api(`/mandates/${mandate.id}/steps`, {
|
||||
@@ -290,9 +323,15 @@ async function createMandate() {
|
||||
body: { step_order: i, step_type: s.step_type, title: s.title, description: s.description },
|
||||
})
|
||||
}
|
||||
|
||||
// Démarrer le processus si demandé
|
||||
if (startImmediately.value) {
|
||||
await $api(`/mandates/${mandate.id}/advance`, { method: 'POST' })
|
||||
}
|
||||
|
||||
navigateTo(`/mandates/${mandate.id}`)
|
||||
} catch (e: any) {
|
||||
submitError.value = e?.message ?? 'Erreur lors de la création'
|
||||
submitError.value = e?.data?.detail ?? e?.message ?? 'Erreur lors de la création'
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
@@ -620,17 +659,38 @@ function selectNomination(c: NominationCase) {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Origine -->
|
||||
<!-- Origine (personne) -->
|
||||
<div class="mwiz__section">
|
||||
<label class="mwiz__label">Origine <span class="mwiz__optional">(optionnel)</span></label>
|
||||
<textarea
|
||||
v-model="origin"
|
||||
class="mwiz__textarea"
|
||||
rows="2"
|
||||
lang="fr"
|
||||
spellcheck="true"
|
||||
placeholder="Qui propose ce mandat, dans quel contexte, suite à quelle décision ou besoin ?"
|
||||
/>
|
||||
<label class="mwiz__label">Proposé par <span class="mwiz__optional">(optionnel)</span></label>
|
||||
<div class="relative">
|
||||
<input
|
||||
:value="originQuery"
|
||||
type="text"
|
||||
class="mwiz__input"
|
||||
placeholder="Rechercher un membre de la communauté…"
|
||||
@input="onOriginInput(($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
<div
|
||||
v-if="originResults.length"
|
||||
class="absolute z-10 mt-1 w-full bg-white dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-700 shadow-lg overflow-hidden"
|
||||
>
|
||||
<button
|
||||
v-for="r in originResults"
|
||||
:key="r.id"
|
||||
class="w-full flex items-center gap-3 px-4 py-2 text-left text-sm hover:bg-gray-50 dark:hover:bg-gray-800"
|
||||
@click="selectOrigin(r)"
|
||||
>
|
||||
<UIcon name="i-lucide-user" class="text-gray-400 shrink-0" />
|
||||
<div>
|
||||
<p class="font-medium text-gray-900 dark:text-white">{{ r.display_name || r.address }}</p>
|
||||
<p class="text-xs text-gray-500 font-mono">{{ r.address.slice(0, 20) }}…</p>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="originId" class="mwiz__hint text-green-600">
|
||||
<UIcon name="i-lucide-check-circle" class="text-xs" /> {{ originQuery }} sélectionné
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Description -->
|
||||
@@ -709,7 +769,7 @@ function selectNomination(c: NominationCase) {
|
||||
<UIcon :name="MANDATE_TYPE_OPTIONS.find(o => o.value === mandateType)?.icon ?? 'i-lucide-circle'" class="text-xs" />
|
||||
{{ MANDATE_TYPE_OPTIONS.find(o => o.value === mandateType)?.label }}
|
||||
</p>
|
||||
<p v-if="origin" class="mwiz__recap-meta">Origine : {{ origin }}</p>
|
||||
<p v-if="originId" class="mwiz__recap-meta">Proposé par : {{ originQuery }}</p>
|
||||
<p v-if="description" class="mwiz__recap-meta">{{ description }}</p>
|
||||
<p class="mwiz__recap-meta">
|
||||
<UIcon name="i-lucide-clock" class="text-xs" />
|
||||
@@ -732,6 +792,18 @@ function selectNomination(c: NominationCase) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Option démarrage -->
|
||||
<div class="mwiz__start-option">
|
||||
<label class="mwiz__start-label">
|
||||
<input v-model="startImmediately" type="checkbox" class="mwiz__checkbox" />
|
||||
<span>Démarrer le processus de nomination immédiatement</span>
|
||||
</label>
|
||||
<p class="mwiz__start-hint">
|
||||
<template v-if="startImmediately">Le mandat passera en phase de nomination dès la création.</template>
|
||||
<template v-else>Le mandat restera en brouillon — à démarrer manuellement depuis la fiche.</template>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p v-if="submitError" class="mwiz__error">{{ submitError }}</p>
|
||||
|
||||
<div class="mwiz__recap-actions">
|
||||
@@ -1173,6 +1245,32 @@ function selectNomination(c: NominationCase) {
|
||||
|
||||
.mwiz__error { color: var(--mood-danger, #e53e3e); font-size: 0.875rem; padding: 0.5rem 0; }
|
||||
|
||||
/* Start option */
|
||||
.mwiz__start-option {
|
||||
background: var(--mood-surface);
|
||||
border-radius: 16px;
|
||||
padding: 1.125rem 1.25rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.mwiz__start-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
font-weight: 600;
|
||||
font-size: 0.9375rem;
|
||||
color: var(--mood-text);
|
||||
cursor: pointer;
|
||||
}
|
||||
.mwiz__checkbox {
|
||||
width: 1.125rem;
|
||||
height: 1.125rem;
|
||||
accent-color: var(--mood-accent);
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.mwiz__start-hint { font-size: 0.8125rem; color: var(--mood-muted); margin-top: 0.375rem; padding-left: 1.75rem; }
|
||||
.mwiz__hint { font-size: 0.8125rem; margin-top: 0.25rem; }
|
||||
|
||||
/* Transitions */
|
||||
.slide-fade-enter-active, .slide-fade-leave-active { transition: all 0.2s ease; }
|
||||
.slide-fade-enter-from { opacity: 0; transform: translateX(20px); }
|
||||
|
||||
Reference in New Issue
Block a user