@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 906d78d
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 20:45 UTC

Preserve read-only module access after license expiry

davoodmehraban89 committed Sep 30, 2026 at 06:33 UTC 906d78d751c7673196044ff55ba5a2224d6ce7ed
2 files changed +31 -19
PROJECT_STATE.md
+19 -19
@@ -21,21 +21,21 @@ Owner explicitly granted standing authority on 2026-09-30 for in-scope GitHub an
21 ## Current change ledger
22 | Date | Request / decision | Status | Evidence / next action |
23 |---|---|---|---|
24 -| 2026-09-30 | Expand Finora into a modular organization-wide ERP: professional office automation, scanned correspondence/attachments, secretariat numbering, configurable requests/forms, module managers and granular read/write/approve/secretariat permissions, modular entry experience, module-by-module commercial licensing/full suite, and future transport/operations modules. Research mature Iranian patterns including Barid/ParGar, Chargoon/Didgah and Faragostar. | **SLICE A IMPLEMENTED / CI VERIFICATION PENDING** | Request recorded at `0b622439`. Research/architecture: `docs/FINORA_MODULAR_ERP_OFFICE_AUTOMATION_V1.md`. Production migrations applied: `20260930025546 modular_entitlements_office_automation_foundation` and `20260930025647 office_secretariat_atomic_registration`; both are archived exactly in this implementation commit. `licenses.modules` supports explicit modules or `full_suite`; existing users are grandfathered to full suite. RLS + atomic sync enforce module entitlement. Private `office-attachments` bucket has owner/module policies. Office slice includes secretariat registries, incoming/outgoing/internal metadata, draft + server-atomic registration number, private PDF/image attachments, archive metadata search and OCR-ready fields. Requests slice includes admin-defined request types/fields and submission. Module launcher and admin license module picker are implemented; unimplemented CRM/transport/manufacturing/maintenance are visible only in architecture/catalog and disabled for sale. Full multi-login organization sharing/module-manager RBAC is deliberately **not claimed** until tenant membership/RLS Slice B. Fresh Quality/Security/Pages required before marking verified. |
25 -| 2026-09-30 | `@GitHub @Supabase`: perform required remaining work without routine permission prompts and finish executable remaining work. | COMPLETED for prior hardening checkpoint | Quality `36661446705` PASS; Security `36661446688` PASS; Pages `36661445458` PASS on prior product checkpoint. |
26 -| 2026-09-30 | Iran-first high-assurance enterprise ERP with accounting/tax/VAT/commerce/labor/social-security controls and enterprise modules. | IN PROGRESS — broader roadmap | Baseline `docs/IRAN_COMPLIANCE_MATRIX_V1.md`; production enterprise migrations through `20260929221754` remain applied and archived. Do not claim statutory consolidation/full tax submission/full HR/CRM until complete lifecycle/accounting/permissions/tests exist. |
24 +| 2026-09-30 | Expand Finora into a modular organization-wide ERP: professional office automation, scanned correspondence/attachments, secretariat numbering, configurable requests/forms, module managers and granular read/write/approve/secretariat permissions, modular entry experience, module-by-module commercial licensing/full suite, and future transport/operations modules. Research mature Iranian patterns including Barid/ParGar, Chargoon/Didgah and Faragostar. | **SLICE A IMPLEMENTED / CI VERIFICATION IN PROGRESS** | Request `0b622439`; implementation `d3934690`. Architecture `docs/FINORA_MODULAR_ERP_OFFICE_AUTOMATION_V1.md`. Production migrations `20260930025546`, `20260930025647`, plus hardening `20260930030314 preserve_readonly_access_after_license_expiry`. The hardening preserves the established expired-license behavior: entitled historical data remains readable while `has_active_license()` continues to gate writes. Production introspection: all 4 existing licenses grandfathered to `full_suite`; 4/4 records policies include module guards; private office bucket and unique correspondence number index exist. Negative DB checks: non-admin module-license RPC denied; unlicensed office write denied. Transactional positive check advanced registry counter 7→8 then rolled back. Quality run `36662546643` has already passed syntax, all accounting/Phase 2–6/Golden gates and the new platform-office invariant gate; Chromium Real-DOM is still running at this state snapshot. Full multi-login organization sharing/module-manager RBAC remains Slice B and is not claimed. |
25 +| 2026-09-30 | `@GitHub @Supabase`: perform required remaining work without routine permission prompts. | COMPLETED for prior hardening checkpoint | Prior Quality `36661446705`, Security `36661446688`, Pages `36661445458` PASS. |
26 +| 2026-09-30 | Iran-first high-assurance enterprise ERP with accounting/tax/VAT/commerce/labor/social-security controls and enterprise modules. | IN PROGRESS — broader roadmap | Baseline `docs/IRAN_COMPLIANCE_MATRIX_V1.md`; do not claim statutory consolidation/full tax submission/full HR/CRM until complete lifecycle/accounting/permissions/tests exist. |
27
28 ## Current production state — 2026-09-30
29 -- Pre-slice repo head: `0b622439fb03b64b029cbc7b0c7987c55160ad0c`; new implementation commit is pending creation/CI in this file version.
29 +- Code implementation head before this hardening archive commit: `d3934690eab066ee61fb65de5226777277818752`.
30 - Supabase `hcsixhqbyuhpshfwqpjx`: `ACTIVE_HEALTHY`, PostgreSQL `17.6.1.166`.
31 -- Applied migrations: 23 through `20260930025647 office_secretariat_atomic_registration`.
32 -- `licenses.modules` exists, default `['full_suite']`; `admin_set_license_modules` exists.
33 -- `records` RLS now includes server module-entitlement checks; `finora_sync_records` rejects unentitled collection writes.
34 -- Office collections allowed: `officeRegistries`, `correspondence`, `correspondenceAttachments`, `correspondenceReferrals`, `correspondenceAudit`.
35 -- Request collections allowed: `requestTypes`, `requests`, `requestActions`.
36 -- Private Storage bucket `office-attachments`: max 20 MB/object; PDF/JPEG/PNG/TIFF; owner + office-module RLS.
37 -- Secretariat registration RPC uses row lock on registry counter plus unique owner/registry/register-number index.
38 -- Performance advisor before this slice: clean. Security advisor before this slice: 6 public SECURITY DEFINER warnings + leaked-password protection disabled. Recheck after CI.
31 +- Applied migrations: 24 through `20260930030314 preserve_readonly_access_after_license_expiry`; all current platform migrations are archived in Git after this commit.
32 +- `licenses.modules` supports explicit modules or `full_suite`; `admin_set_license_modules` validates keys and rechecks admin server-side.
33 +- Record SELECT is owner + purchased-module scoped even after license expiry; INSERT/UPDATE/DELETE and atomic sync additionally require active license.
34 +- Office collections: `officeRegistries`, `correspondence`, `correspondenceAttachments`, `correspondenceReferrals`, `correspondenceAudit`; request collections: `requestTypes`, `requests`, `requestActions`.
35 +- Private `office-attachments`: max 20 MB/object, PDF/JPEG/PNG/TIFF, owner + office-module RLS.
36 +- Secretariat registration RPC uses row lock + unique owner/registry/register-number index.
37 +- Performance advisor after migrations: clean.
38 +- Security advisor after migrations: 7 public authenticated-callable SECURITY DEFINER warnings (the prior six plus `admin_set_license_modules`) + leaked-password protection disabled. The new admin RPC was negative-tested as a non-admin and correctly returned 42501. Do not remove authenticated RPC access merely to silence lint; the client requires the RPC and it has an internal admin authorization check.
39
40 ## Master roadmap status
41 Phases 1–6 remain accepted/completed: UX shell; accounting foundation; double-entry accounting; projects/contracts; inventory/costing/assets/multi-currency/import/integrations; reports/reconciliation/release. Current work is post-release hardening + Iran-first enterprise/platform expansion, not a reset.
@@ -45,6 +45,7 @@ Phases 1–6 remain accepted/completed: UX shell; accounting foundation; double-
45 - Posted vouchers balance and obey fiscal locks; source event/version uniqueness prevents duplicate posting.
46 - Tenant isolation is mandatory at the data boundary; authorization never relies on user-editable metadata.
47 - Commercial module entitlement and member authorization are independent. Effective access is their intersection plus tenant/record scope. UI hiding is never a security boundary.
48 +- Expired/cancelled license keeps entitled historical records readable but cannot write; module removal hides/denies that module's records.
49 - Office registration numbers are allocated server-side atomically; binary scans live in private Storage, not JSON records.
50 - Do not expose/sell roadmap-only modules as operational.
51
@@ -52,17 +53,16 @@ Phases 1–6 remain accepted/completed: UX shell; accounting foundation; double-
53 `docs/PHASE_1_REDESIGN_VERIFICATION.md` · `docs/PHASE_2_REDESIGN_VERIFICATION.md` · `docs/PHASE_3_REDESIGN_VERIFICATION.md` · `docs/PHASE_4_REDESIGN_VERIFICATION.md` · `docs/PHASE_5_VERIFICATION.md` · `docs/PHASE_6_VERIFICATION.md` · `docs/IRAN_COMPLIANCE_MATRIX_V1.md` · `docs/FINORA_ERP_EXPANSION_ROADMAP_V4.md` · `docs/FINORA_UX_ACCOUNTING_BENCHMARK_V3.md` · `docs/FINORA_MODULAR_ERP_OFFICE_AUTOMATION_V1.md` · `docs/PRODUCTION_RUNBOOK.md` · exact SQL under `supabase/migrations/`.
54
55 ## NOT VERIFIED / external boundary
55 -- Multi-login organization membership/module-manager RBAC/shared inbox/referral: NOT YET IMPLEMENTED. Existing business record ownership is still user-owned; Slice B must migrate this securely.
56 +- Multi-login organization membership/module-manager RBAC/shared inbox/referral: NOT YET IMPLEMENTED; Slice B must migrate this securely.
57 - OCR engine accuracy on real Persian scans: NOT VERIFIED; only OCR-ready metadata exists.
58 - Authenticated production-user browser E2E: NOT VERIFIED; no production user credential/session supplied here.
59 - Physical-printer behavior: NOT VERIFIED.
60 - Live third-party webhook/ECE/email gateway delivery: NOT VERIFIED.
60 -- Supabase leaked-password-protection enablement: current platform connector exposes no Auth password-policy mutation.
61 +- Supabase leaked-password-protection enablement: connector exposes no Auth password-policy mutation.
62 - PostgreSQL 17.11 upgrade/reindex: NOT PERFORMED; connector exposes no database-upgrade action.
63
64 ## Exact next executable work
64 -1. Commit this Slice A code/docs/migration archive and run full Quality/Security/Pages, including the new platform-office static check and Chromium test.
65 -2. Recheck production migrations, RLS/storage policies and Supabase advisors; fix any current-head defect before moving on.
66 -3. Slice B: design/migrate organization tenant + memberships + module roles/capabilities + row scopes + confidentiality clearance + immutable permission/referral audit. Only after positive/negative RLS tests may shared secretariat inboxes and module-manager roles be claimed.
67 -4. Slice C: letter templates/editor/signature/approval/referral/read receipts/SLA/reply graph/archive classification/OCR service and quality benchmark/full-text search/integration adapters.
68 -5. Slice D/E: versioned workflow engine, then transport/procurement/service/CRM/manufacturing/maintenance as complete tested vertical modules.
65 +1. Verify the fresh hardening/archive head with Quality/Security/Pages; if Real-DOM finds a defect, fix/retest before progressing.
66 +2. Slice B: organization tenant + memberships + module roles/capabilities + row scopes + confidentiality clearance + immutable permission/referral audit. Only after positive/negative RLS tests may shared secretariat inboxes and module-manager roles be claimed.
67 +3. Slice C: letter templates/editor/signature/approval/referral/read receipts/SLA/reply graph/archive classification/OCR service and Persian quality benchmark/full-text search/integration adapters.
68 +4. Slice D/E: versioned workflow engine, then transport/procurement/service/CRM/manufacturing/maintenance as complete tested vertical modules.
supabase/migrations/20260930030314_preserve_readonly_access_after_license_expiry.sql new
+12
@@ -0,0 +1,12 @@
1 +create or replace function private.has_module_entitlement(module_key text)
2 +returns boolean
3 +language sql stable security definer set search_path = '' as $$
4 + select case
5 + when module_key = 'core' then true
6 + else exists (
7 + select 1 from public.licenses l
8 + where l.user_id = (select auth.uid())
9 + and ('full_suite' = any(l.modules) or module_key = any(l.modules))
10 + )
11 + end
12 +$$;
\ No newline at end of file