سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 20:45 UTC
Plan Office Slice C1 registered history and read evidence
davoodmehraban89 committed
Sep 30, 2026 at 09:11 UTC
59ebb658a4f284b3d0137bb2289ab8829a4bd381
1 file changed
+86
docs/superpowers/plans/2026-09-30-office-slice-c1-registered-history-read-evidence.md
new
+86
@@ -0,0 +1,86 @@
1
+# Office Slice C1 — Registered History + Read Evidence Implementation Plan
2
+
3
+> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
+
5
+**Goal:** Harden registered correspondence history and add server-authoritative read evidence without claiming OCR, qualified signatures or external delivery.
6
+
7
+**Architecture:** Keep correspondence in the existing tenant-aware `records` store. Add database guards that make registration identity/history immutable after registration while allowing separately authorized operational fields to evolve. Record read evidence as organization-scoped audit events through a dedicated RPC so clients cannot forge another user's read event. Build the UI as a focused extension over the existing office view rather than rewriting the office module.
8
+
9
+**Tech Stack:** PostgreSQL/Supabase RLS + PL/pgSQL, vanilla JavaScript, Playwright Real-DOM, GitHub Actions.
10
+
11
+**Spec:** `docs/FINORA_MODULAR_ERP_OFFICE_AUTOMATION_V1.md`
12
+
13
+## Global Constraints
14
+- Effective access remains commercial entitlement ∩ member permission ∩ tenant/record scope/confidentiality.
15
+- Registered correspondence registration identity (`organization_id`, `id`, `registryId`, `registerNumber`, `registeredAt`) is immutable.
16
+- UI visibility is not security; server functions/RLS/triggers are authoritative.
17
+- No claim of OCR accuracy, qualified digital signature, external email/ECE delivery or physical printing.
18
+- Existing accounting/Golden and ELI-1/2/3/4 gates must remain green.
19
+
20
+## Review Focus
21
+- Direct generic record update must not rewrite registration identity.
22
+- Direct delete of registered correspondence must be rejected.
23
+- Read evidence must always identify the authenticated reader, never a caller-supplied user id.
24
+- A user without office read permission must not create/read evidence for an inaccessible letter.
25
+- Existing legacy registered correspondence must remain readable and must not be rewritten by migration.
26
+
27
+---
28
+
29
+### Task 1: Registration-history immutability
30
+
31
+**Files:**
32
+- Create: `supabase/migrations/<production-version>_office_registered_history_hardening.sql`
33
+- Create: `scripts/office-slice-c1-check.mjs`
34
+- Modify: `.github/workflows/quality.yml`
35
+
36
+**Interfaces:**
37
+- Consumes: `public.records`, `private.can_access_record`, existing `office_register_correspondence`.
38
+- Produces: trigger `private.protect_registered_correspondence_history()`.
39
+
40
+- [ ] Write failing invariant/adversarial tests for protected-field update and registered-row delete.
41
+- [ ] Verify RED against current production/repository behavior.
42
+- [ ] Add trigger that rejects protected registration identity changes and deletion when `collection='correspondence'` and old status is `registered` or later.
43
+- [ ] Preserve allowed operational edits without weakening record RLS.
44
+- [ ] Run repository + transactional production tests; archive exact migration version.
45
+
46
+### Task 2: Server-authoritative read evidence
47
+
48
+**Files:**
49
+- Modify same C1 migration or add one follow-up migration if production apply already occurred.
50
+- Modify: `scripts/office-slice-c1-check.mjs`
51
+
52
+**Interfaces:**
53
+- Produces: `public.office_mark_correspondence_read(p_organization_id uuid,p_correspondence_id text) returns text`.
54
+- Persists append-only `correspondenceAudit` event with authenticated user, event `read`, correspondence id and server timestamp.
55
+
56
+- [ ] Write failing tests for authorized read, unauthorized read, forged-user impossibility and immutable evidence.
57
+- [ ] Implement RPC with office entitlement + record-level read check.
58
+- [ ] Make read evidence append-only and auditable.
59
+- [ ] Verify rollback adversarial scenarios in Production.
60
+
61
+### Task 3: Office UI read-evidence integration
62
+
63
+**Files:**
64
+- Create: `js/office-mature.js`
65
+- Modify: `js/bootstrap.js`
66
+- Create: `scripts/office-slice-c1.spec.js`
67
+- Modify: `.github/workflows/quality.yml`
68
+
69
+**Interfaces:**
70
+- Consumes: `office_mark_correspondence_read`.
71
+- Produces: detail/open path that records a read event only after the letter is successfully visible to the user; exposes read-evidence timeline where authorized.
72
+
73
+- [ ] Commit failing Real-DOM coverage first.
74
+- [ ] Implement minimal extension without duplicating the office module.
75
+- [ ] Verify Real-DOM + all existing accounting/ELI gates.
76
+
77
+### Task 4: Evidence and continuity
78
+
79
+**Files:**
80
+- Create: `docs/OFFICE_SLICE_C1_VERIFICATION.md`
81
+- Modify: `PROJECT_STATE.md`
82
+- Modify: `docs/CURRENT_STAGE_GAP_REGISTER_2026-09-30.md`
83
+
84
+- [ ] Record exact production migration, transactional adversarial results and CI run IDs.
85
+- [ ] Mark only C1 registration-history/read-evidence scope complete; keep templates/signatures/SLA/OCR/adapters as open Slice C work.
86
+- [ ] Keep external/provider and two-real-user persistent-production boundaries explicit.