سامانه صدور فاکتور و حسابداری
Plan Office Slice C4 versioned templates
davoodmehraban89 committed
Sep 30, 2026 at 23:54 UTC
97a094b85c0ba63faa32e3438e79ef5a2adba0c6
1 file changed
+36
docs/superpowers/plans/2026-09-30-office-slice-c4-versioned-templates.md
new
+36
@@ -0,0 +1,36 @@
1
+# Office Slice C4 — Versioned Correspondence Templates + Controlled Draft Application Plan
2
+
3
+Date: 2026-09-30
4
+
5
+**Goal:** Add reusable, versioned correspondence templates and a controlled draft editor/application flow while preserving immutable registered history and template provenance.
6
+
7
+## Prerequisite defect found during pre-flight
8
+The live `office_register_correspondence` function still inserts into `public.records` without the mandatory `organization_id` introduced by tenant migration. With no persistent office registry/correspondence data, this escaped browser/static gates. C4 must first repair registration to be organization-aware; otherwise template provenance cannot be safely carried into registered letters.
9
+
10
+## Scope
11
+- Repair atomic registration so registry and correspondence are bound to the caller's active organization and current record-level authorization.
12
+- Add `correspondenceTemplates` as an Office collection.
13
+- Templates are append-only versions keyed by stable `templateKey`; editing creates a new version rather than mutating history.
14
+- Server creates versions atomically and enforces configure permission.
15
+- Server lists/reads only templates in an organization the caller can access.
16
+- Applying a template only populates a draft/new-letter editor; it never rewrites a registered letter.
17
+- Draft/registered correspondence stores `templateKey` + `templateVersion` provenance when a template is applied.
18
+- Registration validates any supplied template reference server-side before persisting it.
19
+- UI adds a template-management surface and template selector/application in new correspondence.
20
+
21
+## Security / history invariants
22
+1. Registration never inserts a tenantless record.
23
+2. Registry must belong to the caller's active organization and be writable under Office authorization.
24
+3. Template creation requires `office_automation/configure`; reading/application requires Office read access.
25
+4. Template versions are immutable and monotonically increasing per organization + template key.
26
+5. A registered letter can reference only an existing template version in the same organization.
27
+6. Template application cannot modify registered correspondence.
28
+7. Existing accounting/Golden, ELI-1/2/3/4 and Office C1/C2/C3 gates remain green.
29
+
30
+## Delivery
31
+- [ ] RED: add registration tenant regression + C4 invariant/Real-DOM tests and observe failure.
32
+- [ ] GREEN: apply/archive registration repair + template/version RPC migration.
33
+- [ ] Run transactional production adversarial tests and rollback fixtures.
34
+- [ ] Implement template manager + draft application/provenance UI.
35
+- [ ] Run full Quality/Real-DOM/Security/Pages.
36
+- [ ] Write `docs/OFFICE_SLICE_C4_VERIFICATION.md`, update gap register and `PROJECT_STATE.md`.