سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 17:00 UTC
fix/wave2-request-input-integrity
Slice B — Organization Tenant + RBAC Verification
Date: 2026-09-30
Status: implementation complete; PR CI is the release gate.
Delivered boundary
Finora now separates four authorization dimensions that must all allow an operation:
- Organization membership —
organizations,organization_units,organization_members. - Commercial entitlement — the organization's existing license and module list.
- Member authorization —
member_module_permissionswithread/create/edit/delete/approve/register/refer/archive/configure. - Record boundary —
own/unit/branch/company/organizationscope plus confidentiality clearance 0..3.
Existing accounts were migrated conservatively: every existing license received an isolated organization, the license owner became that organization's owner, and every existing records row was backfilled to the matching organization without rewriting posted accounting payloads. The record primary key is now (organization_id, collection, id) while owner_id remains the creator/own-scope identity.
Production migrations
20260930031853_organization_membership_rbac_foundation20260930031942_office_shared_rbac_and_referrals20260930032615_slice_b_rbac_fk_indexes20260930032654_harden_legacy_office_storage_member_writes20260930033010_allow_member_core_read_context
Exact applied SQL is archived under supabase/migrations/.
Server enforcement
records SELECT/INSERT/UPDATE/DELETE policies now evaluate organization membership, organization license/module entitlement, capability, row scope and confidentiality. Writes additionally require an active organization license. Expired/cancelled organizations retain authorized historical reads.
finora_sync_records accepts an explicit p_organization_id; it refuses organizations outside the caller's memberships and refuses inactive-license writes. The client pulls only the selected organization.
Organization owners have implicit full member authorization inside commercially entitled modules. Non-owner members receive explicit module permissions. A module manager with configure can assign permissions for that module but cannot turn on a commercially unlicensed module. Active members receive read-only access to the selected organization's core context (for example company/settings context) so a non-owner workspace can initialize; core writes remain owner-only unless a future explicit core-administration model is introduced.
Office automation
office_register_correspondenceis organization-aware and requires active office entitlement +registercapability.office_refer_correspondencerequires active office entitlement +refercapability and only targets active members of the same organization.- Referral records are immutable after insertion.
- Permission changes and referrals write
organization_audit; audit rows are immutable. - New attachment paths are
<organization>/<uploader>/<correspondence>/<file>and Storage access resolves back to correspondence RLS/confidentiality. - Legacy UID-prefixed attachment reads remain available for historical compatibility. Legacy-path writes are restricted to organization owners with active office entitlement; ordinary members must use the organization-aware path.
Client behavior
js/organization-rbac.js loads organization memberships, selected organization, organization license and member permissions before app entry. Non-owner module navigation is derived from both commercial entitlement and member read capability. Organization-aware sync includes p_organization_id.
js/organization-shell.js restores organization controls after the module rail is rebuilt. Multi-organization users get an explicit organization switcher; owners/module-configurers get the access-management entry point.
The organization access surface lets an organization owner add an already-registered Finora user by email and lets owners/module-configurers assign capability, scope and confidentiality. External invitation/email onboarding is intentionally not claimed yet.
js/office-rbac.js gates registry configuration, draft creation, registration and referral by capability and uses organization-aware attachment paths. Authorized office users see the shared records returned by server RLS; referral is exposed only to members with refer.
Database verification executed in production transactions and rolled back
- own-scope member could not see another user's organization record;
- organization-scope
readexposed normal correspondence but not correspondence above confidentiality clearance; - increasing clearance exposed the confidential record;
- read-only member updated 0 rows;
- active non-owner member could read organization
corecontext and updated 0 core rows; - cancelled-license organization owner could read historical correspondence and updated 0 rows;
- referral RPC succeeded for a member with
read+referin organization scope; - non-configure member could not read organization audit;
- referral mutation hit the immutable trigger (
42501); - organization-audit mutation hit the immutable trigger (
42501); - non-owner member with office
createcould use the organization-aware Storage path but not the legacy UID-prefixed write path.
All test data was inside transactions and rolled back.
Advisor review
Security advisor after Slice B reports the same seven reviewed public SECURITY DEFINER warnings from the pre-existing admin/license helper set plus leaked-password protection disabled; Slice B introduced no new exposed SECURITY DEFINER RPC warning. Performance advisor initially identified four unindexed new foreign keys; migration 20260930032615 added the covering indexes. The remaining performance findings are only newly-unused-index informational notices immediately after creation.
Still not claimed
- invitation of a person who does not yet have a Finora account;
- SSO/SCIM/enterprise identity provisioning;
- real Persian OCR accuracy;
- qualified digital signature / certificate validation;
- external ECE/email/webhook gateways;
- full visual workflow designer, delegation/substitution and SLA escalation;
- authenticated multi-device production browser E2E with two real user sessions (server RLS was tested by authenticated-role simulation).