(Feat) V2

This commit is contained in:
2026-07-01 15:44:20 +02:00
parent 9789100334
commit 2a5d9bb0fd
10 changed files with 285 additions and 52 deletions
+29 -4
View File
@@ -81,6 +81,8 @@ Deno.serve(async (req) => {
role: pr.role ?? 'other',
roles,
is_admin: pr.is_admin ?? false,
avatar_color: pr.avatar_color ?? '#7c5cff',
avatar_url: pr.avatar_url ?? null,
created_at: pr.created_at ?? u.created_at
}
})
@@ -131,14 +133,34 @@ Deno.serve(async (req) => {
}
case 'update': {
const { id, full_name, role, roles, is_admin } = p
const { id, full_name, email, password, role, roles, is_admin, avatar_url } = p
if (!id) return json({ error: 'Identifiant manquant.' }, 400)
if (id === user.id && is_admin === false)
return json({ error: 'Tu ne peux pas retirer ton propre statut admin.' }, 400)
// --- a) Champs du compte auth (email / mot de passe / métadonnées) ---
const authPatch: Record<string, unknown> = {}
if (email !== undefined && String(email).trim()) {
authPatch.email = String(email).trim()
authPatch.email_confirm = true // évite le mail de confirmation
}
if (password !== undefined && String(password) !== '') {
if (String(password).length < 6)
return json({ error: 'Le mot de passe doit faire au moins 6 caractères.' }, 400)
authPatch.password = String(password)
}
if (full_name !== undefined)
authPatch.user_metadata = { full_name, role: Array.isArray(roles) ? roles[0] : role }
if (Object.keys(authPatch).length > 0) {
const { error: authErr } = await admin.auth.admin.updateUserById(id, authPatch)
if (authErr) return json({ error: authErr.message }, 400)
}
// --- b) Champs du profil (nom, pôles, admin) ---
const patch: Record<string, unknown> = {}
if (full_name !== undefined) patch.full_name = full_name
if (is_admin !== undefined) patch.is_admin = !!is_admin
if (avatar_url !== undefined) patch.avatar_url = avatar_url || null
// Gestion des pôles : roles = liste complète, role = principal (roles[0]).
if (Array.isArray(roles)) {
const primary = roles[0] ?? 'other'
@@ -148,10 +170,13 @@ Deno.serve(async (req) => {
patch.role = role
patch.roles = [role]
}
if (Object.keys(patch).length === 0) return json({ error: 'Rien à modifier.' }, 400)
if (Object.keys(patch).length > 0) {
const { error } = await admin.from('profiles').update(patch).eq('id', id)
if (error) return json({ error: error.message }, 400)
}
const { error } = await admin.from('profiles').update(patch).eq('id', id)
if (error) return json({ error: error.message }, 400)
if (Object.keys(authPatch).length === 0 && Object.keys(patch).length === 0)
return json({ error: 'Rien à modifier.' }, 400)
return json({ ok: true })
}
+2 -1
View File
@@ -56,7 +56,8 @@ create table if not exists public.tasks (
description text,
status task_status not null default 'todo',
priority priority_level not null default 'medium',
pole member_role,
pole member_role, -- pôle principal (= poles[0], compat)
poles member_role[] not null default '{}', -- tous les pôles concernés par la tâche
assignee_ids uuid[] not null default '{}',
due_date date,
position double precision not null default 0,
+11
View File
@@ -143,3 +143,14 @@ create policy avatars_update on storage.objects
for update to authenticated using (bucket_id = 'avatars');
create policy avatars_delete on storage.objects
for delete to authenticated using (bucket_id = 'avatars');
-- ---------------------------------------------------------------------
-- v7 — Plusieurs pôles par tâche
-- ---------------------------------------------------------------------
alter table public.tasks
add column if not exists poles member_role[] not null default '{}';
-- Reprend le pôle unique existant dans le tableau (si présent).
update public.tasks
set poles = array[pole]
where pole is not null and poles = '{}';