Repository navigation
feat(content): archive, delete and set a status from the Library's rows - #1328
Conversation
Each Library row gets a menu: its status (In progress · In review · Ready · Published; Ready goes through Mark ready, keeping a History version and completing the draft's task) and, for admins and managers, Send to Archive (with Undo) or Restore, and Delete behind a confirmation. An Archived tab holds archived drafts, which keep their status and leave the other tabs, the Plan and the MCP list. Created and Updated replace the AEO score column, and "Draft" reads "In progress". Migration 00233 adds content_drafts.archived_at/archived_by, a trigger letting only admins and managers archive, and a manager delete policy (drafts had none). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk These are the user's Library row actions: a status menu, archive and restore, delete, and Created/Updated columns instead of the AEO score. Migration
Checked on the dev DB:
Web checks: 2,493 tests and the build pass. Checked in light and dark, and at 1024 px with no overflow. |
gkhngyk
left a comment
There was a problem hiding this comment.
A few fixes before merge:
supabase/migrations/00233_content_drafts_archive.sql:60-61: the guard runsbefore updateonly.content_drafts: member insertlets any member insert a draft witharchived_atalready set andarchived_byset to anyone, an admin for example. Soarchived_byis trusted from the app on insert after all, and the admin-or-manager rule doesn't hold for new rows. Run the triggerbefore insert or update. On insert, unless the role bypasses RLS, raise42501when either column is non-null, asguard_content_draft_server_columnsdoes for its columns. Folding both columns into that guard's insert branch also works.web/src/lib/actions/content-drafts.ts:477-487:readActionDraftsstill returns archived drafts. The Action Center drawer lists them, and a task's Start reopens an archived draft (startDraftFromAction→findActionDraft,:575). If archived means set aside, as on the Plan and in MCP, filter onarchived_at is nullhere too, or label them as archived in the drawer.web/src/lib/content/drafts.ts:243:aeoScoreTextand its test, plusscoreBefore/scoreAfteronContentDraftListItemand in the select atcontent-drafts.ts:143, are unused now that the column is gone. Remove them.
Checked on prod: only content_draft_versions, content_draft_sources and content_draft_suggestions (cascade) and prompt_improve_usage (set null) reference content_drafts. Referential actions run as the table owner, so child-table RLS doesn't block the cascade. The delete policy is limited to admins and managers of the brand's organization. Apply 00233 before this merges: the Library and the MCP list select archived_at.
…-actions # Conflicts: # supabase/schema.sql
…of the Action Center - 00233: guard_content_draft_archive runs before insert or update. A member's new draft with archived_at or archived_by set is refused (42501), so archived_by is never the app's word; the server, which bypasses RLS, is unaffected. - readActionDrafts skips archived drafts: the Action Center drawer doesn't list them, and a task's Start writes a new draft instead of reopening one. - Remove aeoScoreText and the list's scoreBefore/scoreAfter, unused since the AEO Score column went. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk Thanks, all three are in
Web: 2,505 tests, lint, tsc, Prettier and the build pass. Archive and Restore still work from the Library in the browser. As you noted, 00233 needs to be on the hosted database before this merges, and #1329 follows it with |
gkhngyk
left a comment
There was a problem hiding this comment.
One fix before merge. The three earlier findings are done in c11162d9:
- 00233's guard runs
before insert or update. Any role that doesn't bypass RLS gets 42501 when it inserts a draft witharchived_atorarchived_byset. readActionDraftsskips archived drafts.aeoScoreText, its test, andscoreBefore/scoreAfterare gone. The Library select no longer readsscore_before/score_after.
The merge of main (a9897ff7) only resolves schema.sql. Re-merging its parents gives the same tree in every other file.
-
Start fails for good once an action's draft is archived.
web/src/lib/actions/content-drafts.ts:487now leaves archived drafts out ofreadActionDrafts. SostartDraftFromAction(:575) doesn't find the archived draft, imports the page, and inserts a new one. That insert hits 00218'scontent_drafts_action_work_key, which is unique on(action_id, method, md5(source_url))for every row, archived ones included. The 23505 retry (:656) reads through the same filter, finds no winner, and throws, so the task's Start button returnsfaileduntil someone restores the draft, and the page import is wasted on every click. Pick one:- (preferred, matches the commit message) In 00233 (not on prod yet), recreate the index as
where action_id is not null and archived_at is null. Restore can then hit 23505 when a newer draft exists for the same work, soarchiveContentDraftshould map that to its own error and the Library should show a toast for it. - Or keep archived drafts in the lookup Start uses: give
readActionDraftsanincludeArchivedflag, and passtruefromstartDraftFromAction, both for the first lookup and for the 23505 retry. Only the drawer (getActionDrafts) would filter them out, so Start reopens the archived draft.
Either way, add a test in
content-drafts-start.test.tsfor an action whose matching draft is archived. - (preferred, matches the commit message) In 00233 (not on prod yet), recreate the index as
Merge notes
- Merges cleanly on current main. It contains no other open PR.
- It conflicts with #1321, and so with #1329, #1334 and #1337, which all carry #1321. The conflicts are only in
content/library/page.test.tsxandlib/actions/content-plan.test.ts, both mock setup, and the fix is to keep both sides. With #1329 it also conflicts inschema.sql. - 00233 isn't on prod yet (no
archived_atcolumn). Apply it before this merges: the Library, the Plan and the MCP list all filter onarchived_at.
…-actions # Conflicts: # web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx # web/src/lib/actions/content-plan.test.ts
…chived 00218's content_drafts_action_work_key counted archived drafts too, so a task whose draft was archived could never start again: readActionDrafts skips the archived one, the insert hit the key, and the 23505 retry found no winner. 00233 recreates the key over drafts not archived. Restoring the archived one while a newer draft does the same work is refused (23505), named newer_draft, and the Library says what to do. getOpportunityDrafts (from ansvisor#1334, now on main) skips archived drafts too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk Thanks. Your preferred fix is in
Web: 2,614 tests, lint, tsc, Prettier and the build pass. As before, 00233 needs to be on prod before this merges. The index swap there is a plain drop/create on |
gkhngyk
left a comment
There was a problem hiding this comment.
The round-6 item is fixed. 00233 now scopes content_drafts_action_work_key to drafts that aren't archived. A restore that collides with a newer draft returns newer_draft, with its own Library toast, and both paths have tests. getOpportunityDrafts filters archived drafts too.
One thing before merge: #1333 is landing now, and its getDraftForPrompt (web/src/lib/actions/content-drafts.ts) doesn't filter archived drafts yet. Please merge main in once it's there, then add:
.is('archived_at', null)to that query;- the matching filter assertion in
content-drafts-start.test.ts.
After that I'll apply 00233 and merge.
getDraftForPrompt (ansvisor#1333) skips archived drafts, as getOpportunityDrafts does, so Start opens the work in hand, never one sent to the Archive. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk merged main in once #1333 landed (d430e75), then cae03ce:
|
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. The open item is fixed in cae03cee:
getDraftForPromptnow skips archived drafts with.is('archived_at', null)(web/src/lib/actions/content-drafts.ts:359-360).content-drafts-start.test.ts:273checks that filter.
The merge of main (d430e75b) re-merges to exactly the same tree, so it carries no hidden changes. schema.sql matches build-schema.sh. Since the last review, the only other main change that reads content_drafts is the Content Agent's writer (#1351). It works on one draft by id, so it needs no archive filter.
Merge notes
- It merges cleanly on current main (
a08cbc68) and contains no other open PR. It also merges cleanly with #1312 and #1358. - 00233 isn't on prod yet: there is no
archived_atcolumn, no guard function or trigger, no delete policy, and the work key is still 00218's. I'll apply it, then merge.
00233 is applied on production: both columns, the guard trigger, the work key limited to drafts not archived, and the manager delete policy. Tested on top of main together with #1358: web and server tests, tsc, lint and Prettier pass, and schema.sql matches a rebuild.
Summary
From the user's review of the Library: rows need archive and delete, a "…" menu to set the status (In review, In progress, Ready, Published, Send to Archive), and Created and Updated dates instead of the AEO score column, which always read "—".
Library (
content/library)markContentDraftReady, the editor's Mark ready, so it keeps a History version and completes the draft's Action Center task. The others go through the newsetContentDraftStatus.xl(320 px fromxlup).contentEditor.status.draftand the tab). It's a label only; the stored status staysdraft.Migration
00233_content_drafts_archive.sqlcontent_drafts.archived_at/archived_by. Archive is deliberately not a fifth status, so the Agent API, MCP schemas and the editor keep reading the four statuses unchanged.guard_content_draft_archivetrigger. Only an admin or manager of the brand's organization, or the server, can set or cleararchived_at.archived_byis set by the trigger rather than trusted from the app.content_drafts: manager deletepolicy. The table had no delete policy, so nobody could delete a draft before. On delete, the draft's versions, sources and suggestions go too (cascade). Improve usage keeps its row (set null), and the Action Center task it was sent as stays.Archived drafts are set aside elsewhere too:
getContentPlan);list_content_draftstool skips them.Checked on the dev DB:
archived_by, restore clears it, and delete works.42501 only admins and managers archive content drafts.Related issue
None. Product feedback from the user.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Apply
00233first.Checked in light and dark, at 1024 px and wider.
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)yarn test: 281 files, 2,493 tests pass.yarn buildpasses with CI's placeholders.bash supabase/build-schema.shwas run.🤖 Generated with Claude Code