# Task 5 Report — Ownership articoli in API posts + assegnazione autore ## Implementazione File creati/modificati esattamente come da brief: - `src/lib/posts.ts` (modificato): aggiunta `canModifyPost(role, userId, post)` — admin/superuser sempre true, altrimenti `post.author_id === userId`. - `src/pages/api/admin/posts/index.ts` (modificato): `POST` legge `locals` e passa `author_id: locals.user!.id` a `createPost`. - `src/pages/api/admin/posts/[id].ts` (modificato): `PUT`/`DELETE` caricano il post esistente, 404 se assente, 403 se `canModifyPost` è false. - `tests/posts-ownership.test.ts` (nuovo): copiato verbatim dal brief. ## TDD evidence **RED** — `npm test -- tests/posts-ownership.test.ts` prima dell'implementazione: ``` TypeError: canModifyPost is not a function ``` **GREEN** — dopo implementazione di `canModifyPost`: ``` Test Files 1 passed (1) Tests 2 passed (2) ``` **Full suite** — `npm run build` + `npm test`: ``` build: Complete! Test Files 12 passed (12) Tests 60 passed (60) ``` ## Concerns Nessuno bloccante. ## Commit ``` c3267c9 feat(posts-api): assegna autore in POST, ownership su PUT/DELETE 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 tests/posts-ownership.test.ts ``` **Status**: COMPLETATO