Skip to content

TEN · Tenancy

An organization is the tenant. It has legal entities (TOP, MOP), which sign contracts and receive money, and pools (Pamulang…), where cars and drivers belong. Code TEN.

  • DOC-Q2 (which time zones): a new rule, R-TEN-16: a pool's time zone is one of Indonesia's four.
  • DOC-Q6 (global tables): R-TEN-01 now names its exceptions as [Ref] Data model V13 lists them. profiles and permissions are global, with no organization. This makes the wording exact; the rule's meaning is unchanged.
  • DOC-Q11 (who reads an organization's row): its members. A new rule, R-TEN-17.
  • System rows after the copy (#149): each organization's copies stay locked (R-MD-05, R-ACC-21), and R-TEN-01's list of tables whose organization may be empty goes. Written in #164.
  • Legal entities and pools on the master data page (#459, zuki and the lead, 2026-11-17): they are written only through database functions that raise D10 keys (R-TEN-18). A holder of master_data:write adds them (R-TEN-12). A code is set once, in upper-case letters, and so is a pool's time zone (R-TEN-19 to R-TEN-21). They are retired and restored, never deleted (R-TEN-13, R-TEN-23, R-TEN-24), and retiring is refused while the row is in use or is the last active one (R-TEN-25 to R-TEN-27). The organization row, subscriptions and divisions stay out of the page.

R-TEN-01 · Every row belongs to one organization, except in the tables the data model names

Section titled “R-TEN-01 · Every row belongs to one organization, except in the tables the data model names”
  • Status: built

  • Example: given a new vehicles row, when it is saved without organization_id, then it is refused. Given a new permissions row, it has no organization_id column at all.

  • Refusal: none: not_null_violation (23502).

  • Who: every writer.

  • Source: [Ref] Data model V13, the columns left out of every table. The exceptions:

    • Global, no organization: organizations, profiles (a person may work for several organizations) and permissions (one catalogue for every tenant).
    • Belong through their parent: pool_settings, role_permissions and member_rental_companies.

    The system lookups (roles, charge_types, lead_sources, inspection_item_types and body_panels) are not an exception: each organization holds its own copies, with its organization_id (R-TEN-03). #164 dropped "organization may be empty for system rows".

R-TEN-02 · A user sees no row of an organization they aren't a member of

Section titled “R-TEN-02 · A user sees no row of an organization they aren't a member of”
  • Status: built
  • Example: given Deka, an admin of organization A only, when Deka reads vehicles, then no car of organization B comes back.
  • Refusal: none: hidden.
  • Who: every signed-in user, whatever their roles.
  • Source: [Ref] Roles, permissions and row-level security; the M0 acceptance checks.

R-TEN-03 · Every row belongs to an organization: each organization gets its own copy of the system lookups, and only the permission catalogue is shared

Section titled “R-TEN-03 · Every row belongs to an organization: each organization gets its own copy of the system lookups, and only the permission catalogue is shared”
  • Status: built
  • Example: given a new organization, when it is created, then it has its own rows for the system roles, charge types (rent, admin_fee…), lead sources, checklist items and body panels, each with its organization_id; the permissions table is the one global catalogue.
  • Refusal: none: not_null_violation (23502) on organization_id.
  • Who: every organization.
  • Source: #144 (R-TEN-03: a row can't be without an organization). Replaces "system rows with no organization are shared".

R-TEN-04 · A unique value is unique within its organization, so two organizations may hold the same plate, NIK, code or document number; the only exception inside one organization is a temporary plate

Section titled “R-TEN-04 · A unique value is unique within its organization, so two organizations may hold the same plate, NIK, code or document number; the only exception inside one organization is a temporary plate”
  • Status: built
  • Example: given organization A has plate B1234XYZ, when organization B saves a car with plate B1234XYZ, then it is accepted; a second B1234XYZ inside organization A is refused, unless it is on the temporary plates list (R-VEH-02).
  • Refusal: none: unique_violation (23505), within one organization.
  • Who: every writer.
  • Source: D9 (P3); #144 (R-TEN-04: okay except plates); D39.

R-TEN-05 · A row can't reference a parent row of another organization

Section titled “R-TEN-05 · A row can't reference a parent row of another organization”
  • Status: planned
  • Example: given a driver of organization A and a car of organization B, when a rental of organization A links them, then it is refused.
  • Refusal: none: foreign_key_violation (23503), from composite foreign keys (organization_id, id).
  • Who: every writer, jobs included: foreign keys ignore row-level security.
  • Source: D9 (P2). Due before the second tenant, on drivers, vehicles, rentals and charges.

R-TEN-06 · An organization's slug is unique across all organizations

Section titled “R-TEN-06 · An organization's slug is unique across all organizations”
  • Status: built
  • Example: given an organization with slug optima, when another organization is saved with slug optima, then it is refused.
  • Refusal: none: unique_violation (23505).
  • Who: every writer.
  • Source: [Ref] Data model V13: organizations.
Section titled “R-TEN-07 · A legal entity's code is unique within its organization”
  • Status: built
  • Example: given legal entity TOP, when a second TOP is saved in the same organization, then it is refused.
  • Refusal: master_data.code_taken through the functions of R-TEN-18 (R-TEN-22); elsewhere none: unique_violation (23505).
  • Who: every writer.
  • Source: [Ref] Data model V13: legal_entities; the key: zuki on #459 (2026-11-17).

R-TEN-08 · A pool's code is unique within its organization

Section titled “R-TEN-08 · A pool's code is unique within its organization”
  • Status: built
  • Example: given pool PML, when a second PML is saved in the same organization, then it is refused.
  • Refusal: master_data.code_taken through the functions of R-TEN-18 (R-TEN-22); elsewhere none: unique_violation (23505).
  • Who: every writer.
  • Source: [Ref] Data model V13: pools; the key: zuki on #459 (2026-11-17).

R-TEN-09 · A pool's time zone defaults to Asia/Jakarta

Section titled “R-TEN-09 · A pool's time zone defaults to Asia/Jakarta”
  • Status: built
  • Example: given a new pool saved without a time zone, when it is read back, then timezone is Asia/Jakarta.
  • Refusal: none.
  • Who: every writer.
  • Source: D9 (P11); [Ref] Data model V13: pools.

R-TEN-10 · An organization has at most one subscription

Section titled “R-TEN-10 · An organization has at most one subscription”
  • Status: built
  • Example: given an organization with a subscription, when a second subscription is saved for it, then it is refused.
  • Refusal: none: unique_violation (23505).
  • Who: every writer.
  • Source: [Ref] Data model V13: subscriptions.
Section titled “R-TEN-11 · Legal entities and pools are readable by every member of the organization”
  • Status: built
  • Example: given a satpam at pool PML, when they read pools, then every pool of their organization comes back, PML and the others.
  • Refusal: none.
  • Who: every member, whatever their roles.
  • Source: [Ref] Roles, policy matrix.
Section titled “R-TEN-12 · Adding or changing a legal entity or a pool needs master_data:write”
  • Status: built
  • Example: given a finance user, when they rename a pool or add the legal entity MOP, then it is refused; an admin's rename and add go through.
  • Refusal: master_data.not_allowed, from the functions of R-TEN-18.
  • Who: super_admin, admin, maintenance and asuransi hold master_data:write.
  • Source: [Ref] Roles, policy matrix; the key: zuki on #459 (2026-11-17) (every write through a function, as R-MD-24 did for the first five lists).
Section titled “R-TEN-13 · App users can't delete a legal entity or a pool”
  • Status: built
  • Example: given a super_admin, when they delete a pool straight through PostgREST, then nothing is deleted; a pool that closes is retired instead (R-TEN-23). No function deletes either.
  • Refusal: none: insufficient_privilege (42501), as authenticated holds only select on these tables (R-TEN-18).
  • Who: every app user, super_admin included.
  • Source: [Ref] Roles, policy matrix; D9 (P13); zuki on #459 (2026-11-17).

R-TEN-14 · Reading the organization's subscription needs user:write

Section titled “R-TEN-14 · Reading the organization's subscription needs user:write”
  • Status: built
  • Example: given an admin, when they read subscriptions, then no row comes back; a super_admin sees the organization's plan.
  • Refusal: none: hidden.
  • Who: super_admin holds user:write.
  • Source: [Ref] Roles, policy matrix (subscriptions: owner only).

R-TEN-15 · App users can't change the organization's subscription

Section titled “R-TEN-15 · App users can't change the organization's subscription”
  • Status: built
  • Example: given a super_admin, when they change the plan to enterprise, then nothing changes.
  • Refusal: none: no effect, as there is no insert, update or delete policy.
  • Who: every app user. Billing changes come from a job or the migration.
  • Source: [Ref] Roles, policy matrix.

R-TEN-16 · A pool's time zone is one of Indonesia's: Asia/Jakarta, Asia/Pontianak, Asia/Makassar or Asia/Jayapura

Section titled “R-TEN-16 · A pool's time zone is one of Indonesia's: Asia/Jakarta, Asia/Pontianak, Asia/Makassar or Asia/Jayapura”
  • Status: built
  • Example: given a new pool in Balikpapan, when it is saved with Asia/Makassar (WITA), then it is accepted; Asia/Singapore or a misspelt Asia/Jakart is refused.
  • Refusal: master_data.timezone_invalid, with {field: timezone}, raised by the add function of R-TEN-18. The time zone is set once, so no other function takes it.
  • Who: every writer.
  • Source: the key: zuki on #459 (2026-11-17). D9 (P11), which adds the time zone for pools in WITA and WIT cities. Asia/Jakarta and Asia/Pontianak are WIB, Asia/Makassar is WITA, Asia/Jayapura is WIT. Added for DOC-Q2. A pool outside Indonesia would need a change request.

R-TEN-17 · An organization's own row is readable by its members

Section titled “R-TEN-17 · An organization's own row is readable by its members”
  • Status: built
  • Example: given Deka is a member of organization A only, when they read organizations, then A's row comes back, so the app can show its name, and no other organization's.
  • Refusal: none: hidden.
  • Who: every member, whatever their roles.
  • Source: [Ref] Roles, The RLS pattern (organization-level tables use app.my_org_ids(): any member reads). Added for DOC-Q11.
Section titled “R-TEN-18 · Legal entities and pools are written only through database functions”
  • Status: built
  • Example: given an admin, when they insert a pool or update a legal entity's legal_name straight through PostgREST, then it is refused; the same change through the function goes through. A call that names a row the caller's organization doesn't hold raises master_data.not_found.
  • Refusal: master_data.not_found from a function; a direct insert, update or delete: none: insufficient_privilege (42501), as authenticated holds only select on these tables.
  • Who: every app user. The functions are security definer and check master_data:write (R-TEN-12); each refusal raises a key (D10).
  • Source: D3, D10; the lead on #459 (2026-11-17: the R-MD-23 pattern for every table of the slice).
Section titled “R-TEN-19 · A legal entity's or pool's code is set when it is added and never changed”
  • Status: built
  • Example: given the legal entity TOP, when an admin changes its legal name, then the name changes and the code stays TOP; no function takes a new code, and a direct update is refused (R-TEN-18). The same holds for pool PML. Contract, BASTK and surat hutang numbers already issued carry the code (D40), so it can't move under them.
  • Refusal: none: the change functions take no code.
  • Who: every holder of master_data:write.
  • Source: zuki on #459 (2026-11-17: codes are set once, as R-MD-32); D40.
Section titled “R-TEN-20 · A legal entity's or pool's code that isn't upper-case letters only is refused”
  • Status: built
  • Example: given an admin, when they add a legal entity with code Top, T-OP or TOP1, or a pool with code pml, then it is refused, and the form says only upper-case letters are allowed; TOP, MOP and PML are accepted. Spaces around the code are trimmed first.
  • Refusal: master_data.code_invalid, with {field: code} in its detail.
  • Who: every holder of master_data:write, through the add functions of R-TEN-18.
  • Source: zuki on #459 (2026-11-17: upper-case letters, such as TOP, MOP and PML).

R-TEN-21 · A pool's time zone is set when the pool is added and never changed

Section titled “R-TEN-21 · A pool's time zone is set when the pool is added and never changed”
  • Status: built
  • Example: given pool BPN added with Asia/Makassar, when an admin renames it or changes its city, then the time zone stays Asia/Makassar; the change function takes no time zone, so the pool's business dates (R-CONV-10) never move under rows already dated. A pool added without one gets Asia/Jakarta (R-TEN-09).
  • Refusal: none: the change function takes no time zone.
  • Who: every holder of master_data:write.
  • Source: zuki on #459 (2026-11-17: a pool's time zone is set once).
Section titled “R-TEN-22 · A legal entity's or pool's code already held in the organization, by an active or a retired row, is refused”
  • Status: built
  • Example: given the retired pool PML, when an admin adds a pool with code PML, then it is refused, and the message offers to restore the retired one (R-TEN-24); a code an active row holds is refused with the same key, without the offer. Legal entity TOP and pool TOP are two codes in two lists, and both are accepted.
  • Refusal: master_data.code_taken, with {field: code, id, retired} in its detail.
  • Who: every holder of master_data:write, through the add functions of R-TEN-18.
  • Source: R-TEN-07, R-TEN-08; R-MD-37; the lead on #459 (2026-11-17).
Section titled “R-TEN-23 · A holder of master_data:write retires a legal entity or a pool of their organization”
  • Status: built
  • Example: given an admin, when they retire pool SBY, which holds no car and no live rental, then it is kept with is_active false, and the audit log shows who retired it (R-TEN-30). Retiring a row that is already retired goes through, changes nothing and writes no audit row. A finance user's attempt is refused. Its members, pool settings and past rows stay as they are.
  • Refusal: in this order: master_data.not_found for a row outside the organization; master_data.not_allowed without the permission; master_data.last_active (R-TEN-27); then master_data.in_use (R-TEN-25, R-TEN-26). The first that applies is raised.
  • Who: super_admin, admin, maintenance and asuransi hold master_data:write.
  • Source: zuki on #459 (2026-11-17: retire as R-MD-26, refused while in use); D9 (P13); D65.
Section titled “R-TEN-24 · A holder of master_data:write restores a retired legal entity or pool”
  • Status: built
  • Example: given the retired pool SBY, when an admin restores it, then is_active is true again; a finance user's attempt is refused. Restoring a row that is active goes through, changes nothing and writes no audit row.
  • Refusal: in this order: master_data.not_found for a row outside the organization; then master_data.not_allowed without the permission.
  • Who: super_admin, admin, maintenance and asuransi hold master_data:write.
  • Source: zuki on #459 (2026-11-17: restore as R-MD-27).

R-TEN-25 · A pool can't be retired while it is the home pool of a car still in the fleet, or holds a live rental

Section titled “R-TEN-25 · A pool can't be retired while it is the home pool of a car still in the fleet, or holds a live rental”
  • Status: built
  • Example: given pool SBY, home pool of a car whose status is ready, when an admin retires SBY, then it is refused and the message gives the number of cars; when every car of SBY is inactive (it left the fleet, D39) or has moved to another home pool, and no rental of SBY is live (pending, booked, active, paused, returning, repossessing or returned, D67), then the retirement goes through. An ended or cancelled rental doesn't hold the pool.
  • Refusal: master_data.in_use, with {reason: vehicles or rentals, count} in its detail. Cars are checked before rentals, so a pool that holds both is refused with reason vehicles. It comes after the refusals of R-TEN-23 and R-TEN-27.
  • Who: every holder of master_data:write.
  • Source: zuki on #459 (2026-11-17: refused while the pool holds cars or a live rental); the lead on #459 (2026-11-18: a car counts unless it is inactive; rentals count from pending to returned, as R-RNT-20 and R-RNT-21's live set, D67).
Section titled “R-TEN-26 · A legal entity can't be retired while it has an active company bank account or an active contract template”
  • Status: built
  • Example: given legal entity MOP with one active bank account, when an admin retires MOP, then it is refused and the message names the account count; once the account and every active template of MOP are retired (R-MD-43), the retirement goes through.
  • Refusal: master_data.in_use, with {reason: company_bank_accounts or contract_templates, count} in its detail. Bank accounts are checked before templates, so an entity that has both is refused with reason company_bank_accounts. It comes after the refusals of R-TEN-23 and R-TEN-27.
  • Who: every holder of master_data:write.
  • Source: zuki on #459 (2026-11-17: refused while the entity still has active bank accounts or templates); the lead on #459 (2026-11-18): pools have no legal entity, so they don't hold one.
Section titled “R-TEN-27 · The organization's last active legal entity, or its last active pool, can't be retired”
  • Status: built
  • Example: given an organization whose only active pool is PML, when an admin retires PML, then it is refused, even with no car or rental there; with SBY active too, the rules of R-TEN-25 decide. The same holds for the last active legal entity.
  • Refusal: master_data.last_active, with {field: legal_entities or pools} in its detail. It is checked after not_found and not_allowed, and before master_data.in_use (R-TEN-25, R-TEN-26), in the order of R-TEN-23, so the last active pool is refused with last_active even while it holds cars.
  • Who: every holder of master_data:write.
  • Source: zuki on #459 (2026-11-17).
Section titled “R-TEN-28 · A legal entity's code or legal name, or a pool's code, name or city, that is blank once trimmed is refused; a blank address is stored as none”
  • Status: built
  • Example: given an admin, when they add a pool named " " or a legal entity with legal name "", then it is refused; a pool named " Surabaya " is saved as Surabaya, and an address of " " is saved empty.
  • Refusal: master_data.name_required, with {field} in its detail.
  • Who: every holder of master_data:write, through the functions of R-TEN-18.
  • Source: R-MD-36; the lead on #459 (2026-11-17: the keys of #458).

R-TEN-29 · A pool's capacity can't be below 0

Section titled “R-TEN-29 · A pool's capacity can't be below 0”
  • Status: built
  • Example: given an admin, when they save pool PML with a capacity of -5, then it is refused; 0, 120 or an empty capacity are accepted.
  • Refusal: master_data.out_of_range, with {field: capacity, min: 0} in its detail.
  • Who: every holder of master_data:write, through the functions of R-TEN-18.
  • Source: the column check on pools.capacity; R-MD-39 (the same key).
Section titled “R-TEN-30 · Every add, change, retirement and restore of a legal entity or a pool writes an audit row”
  • Status: built
  • Example: given an admin, when they rename pool SBY and then retire it, then pools has two audit rows naming the admin, with the changed fields name and is_active (R-AUD-01, R-AUD-02). Retiring a retired row, or restoring an active one, writes none (R-TEN-23, R-TEN-24).
  • Refusal: none.
  • Who: every writer, and the functions of R-TEN-18.
  • Source: #459 (the slice: edits write audit entries); R-AUD-01; legal_entities and pools are watched tables already.

R-TEN-31 · A member keeps their roles, grants and permissions at a pool that is retired, so they still read its history

Section titled “R-TEN-31 · A member keeps their roles, grants and permissions at a pool that is retired, so they still read its history”
  • Status: built
  • Example: given Deka holds checker at pool SBY, when an admin retires SBY (R-TEN-23), then Deka's role at SBY is kept, my_permissions() still returns SBY's rows (R-TEN-32), and Deka can still read SBY's past inspections under row-level security. Restoring SBY (R-TEN-24) needs no new grant.
  • Refusal: none. Writes that a retired pool refuses keep their own rules.
  • Who: every member with a role, grant or deny at a retired pool.
  • Source: zuki on #667 (a retired pool is hidden from the switcher and keeps its permissions; reads of its history stay); the lead in the session on #650.

R-TEN-32 · my_permissions() says on each row whether its pool is active

Section titled “R-TEN-32 · my_permissions() says on each row whether its pool is active”
  • Status: built
  • Example: given Deka holds checker at PML and at the retired pool SBY, when they call my_permissions(), then the PML rows carry pool_is_active true and the SBY rows pool_is_active false; the rows are otherwise as R-ACC-28 says.
  • Refusal: none.
  • Who: every signed-in user (R-ACC-28). apps/web reads it for the switcher and the current pool (R-APP-29 to R-APP-31).
  • Source: zuki on #667; the lead in the session on #650 (my_permissions() gains pool_is_active).