Groupes d'identités : modèle DB, router, store, UI cercles + Protocoles
- Group + GroupMember : modèle SQLAlchemy + migration + router CRUD - /api/v1/groups : liste, création, suppression, membres (add/remove) - groups.ts : store Pinia (fetchAll, getGroup, create, remove, addMember, removeMember) - decisions/new.vue : cercles 1 & 2 en mode texte libre OU groupe prédéfini (affected_count calculé depuis le member_count du groupe) - protocols/index.vue : section Groupes avec expand/collapse, ajout/suppression membres - lang="fr" + spellcheck sur tous les textareas ; placeholder cercle 2 corrigé - n8n channels : prévu sprint futur (texte libre → webhook appel à contribution) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
110
frontend/app/stores/groups.ts
Normal file
110
frontend/app/stores/groups.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
export interface GroupMember {
|
||||
id: string
|
||||
display_name: string
|
||||
identity_id: string | null
|
||||
added_at: string
|
||||
}
|
||||
|
||||
export interface Group {
|
||||
id: string
|
||||
name: string
|
||||
description: string | null
|
||||
organization_id: string | null
|
||||
created_at: string
|
||||
members: GroupMember[]
|
||||
}
|
||||
|
||||
export interface GroupSummary {
|
||||
id: string
|
||||
name: string
|
||||
description: string | null
|
||||
organization_id: string | null
|
||||
member_count: number
|
||||
}
|
||||
|
||||
export interface GroupCreate {
|
||||
name: string
|
||||
description?: string | null
|
||||
}
|
||||
|
||||
export interface GroupMemberCreate {
|
||||
display_name: string
|
||||
identity_id?: string | null
|
||||
}
|
||||
|
||||
export const useGroupsStore = defineStore('groups', () => {
|
||||
const { $api } = useApi()
|
||||
const orgs = useOrgsStore()
|
||||
|
||||
const list = ref<GroupSummary[]>([])
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
async function fetchAll() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
list.value = await $api<GroupSummary[]>('/groups/')
|
||||
} catch (e: any) {
|
||||
error.value = e?.message ?? 'Erreur chargement groupes'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function getGroup(id: string): Promise<Group | null> {
|
||||
try {
|
||||
return await $api<Group>(`/groups/${id}`)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function create(payload: GroupCreate): Promise<Group | null> {
|
||||
try {
|
||||
const group = await $api<Group>('/groups/', { method: 'POST', body: payload })
|
||||
await fetchAll()
|
||||
return group
|
||||
} catch (e: any) {
|
||||
error.value = e?.message ?? 'Erreur création groupe'
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(id: string): Promise<boolean> {
|
||||
try {
|
||||
await $api(`/groups/${id}`, { method: 'DELETE' })
|
||||
list.value = list.value.filter(g => g.id !== id)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async function addMember(groupId: string, payload: GroupMemberCreate): Promise<GroupMember | null> {
|
||||
try {
|
||||
const member = await $api<GroupMember>(`/groups/${groupId}/members`, {
|
||||
method: 'POST',
|
||||
body: payload,
|
||||
})
|
||||
const g = list.value.find(g => g.id === groupId)
|
||||
if (g) g.member_count++
|
||||
return member
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function removeMember(groupId: string, memberId: string): Promise<boolean> {
|
||||
try {
|
||||
await $api(`/groups/${groupId}/members/${memberId}`, { method: 'DELETE' })
|
||||
const g = list.value.find(g => g.id === groupId)
|
||||
if (g) g.member_count--
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return { list, loading, error, fetchAll, getGroup, create, remove, addMember, removeMember }
|
||||
})
|
||||
Reference in New Issue
Block a user