← Back to Pull requests

feat(social): archive posts and restore them (#1299) #1328

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 24, 2026 12:30 UTC
Author

Archived posts and their restore (#1299), as Planable archives a post and restores it.

Protected path: this PR adds a migration (supabase/migrations/20261030020000_crove_social_post_archive.sql, columns only). The coordinator runs the independent security review.

What changed

  • Migration (columns only): crove_social.post.archived_at timestamptz, archived_by uuid, CHECK post_archived_pair (both or neither), partial index post_live_idx (org_id, updated_at DESC, id DESC) WHERE archived_at IS NULL. Grants unchanged: crove_tenant keeps table-level UPDATE on post, as for every other post column. packages/db types regenerated.

  • - Decision: no foreign key on archived_by. No _by column of the Social tables has one (author, assignee, removed_by, revoked_by, created_by are plain uuids kept when the person leaves). An FK to crove_kernel.tenant_member would either delete the post with the membership (CASCADE) or break the pair CHECK (SET NULL). This also keeps the migration free of a cross-module waiver.
  • Commands (modules/social/src/archive.ts): social.post.archive, social.post.restore (R1; members their own posts, owners and admins any; a member limited to some channels only a post wholly on theirs, #1081), and social.post.bulk_archive / social.post.bulk_restore (up to 100, posts locked in id order, the single command run as a nested command per post, outcomes not_found, not_allowed, unchanged, scheduled, in_flight, removing). New contract routes posts.archive, restore, bulkArchive, bulkRestore; posts.list takes archived: true; PostView carries archivedAt/archivedBy.

  • Refusals: POST_ARCHIVE_SCHEDULED (scheduled or paused), POST_ARCHIVE_IN_FLIGHT (publishing, processing, ambiguous, needs_attention), POST_ARCHIVE_REMOVING (a takedown asked and not answered, or a planned takedown the sweep will still ask for, #860/#861).

  • Archiving turns off evergreen and the repeat (a restore leaves them off) and revokes the post's open review links, its own and every plan link that includes it (#902). Restore clears the two columns only: status, channels, labels, queue slots and updated_at stay as they were. Both are audited and show on the post's timeline (archived/unarchived; a call that changed nothing is audited but left off the timeline).

  • Archived posts are left out of: postFilterQuery (lists, board, calendar, undated list, multi-client home figures), the upcoming count, review inbox, attention inbox, plan export, plan links from a date range, digest review and failure lists. Review reminders for an archived post are marked as sent without telling anyone, so the oldest-first reminder scan does not stall on it. Evergreen and recurring sweeps never find them (the rule is cleared, and the worker commands re-check under the lock).

  • Refused on an archived post with 409 POST_ARCHIVED: post and variant edits, add channels, restore version, submit, decide, schedule, reschedule, retry, review link create (and plan create with an archived post), set evergreen (turning it off still works), set recurrence, set text variations. Labels, comments and copies still work.

  • Kept: published archived posts stay in metrics, reports, the team report and the duplicate-text check (they describe what went out).

  • UI: Lưu trữ on the post page (disabled with the reason when blocked) and a notice with Khôi phục on an archived post; Lưu trữ in the bulk bar of the Review, Attention, Drafts and Done lists and the board; a new Đã lưu trữ tab with Khôi phục* in its bulk bar. vi/en copy, SPA wording for the new error codes.

  • docs/plan/social.md: one paragraph.
  • Not in this PR

  • The calendar feed's public definer (#862) still lists published archived posts; changing it is a definer change, outside "columns only". Follow-up: #1327 (Icebox, P3).

  • Archived drafts keep their queue slots (a restore must give the post back unchanged), so a slot held by an archived draft stays taken; social.queue.set still moves it like any queued draft.
  • Tests

  • New apps/kernel/test/social-archive.db.test.ts (PostgreSQL 17, 9 tests): every list and filter leaves archived posts out and archived: true lists them; restore returns social.post.get unchanged; roles (author, other member, viewer, admin, owner, other org); channel scope (single and bulk not_allowed); each refusal (scheduled, paused, publishing, processing, ambiguous, needs_attention, takedown asked, takedown planned) single and bulk; bulk outcomes in id order with audits; evergreen and recurrence cleared and evergreen_due/recurring_due skip the post, worker commands no-op, set refused; single and plan review links revoked (others untouched), new links refused, range plans skip it; the refused commands; inboxes, plan export, overview figures, reminders (marked, no event) exclude it while metrics keep the published one.

  • Related DB suites re-run green locally after merging main: evergreen, recurring, reminders, inbox, attention, plan review, bulk edit, channel access, clients-social, social-posts, report links, text variations, activity, check-unions. Full DB suite: all tests passed; 10 files hit hook timeouts under load and passed on re-run.

  • New apps/app/test/social-archive.test.ts and a BulkBar case in social-bulk-bar.test.tsx; app, social module and contract unit tests green; pnpm typecheck, pnpm lint, pnpm docs:check green.

  • node tools/ci/migration-order.mjs origin/main and migration-lint --since $(git merge-base HEAD origin/main) OK.

  • Local Windows-only failures ignored as known: route-coverage, status-page, invariant-summary. e2e not run locally (shared Docker disk is full); CI covers it.
  • Closes #1299

    🤖 Generated with Claude Code

    ---

    <!-- dos-pr-summary -->

    📌 TL;DR


    This PR introduces a "Soft Archive" feature for social media posts, allowing users to hide posts from all active lists (calendar, board, drafts) without deleting them. It includes single-post and bulk archive/restore actions, permission checks, state-based blocking rules (e.g., preventing archiving of scheduled or in-flight posts), and a new "Archived" tab in the UI.

    🎯 Type of Change


  • 🚀 New feature

  • 🐛 Bugfix

  • 🧹 Refactor

  • ⚡ Performance

  • 📚 Documentation

  • ⚙️ CI / Configuration
  • 🔍 Changes Walkthrough


    | File | Summary of Changes |
    | :--- | :--- |
    | apps/app/src/lib/social-archive.ts | New file. Defines client-side logic for archive permissions (mayArchive) and blocking rules (archiveBlock) based on post variant statuses (e.g., publishing, scheduled). |
    | apps/app/src/lib/social-bulk.ts | Adds ArchiveAction type ('archive' \| 'restore') and updates BulkAction and PostAction types to include archive operations. |
    | apps/app/src/lib/social.ts | Adds 'archived' to the SOCIAL_TABS constant to enable the new tab in the UI routing. |
    | apps/app/src/lib/kernel-errors.ts | Registers new error codes: POST_ARCHIVED, POST_ARCHIVE_IN_FLIGHT, POST_ARCHIVE_SCHEDULED, and POST_ARCHIVE_REMOVING. |
    | apps/app/src/components/social-bulk.tsx | Integrates archive/restore into the bulk action bar. Adds confirmation dialogs, progress tracking, and result display for bulk archive/restore operations. |
    | apps/app/src/routes/social-post.tsx | Adds "Archive" and "Restore" buttons to the single post view. Implements read-only mode for archived posts and displays a warning banner with restore options. |
    | apps/app/src/routes/social.tsx | Adds the "Archived" tab to the social home page. Configures bulk actions to show "Restore" on the archived tab and "Archive" on other tabs. Filters list queries to include/exclude archived posts based on the active tab. |
    | apps/app/src/i18n/messages/en.ts | Adds English translations for archive actions, confirmations, error messages, and the new "Archived" tab. |
    | apps/app/src/i18n/messages/vi.ts | Adds Vietnamese translations for archive actions, confirmations, error messages, and the new "Archived" tab. |
    | apps/kernel/src/rpc.ts | Exposes new RPC handlers for archive, restore, bulkArchive, and bulkRestore commands. |
    | apps/app/test/social-archive.test.ts | New file. Unit tests for client-side archive logic (permissions, blocking rules) and tab configuration. |
    | apps/app/test/social-bulk-bar.test.tsx | Updates bulk bar tests to verify archive/restore buttons appear correctly in different contexts. |
    | apps/kernel/test/social-archive.db.test.ts | New file. Integration tests for the database layer, verifying archive/restore behavior, permissions, state blocking, and list filtering. |

    📊 Architectural Flow


    sequenceDiagram
        participant UI as Social UI (Post/Bulk)
        participant Client as Client Logic (social-archive.ts)
        participant RPC as Kernel RPC
        participant DB as Database
    
        Note over UI,DB: Archive Flow
        UI->>Client: Check mayArchive(role, post)
        Client-->>UI: Permission Granted
        UI->>Client: Check archiveBlock(variants)
        Client-->>UI: No Block (or Block Reason)
        UI->>UI: Show Confirmation Dialog
        UI->>RPC: Call social.post.archive / bulkArchive
        RPC->>DB: Update post.archived_at, archived_by
        DB-->>RPC: Success
        RPC-->>UI: ArchiveResult
        UI->>UI: Refresh List (Exclude Archived)
    
        Note over UI,DB: Restore Flow
        UI->>RPC: Call social.post.restore / bulkRestore
        RPC->>DB: Clear post.archived_at, archived_by
        DB-->>RPC: Success
        RPC-->>UI: ArchiveResult
        UI->>UI: Refresh List (Include Restored)
    

    <!-- /dos-pr-summary -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: claude[bot] Review duration: 17m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1328"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%
    Repository