From dbaec8e03eee2c74932e4ed557f1a36342be3cd5 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 09:08:01 +0000 Subject: [PATCH] Corrections issues de la revue de code (agents de test) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Double authentification : l'écran du code se ferme bien après un code juste (la session « aal2 » prévient maintenant l'app) ; plus d'affichage furtif de l'app avant la vérification ; revérification au retour du réseau - Serveur (migration 20261128170000, appliquée) : les lectures par fonction (profil, bibliothèque, fil, notifications, listes partagées, avis, recherche, blocages) exigent aussi le code pour un compte protégé ; une fiche restaurée ne compte plus comme « a noté » ; une demande d'abonnement refusée disparaît des notifications - Catalogue : la grille continue de se charger après un passage par Journal / Listes - Moyenne des notes de saison arrondie à la demi-étoile (et plus à l'étoile entière) - Double tap sur « +1 » : plus de double message de fin de revisionnage ; « −1 » jamais ignoré - Bouton « Ouvrir les Réglages » (clé TMDB retirée) supprimé de la recherche - Pluriels russe, polonais et arabe complétés pour les notifications Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe --- CLAUDE.md | 2 +- src/App.tsx | 10 +--- src/Root.tsx | 38 ++++++++----- src/components/HomeHero.tsx | 1 + src/components/title/AddTitle.tsx | 7 --- src/components/title/EditDetails.tsx | 1 - src/components/title/TitleSheet.tsx | 5 +- src/i18n/locales/ar.ts | 4 +- src/i18n/locales/de.ts | 1 - src/i18n/locales/en.ts | 1 - src/i18n/locales/es.ts | 1 - src/i18n/locales/fr.ts | 1 - src/i18n/locales/hi.ts | 1 - src/i18n/locales/id.ts | 1 - src/i18n/locales/it.ts | 1 - src/i18n/locales/ja.ts | 1 - src/i18n/locales/ko.ts | 1 - src/i18n/locales/nl.ts | 1 - src/i18n/locales/pl.ts | 3 +- src/i18n/locales/pt.ts | 1 - src/i18n/locales/ru.ts | 3 +- src/i18n/locales/th.ts | 1 - src/i18n/locales/tr.ts | 1 - src/i18n/locales/vi.ts | 1 - src/i18n/locales/zh.ts | 1 - src/lib/cloud/auth.ts | 5 +- src/lib/seasons.ts | 6 +- src/pages/CatalogPage.tsx | 2 +- src/store.tsx | 12 ++-- .../20261128170000_mfa_reads_and_fixes.sql | 55 +++++++++++++++++++ 30 files changed, 106 insertions(+), 63 deletions(-) create mode 100644 supabase/migrations/20261128170000_mfa_reads_and_fixes.sql diff --git a/CLAUDE.md b/CLAUDE.md index 0106fb9..095121a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -61,7 +61,7 @@ npm run build # build de prod - RTL géré (arabe) : préférer les classes logiques (`ps-`/`pe-`, `ms-`/`me-`, `start-`/`end-`, `border-e`). ## État (au 28 nov. 2026) -- **Toutes les migrations de `supabase/migrations/` sont appliquées en ligne**, jusqu'à `20261128160000_mfa_enforcement.sql` incluse. +- **Toutes les migrations de `supabase/migrations/` sont appliquées en ligne**, jusqu'à `20261128170000_mfa_reads_and_fixes.sql` incluse. - **Notifications : abonnements uniquement** (27 nov. 2026) — cloche sur l'accueil, dans l'app, pas de push. Types : `new_follower`, `follow_request`, `unfollow`, `follow_accepted` (trigger `follows_notify`, RPC `get_notifications` / `unread_notifications` / `mark_notifications_read`). Les anciennes notifications (push, commentaires, épisodes, invitations) et `azuu_notify` ont été supprimées. La fonction Edge `send-push` répond 410 : à supprimer depuis le tableau de bord Supabase. - **Retirés (27-28 nov. 2026)** : défis, couleur d'accent au choix, apparences Nuit/Étoilé, notation sur 10 (les notes restent stockées sur 10 en interne, affichées sur 5 étoiles). - **Double authentification (TOTP)** : optionnelle, Réglages → Mon compte (`src/components/TwoFactor.tsx`, fonctions dans `src/lib/cloud/auth.ts`). À la connexion, `Root.tsx` demande le code (`MfaScreen`) si le compte a un facteur vérifié. Côté serveur, `azuu_mfa_ok()` : règles RLS restrictives « mfa required » (items, lists, settings, follows, profiles, activity), `is_admin()` et `azuu_me_active()` ; les fonctions Edge (`_shared/auth.ts`) refusent un jeton « aal1 » d'un compte protégé. diff --git a/src/App.tsx b/src/App.tsx index e6b8619..644368c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -104,13 +104,7 @@ export default function App() { // Laisse les fenêtres retirer leur entrée d'historique avant de changer d'onglet setTimeout(() => go('home'), 50) } - const toSettings = () => { - setLayers([]) - setAdding(false) - setManual(null) - // Laisse les fenêtres retirer leur entrée d'historique avant de changer d'onglet - setTimeout(() => go('settings'), 50) - } + return ( @@ -144,7 +138,6 @@ export default function App() { onOpenItem={openItem} onOpenPerson={openPerson} onManual={(title) => setManual(title)} - onGoToSettings={toSettings} /> )} {layers.map((l) => @@ -154,7 +147,6 @@ export default function App() { item={l.item} seed={l.seed} onClose={() => closeLayer(l.uid)} - onGoToSettings={toSettings} onOpenPerson={openPerson} focus={l.item ? l.focus : undefined} onDone={backHome} diff --git a/src/Root.tsx b/src/Root.tsx index 6652ee3..34a4669 100644 --- a/src/Root.tsx +++ b/src/Root.tsx @@ -46,28 +46,38 @@ export default function Root() { setAuthMode(mode) setGuest(false) } - // Double authentification : un compte protégé doit saisir son code avant d'entrer (undefined = vérification en cours). - // Comptes sans double authentification (déjà vérifiés sur cet appareil) : on entre tout de suite, la vérification se fait en fond. - const [mfaFactor, setMfaFactor] = useState(() => - cloudEnabled && getSession() && sessionAal() !== 'aal2' && knownMfa() !== false ? undefined : null, - ) + // Double authentification : un compte protégé doit saisir son code avant d'entrer. + // Résultat de la vérification, rattaché au jeton vérifié : un nouveau jeton (connexion, code validé) est revérifié. + const [mfa, setMfa] = useState<{ token: string; factor: string | null }>() + // Réseau retrouvé : on revérifie (une session ouverte hors-ligne n'a pas pu l'être) + const [onlineTick, setOnlineTick] = useState(0) + useEffect(() => { + const on = () => setOnlineTick((n) => n + 1) + window.addEventListener('online', on) + return () => window.removeEventListener('online', on) + }, []) const accessToken = session?.accessToken useEffect(() => { - if (!cloudEnabled || !accessToken || sessionAal() === 'aal2' || !navigator.onLine) { - setMfaFactor(null) - return - } + if (!cloudEnabled || !accessToken || sessionAal() === 'aal2' || !navigator.onLine) return let alive = true - // Nouvelle connexion d'un compte peut-être protégé : on attend la vérification avant d'ouvrir l'app - if (knownMfa() !== false) setMfaFactor(undefined) pendingMfaFactor() - .then((f) => alive && setMfaFactor(f)) + .then((factor) => alive && setMfa({ token: accessToken, factor })) // Serveur injoignable : on laisse entrer (la base refuse de toute façon les données sans le code) - .catch(() => alive && setMfaFactor(null)) + .catch(() => alive && setMfa({ token: accessToken, factor: null })) return () => { alive = false } - }, [accessToken]) + }, [accessToken, onlineTick]) + // Calculé au rendu (pas d'effet) : l'app n'est jamais montée, même un instant, avant la vérification. + // undefined = vérification en cours ; comptes connus sans double authentification : on entre tout de suite. + const mfaFactor: string | null | undefined = + !session || sessionAal() === 'aal2' || !navigator.onLine + ? null + : mfa?.token === session.accessToken + ? mfa.factor + : knownMfa() === false + ? null + : undefined const userId = session?.user.id const userEmail = session?.user.email const user = useMemo(() => (userId ? { id: userId, email: userEmail ?? '' } : undefined), [userId, userEmail]) diff --git a/src/components/HomeHero.tsx b/src/components/HomeHero.tsx index c0c8156..781b7e0 100644 --- a/src/components/HomeHero.tsx +++ b/src/components/HomeHero.tsx @@ -51,6 +51,7 @@ function usePlusOne(onOpen: (item: MediaItem, focus?: Completion) => void) { const cap = episodeCap(item) const endsRewatch = !!item.rewatch && !!cap && item.rewatch.episodes + 1 >= cap return incrementEpisode(item.id).then((done) => { + if (done === false) return if (done) onOpen(item, done) else if (endsRewatch) toast.show(t('rewatch.finishedToast', { title: item.title })) }) diff --git a/src/components/title/AddTitle.tsx b/src/components/title/AddTitle.tsx index aa77a2f..65d8e60 100644 --- a/src/components/title/AddTitle.tsx +++ b/src/components/title/AddTitle.tsx @@ -34,14 +34,12 @@ export default function AddTitle({ onOpenItem, onOpenPerson, onManual, - onGoToSettings, }: { onClose: () => void onPick: (r: SearchResult) => void onOpenItem: (item: MediaItem) => void onOpenPerson: (p: PersonHit) => void onManual: (title: string) => void - onGoToSettings?: () => void }) { const { items, settings } = useMedia() const social = useSocial() @@ -217,11 +215,6 @@ export default function AddTitle({ {!hasKey && (tab === 'all' || tab === 'titles' || tab === 'people') && (
{t('search.animeOnly')} - {onGoToSettings && ( - - )}
)} diff --git a/src/components/title/EditDetails.tsx b/src/components/title/EditDetails.tsx index bb898bd..4f6f86b 100644 --- a/src/components/title/EditDetails.tsx +++ b/src/components/title/EditDetails.tsx @@ -40,7 +40,6 @@ export default function EditDetails({ initialTitle?: string onClose: () => void onCreated?: (item: MediaItem) => void - onGoToSettings?: () => void }) { const { items, add, update } = useMedia() useScrollLock() diff --git a/src/components/title/TitleSheet.tsx b/src/components/title/TitleSheet.tsx index 344f26a..0380f20 100644 --- a/src/components/title/TitleSheet.tsx +++ b/src/components/title/TitleSheet.tsx @@ -45,7 +45,6 @@ interface Props { /** Titre trouvé en ligne (pas encore ajouté) */ seed?: SearchResult onClose: () => void - onGoToSettings?: () => void /** Ouvre la page d'un acteur / réalisateur (sa filmographie) */ onOpenPerson?: (p: { id: string; name?: string; photo?: string }) => void /** Ouverte après un +1 qui termine une saison (ou la série) : on amène l'utilisateur à la note */ @@ -58,7 +57,7 @@ interface Props { * Fiche d'un titre, façon Letterboxd : tout se fait ici, et chaque geste est enregistré tout de suite. * Vu / En cours / À voir, note, coup de cœur, avis, épisodes, casting et note moyenne du public. */ -export default function TitleSheet({ item: initial, seed, onClose, onGoToSettings, onOpenPerson, focus: initialFocus, onDone }: Props) { +export default function TitleSheet({ item: initial, seed, onClose, onOpenPerson, focus: initialFocus, onDone }: Props) { const { items, settings, add, update, lists, patchMany } = useMedia() const actions = useLibraryActions() const social = useSocial() @@ -694,7 +693,7 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting }} /> )} - {editing && item && setEditing(false)} onGoToSettings={onGoToSettings} />} + {editing && item && setEditing(false)} />} {preview && setPreview(undefined)} />} void>() function setSession(s: Session | null) { - const changedUser = current?.user.id !== s?.user.id + // Changement de compte, ou nouveau jeton (renouvellement, code de double authentification validé) + const changed = current?.user.id !== s?.user.id || current?.accessToken !== s?.accessToken current = s try { if (s) localStorage.setItem(KEY, JSON.stringify(s)) @@ -66,7 +67,7 @@ function setSession(s: Session | null) { } catch { /* ignore */ } - if (changedUser) for (const fn of listeners) fn(s) + if (changed) for (const fn of listeners) fn(s) } // Connexion / déconnexion dans un autre onglet diff --git a/src/lib/seasons.ts b/src/lib/seasons.ts index 89176e0..1ad5183 100644 --- a/src/lib/seasons.ts +++ b/src/lib/seasons.ts @@ -10,15 +10,15 @@ import { episodeCap, episodesBeforeSeason } from './franchise' /** Série découpée en saisons connues (au moins 2). */ export const hasSeasons = (item: Pick) => (item.seasons?.length ?? 0) >= 2 -/** Moyenne des saisons notées, arrondie à l'étoile entière (valeur stockée sur 10). */ +/** Moyenne des saisons notées, arrondie à la demi-étoile (valeur stockée sur 10). */ export function seasonsAverage(ratings: MediaItem['seasonRatings']): number | undefined { const values = Object.values(ratings ?? {}) .map((r) => r.rating) .filter((v): v is number => typeof v === 'number' && v > 0) if (!values.length) return undefined const avg = values.reduce((a, b) => a + b, 0) / values.length - // Étoiles : une étoile = 2 points sur 10 → on arrondit à l'étoile entière - return Math.max(2, Math.round(avg / 2) * 2) + // Une demi-étoile = 1 point sur 10 + return Math.max(1, Math.round(avg)) } /** Saisons entièrement vues pour un nombre d'épisodes donné (1 = première). */ diff --git a/src/pages/CatalogPage.tsx b/src/pages/CatalogPage.tsx index 51676b8..a2b0544 100644 --- a/src/pages/CatalogPage.tsx +++ b/src/pages/CatalogPage.tsx @@ -133,7 +133,7 @@ export default function CatalogPage({ onOpen, onAdd }: Props) { const io = new IntersectionObserver((e) => e[0]?.isIntersecting && setGridCount((n) => n + GRID_STEP), { rootMargin: '1200px 0px' }) io.observe(el) return () => io.disconnect() - }, [gridCount, results.length]) + }, [gridCount, results.length, view]) const selected = useMemo(() => (selection ? items.filter((i) => selection.has(i.id)) : []), [items, selection]) const allShownSelected = selecting && results.length > 0 && results.every((i) => selection.has(i.id)) diff --git a/src/store.tsx b/src/store.tsx index 503ae50..41abafb 100644 --- a/src/store.tsx +++ b/src/store.tsx @@ -55,7 +55,8 @@ interface MediaStore { update: (id: string, patch: Partial) => Promise remove: (id: string) => Promise /** +1 épisode. Renvoie ce que ça vient de terminer (une saison, ou toute la série), pour proposer de noter. */ - incrementEpisode: (id: string, delta?: number) => Promise + /** false : double tap ignoré */ + incrementEpisode: (id: string, delta?: number) => Promise importItems: (items: MediaItem[], mode: 'merge' | 'replace') => Promise /** Remplace le Top 5 d'une catégorie par ces fiches, dans l'ordre (max 5). */ setTopList: (category: TopCategory, orderedIds: string[]) => Promise @@ -403,9 +404,12 @@ export function MediaProvider({ const lastIncrement = useRef(new Map()) const incrementEpisode = useCallback( async (id: string, delta = 1) => { - const now = Date.now() - if (now - (lastIncrement.current.get(id) ?? 0) < 400) return - lastIncrement.current.set(id, now) + if (delta > 0) { + const now = Date.now() + // false : tap ignoré (rien n'a changé), à ne pas confondre avec « pas de saison terminée » + if (now - (lastIncrement.current.get(id) ?? 0) < 400) return false as const + lastIncrement.current.set(id, now) + } const item = itemsRef.current.find((i) => i.id === id) if (!item) return // Revisionnage : on avance sa propre progression (le premier visionnage ne bouge pas) diff --git a/supabase/migrations/20261128170000_mfa_reads_and_fixes.sql b/supabase/migrations/20261128170000_mfa_reads_and_fixes.sql new file mode 100644 index 0000000..0902bc6 --- /dev/null +++ b/supabase/migrations/20261128170000_mfa_reads_and_fixes.sql @@ -0,0 +1,55 @@ +-- 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 $$;