-- Bobinoo — 28 nov. 2026, suite de la revue de code. Idempotent. -- 1) Double authentification : les lectures par fonction (profil, bibliothèque, fil, notifications, -- listes partagées, avis, recherche…) exigent aussi le code pour un compte protégé. -- 2) Fil : une fiche restaurée (après suppression / import) ne compte plus comme « a noté ». -- 3) Notifications : une demande d'abonnement refusée disparaît. do $$ declare r record; def text; begin for r in select * from (values ('public.can_view(uuid)', 'select auth.uid() is not null and (', 'select auth.uid() is not null and public.azuu_mfa_ok() and ('), ('public.azuu_sl_member(uuid)', 'select auth.uid() is not null and exists (', 'select auth.uid() is not null and public.azuu_mfa_ok() and exists ('), ('public.get_feed(timestamp with time zone,integer)', 'where (p_before is null or l.created_at < p_before)', 'where public.azuu_mfa_ok() and (p_before is null or l.created_at < p_before)'), ('public.get_notifications()', 'where user_id = auth.uid() and kind in', 'where user_id = auth.uid() and public.azuu_mfa_ok() and kind in'), ('public.unread_notifications()', 'where n.user_id = auth.uid() and n.read_at is null', 'where n.user_id = auth.uid() and public.azuu_mfa_ok() and n.read_at is null'), ('public.mark_notifications_read()', 'where user_id = auth.uid() and read_at is null', 'where user_id = auth.uid() and public.azuu_mfa_ok() and read_at is null'), ('public.get_follow_requests()', 'where f.following_id = auth.uid() and f.status', 'where f.following_id = auth.uid() and public.azuu_mfa_ok() and f.status'), ('public.my_blocks()', 'where b.blocker_id = auth.uid()', 'where b.blocker_id = auth.uid() and public.azuu_mfa_ok()'), ('public.search_profiles(text)', 'if auth.uid() is null or char_length(term) < 2', 'if auth.uid() is null or not public.azuu_mfa_ok() or char_length(term) < 2'), ('public.title_reviews(text,integer)', 'if me is null or p_external_id', 'if me is null or not public.azuu_mfa_ok() or p_external_id'), ('public.get_shared_lists(text)', 'if me is null then', 'if me is null or not public.azuu_mfa_ok() then'), ('public.azuu_item_activity()', 'elsif tg_op = ''UPDATE'' and new.data ? ''rating''', 'elsif tg_op = ''UPDATE'' and old_st is not null and new.data ? ''rating''') ) v(fn, search, repl) loop def := pg_get_functiondef(to_regprocedure(r.fn)); if position(r.repl in def) > 0 then continue; end if; if position(r.search in def) = 0 then raise exception 'motif introuvable dans %', r.fn; end if; execute replace(def, r.search, r.repl); end loop; end $$; -- 3) Demande refusée (« retirer » par le compte suivi) : la notification « demande à te suivre » part avec do $$ declare def text; begin def := pg_get_functiondef('public.azuu_follow_notify()'::regprocedure); if position('-- Demande refusée ou annulée' in def) = 0 then def := replace(def, ' if auth.uid() is distinct from old.follower_id then return null; end if; if old.status = ''pending'' then -- Demande annulée : elle disparaît simplement delete from public.notifications where user_id = old.following_id and actor_id = old.follower_id and kind = ''follow_request''; return null; end if;', ' if old.status = ''pending'' then -- Demande refusée ou annulée : elle disparaît simplement delete from public.notifications where user_id = old.following_id and actor_id = old.follower_id and kind = ''follow_request''; return null; end if; if auth.uid() is distinct from old.follower_id then return null; end if;'); if position('-- Demande refusée ou annulée' in def) = 0 then raise exception 'motif introuvable dans azuu_follow_notify'; end if; execute def; end if; end $$;