Org domain decisions
This page records the ratified design decisions for the Org domain. Read it before you design anything in this domain.
Each decision states what we decided, why, and where the evidence is. Decisions live only on this page. Other docs must link here instead of repeating the text. When a decision changes, update this page the same day.
Schema truth is jodapp-api/docs/db/org.dbml. Verify columns there before you rely on this page.
D1 — is_selected always marks the membership Rails acts as (2026-09-24)
An Org::Membership connects one Identities::User to one Org::Company. A person can hold several, one per company. The column org_memberships.is_selected marks the one the person acts as. A partial unique index, index_org_memberships_on_user_id_where_is_selected, allows at most one selected row per person.
A membership is usable when its status is active and its company's status is active. Org::Membership#usable? answers this. Org::Memberships::CurrentResolveService answers which membership Rails acts as:
- the selected row, but only while it is usable
- otherwise the newest usable row
- when no row is usable, the newest row
Every employer request asks Org::Memberships::CurrentResolveService, through Employers::BaseController.
Ali decided this on 2026-09-24.
What we decided
| Part | Decision | Ruled |
|---|---|---|
| The rule | While a person has a usable membership, is_selected: true sits on the row Org::Memberships::CurrentResolveService answers. Every other row of that person has is_selected: false | 2026-09-24 |
| When the selected membership stops being usable | The write that makes it unusable moves is_selected to the row Org::Memberships::CurrentResolveService answers, in the same transaction. Two writes do this: a Jod team member changes a company's status in Team Portal, and the nightly JodGig company sync copies a company's status. A write that revokes a member does the same | 2026-09-24 |
| When no usable membership is left | The same write sets is_selected: false on every row of the person. The person then lands on /employers/access-unavailable, which tells them they have no company they can use. JodApp Web — What the access-unavailable page shows states the text | 2026-09-24 |
| A company that is switched on again | It does not get the selection back when the person already acts as another usable membership. Churned companies rarely return, so this costs little. A person with no selected row gets one from the same write | 2026-09-24 |
| Who reads it | GET /identities/users/current/org_memberships returns is_selected on every entry. JodApp Web reads it there, and nowhere else | 2026-09-24 |
| How the rule runs | One call to the service in every place that writes a company's status or a membership's status: the managers, and the JodGig company sync. It is never a model callback, because the codebase makes every side effect an explicit call in the code that does the write | 2026-09-24 |
Why
- One meaning for one flag. JodApp Web reads
is_selected: trueas "Rails acts as this membership". It never works out which membership is current in the browser. - The session does not answer it. Identities D6 — The current-session answer holds the person and one access word per area keeps membership ids out of the session. So the memberships endpoint gives the only answer, and it must be right.
- The same transaction, so no request sees a half-done change. A request that ran between two separate writes would read a selected row on a company that is already switched off.
- Clear, not keep, when nothing is usable. A kept flag on an unusable row would give
is_selected: truea second meaning. Every reader would then have to checkaccess_statusas well, and the row marked selected could differ from the rowOrg::Memberships::CurrentResolveServiceanswers.
Evidence
| Fact | Where |
|---|---|
| The column and the index | is_default became is_selected in jodapp-api#1926, migration 20260821101500, merged 2026-08-21. The partial unique index came in jodapp-api#1915, commit 85d316953, migration 20260822090000, merged 2026-08-23 |
| The rule that picks the row | jodapp-api at bc04d829b, app/domains/org/memberships/current_resolve_service.rb:63-75 |
| A switch refuses an unusable row, and clears then sets in one transaction | app/domains/org/memberships/employers_select_validator.rb:24-40; employers_select_manager.rb:63-81 |
A company switched off in Team Portal left is_selected where it was | app/domains/org/companies/team_update_manager.rb:59, :64-74 |
The nightly JodGig company sync changes status with upsert_all, which runs no model code | app/domains/jod_gig/companies/sync_service.rb:47-63 |
| No model callbacks for side effects | jodapp-api AGENTS.md:194 |
| Production on 2026-09-24 | 78 memberships and 78 people, each with one membership, and each membership selected. 0 people with two memberships. 2 selected memberships are revoked on an active company, so the rule clears 2 and moves 0. org_companies.status: 228 active, 144 disabled, 0 empty. Counted by Ali in the Rails console |
| The first people with two memberships | They arrive with the JodGig employer sync. JodGig holds 1,349 active manager accounts, and 248 of them sit on a disabled or deleted company. Counted on a scrubbed copy of the JodGig database, 2026-09-24. The sync's own plan already moves the flag on a revoke: Employer migration phase 3 — Maintain one selected membership |
D2 — The employer sync takes over a jodapp membership on a company JodGig grants (2026-10-01)
The column org_memberships.provisioning_source records which system created an Org::Membership.
:jodgigmeans the nightly employer sync,JodGig::Users::EmployersSyncJob, created it. The employer sync may update and revoke it.:jodappmeans someone created it in JodApp. Today only company sign-up does this, throughPOST /employers/org/memberships.
A person has at most one membership per company. A unique index on org_memberships (user_id, company_id) enforces this. So JodGig can grant a person a company where they already hold a :jodapp membership. The employer sync cannot add a second row there. It must either leave the row alone or take it over.
Ali decided this on 2026-10-01.
What we decided
| Case | What the employer sync does | Ruled |
|---|---|---|
A :jodapp membership on a company that JodGig does not grant to that person | Never changes it and never revokes it | 2026-10-01 |
A :jodapp membership on a company that JodGig grants to that person | Takes it over. It writes provisioning_source: :jodgig and the JodGig role, title, status and notification choices. From then on, the employer sync updates and revokes it like any other :jodgig membership | 2026-10-01 |
is_owner on a membership the employer sync takes over | Keeps its value. The employer sync writes is_owner: false only when it creates a membership | 2026-10-01 |
is_selected on a membership the employer sync takes over | Follows Org D3 — The employer sync selects a membership only when the person has no usable selected one | 2026-10-01 |
| The run report | The person's row in jodgig_users_employers_sync_reports carries the reason :takeover_jodapp_membership. It appears on the run that takes the membership over | 2026-10-01 |
Why
- A reviewer would always give the same answer. The row joins the same person to the same company in both systems. JodGig already owns that company's access. A human who reviewed the case would set it to
:jodgigevery time. - A review case blocks the person's login. The employer sync writes nothing for a person in review. Their single login then waits until someone acts. No tool exists to act on a review case.
- The case comes from companies that exist in both systems. A client can create the same company in JodApp and in JodGig. The company sync then links the JodApp row to its JodGig copy. The person who created the company in JodApp is often its JodGig manager too.
- The report reason keeps the takeover visible. A dry run counts the takeovers without blocking anyone.
is_owneris the only true owner record. Company sign-up setsis_owner: trueon the person who created the company. JodGig has no owner field. The business team sets owners by hand, as the employer migration decision log states for 2026-07-23. A sync that writesis_owneron every run would undo their updates every night.
Evidence
| Fact | Where |
|---|---|
The employer sync took over :jodapp memberships on companies JodGig does not grant. The next run revoked them | jodapp-api#2110 |
| The fix that stops planning those memberships. Its description gives the reasoning for a takeover | jodapp-api#2112 |
| The writer finds a membership by person and company only, then overwrites it | jodapp-api at 957745669, app/domains/jod_gig/users/employers_sync_service.rb:202-221 and app/models/application_record.rb:15-21 |
The writer sets is_owner on every run | employers_sync_service.rb:212 |
Company sign-up sets is_owner: true | app/domains/org/memberships/employers_create_manager.rb:81 |
| The company sync links a JodApp-created company to its JodGig copy when the slugs match | jodapp-api#2097, open on 2026-10-01 |
D3 — The employer sync selects a membership only when the person has no usable selected one (2026-10-01)
Org D1 — is_selected always marks the membership Rails acts as defines org_memberships.is_selected as the membership the person acts as. It also defines a usable membership: status: :active, on a company with status: :active. A person changes the company they act as with PATCH /employers/org/memberships/:org_membership_id/select.
The nightly employer sync, JodGig::Users::EmployersSyncJob, also writes is_selected when it plans :jodgig memberships. This decision says when it may.
Ali decided this on 2026-10-01.
What we decided
| Before the run, the person has | What the employer sync does with is_selected | Ruled |
|---|---|---|
| A usable selected membership that the run keeps usable | Leaves is_selected where it is. This holds for a :jodgig membership and for a :jodapp one | 2026-10-01 |
| A selected membership that the run revokes | Moves is_selected as Org D1 — is_selected always marks the membership Rails acts as states | 2026-10-01 |
| No selected membership | Selects one of the memberships the run plans. For an external super-HQ user, that is jodgig.users.company_id when it is a valid grant. Otherwise it is the valid grant with the highest jodgig.user_company.id. An HQ, AREA or LOCATION user has one grant. The employer sync selects it | 2026-10-01 |
Why
- The selection is the person's choice. Org D1 —
is_selectedalways marks the membership Rails acts as moves it only when the selected membership stops being usable. A sync that moves it every night undoes the person's choice every night. - For an external super-HQ user,
users.company_idis the last company they opened in JodGig. Opening a company writes its id there. Leaving it sets the column to NULL. Copying it every night would make JodApp follow their last click in JodGig. - A person who already uses JodApp keeps working where they were. Suppose a person signed up on JodApp and is also a JodGig employer. They stay on the company they created in JodApp, not on their JodGig company.
- The selection must land on a membership the run plans. When
jodgig.users.company_idis not a valid grant, no planned membership matches it. The fallback to the highestjodgig.user_company.idmakes sure one does.
Evidence
| Fact | Where |
|---|---|
Opening a company in the JodGig portal writes users.company_id. Leaving it sets the column to NULL | PORTAL_V2_BACKEND_GLOBAL at b224576d3 (branch merge-prod), app/Services/HqUserService.php:380-463 |
The planner selects users.company_id when it is set, valid or not | jodapp-api at 957745669, app/domains/jod_gig/users/employers_migration_plan_service.rb:435 |
| The writer clears every other selected row of the person on every run | employers_sync_service.rb:189-196 and :231-243 |
| How many people hold two or more companies | 64 active external super-HQ users in JodGig. 9 of them hold two or more valid companies. 0 have a users.company_id that is not a valid grant while they hold another one. Counted on the jodgig_ai copy, 2026-10-01 |
D4 — area_manager and outlet_manager can each have zero or more outlets (2026-11-02)
Three records decide which outlets a person can manage.
- An
Org::Membershiphas one of three roles:hq_manager,area_manageroroutlet_manager. - An
Org::OutletAssignmentlinks one membership to oneOrg::Outletthe person can manage. - An
Org::Invitecarries the role and the outlets asOrg::InviteOutletrows.- Acceptance turns each
Org::InviteOutletrow into oneOrg::OutletAssignment.
- Acceptance turns each
This decision says how many outlets each role can have.
Proposed in jodapp-api#2243 on 2026-11-02. Approved on 2026-11-05, because it clears a known blocker in JodGig, the previous app.
What we decided
| Part | Decision | Ruled |
|---|---|---|
hq_manager | Zero outlets. The role can already manage every outlet in the company | 2026-11-05 |
area_manager | Zero or more outlets | 2026-11-05 |
outlet_manager | Zero or more outlets. The same rule as area_manager | 2026-11-05 |
| Where the rule applies | Everywhere a role gets outlets: a new invite, a new membership, adding or removing an assignment, and a role change | 2026-11-05 |
| A scoped membership with zero outlets | It can see no outlet until an hq_manager or an admin assigns one | 2026-11-05 |
Why
- An
hq_managercan add a person before deciding their outlets.- The invite or the membership comes first, and the outlets come later.
- In practice, some outlet managers look after more than one outlet.
- A limit of exactly 1 outlet would force the company to give them the
area_managerrole.
- A limit of exactly 1 outlet would force the company to give them the
- It clears a known blocker in JodGig, the previous app.
- One rule is simpler than one rule per role.
- Both scoped roles follow the same count rule, so no validator needs a branch per role.
Evidence
| Fact | Where |
|---|---|
| The issue that states the rule for invites | jodapp-api#2243 |
| The invite validator lists the outlets allowed per role | jodapp-api at 5e7dab017, app/domains/org/invites/shared_create_validator.rb:10-16 |
The only count rule in the invite code is "no outlets for hq_manager" | shared_create_validator.rb:115-123 |
Tests for an outlet_manager invite with zero outlets and an area_manager invite with two | test/controllers/employers/org/invites_controller_test.rb:80-104 |
D5 — Only an Org::Membership gives access to a company, not the parent company (2026-11-16)
A person can see and manage an Org::Company only when they hold an active Org::Membership on that company.
- A company can have one parent company through the column
org_companies.parent_company_id. - A root company has no parent, and a child company is an enterprise division under one root company.
- This decision says that the parent link gives no access to anyone.
Proposed in jodapp-api#2316 on 2026-11-16.
What we decided
| Part | Decision |
|---|---|
| Access to a company | Only an active Org::Membership on that company gives access to it |
| The parent link | It groups divisions under one legal entity, and it gives no access in either direction |
| A member of a root company | They can see and manage the root company only, and each child company needs its own membership |
| A member of a child company | They can see and manage that child company only |
| An employer creates a child company | The system creates a membership for the creator on the new child company, with is_owner: true |
| An admin creates a child company | The system creates no membership, and the admin adds members with Org::Membership UC-3 |
| Delete a child company | Only a membership with is_owner: true on that child company can delete it |
| Members who had access through the parent link | A one-time backfill gives them a membership on each child company, with the same role and is_owner |
The membership for the creator of a child company has these values:
role: :hq_manageris_owner: trueis_selected: false
The flag org_memberships.is_owner marks the person who created the company on Jod.
- It works like a "created by" field.
- It does not mean the person owns the company in the real world.
The one-time backfill reads each active or suspended membership on a root company.
- For each child company of that root, it creates one
Org::Membershipfor the sameIdentities::User. - It skips a child company where that user already has a membership.
Each backfilled membership has these values:
role: the same role as the membership on the root companystatus: the same status as the membership on the root companyis_owner: the same value as the membership on the root company, unless the child company already has an owner- When the child company already has a membership with
is_owner: true, the new membership getsis_owner: false.
- When the child company already has a membership with
is_selected: false- no
Org::OutletAssignmentrows, because the outlets of the root company are not the outlets of the child company
Why
- One record per company answers "who can access this company?"
- The table
org_membershipslists every person with access, and nothing else adds to the list.
- The table
- An
hq_managercan see and remove every person who has access to their company.- Access through the parent link did not appear in the member list of the child company.
- A person who should manage several companies already has a way to do it.
- They hold one membership per company, as Org::Membership — Multi-Company Access describes.
- The backfill keeps today's access for every existing person.
- Nobody loses access on the day the code stops reading the parent link.
- The owner of the root company becomes the owner of each child company that has no owner yet.
- A child company that already has an owner keeps it, so each company still has exactly one owner.
- Deleting a child company removes it for every member, so only its owner can do it.
- The owner is the person who created the child company, or the owner of the root company after the backfill.
Evidence
| Fact | Where |
|---|---|
| The issue that states the rule and the backfill | jodapp-api#2316 |
| The employer company list adds every child of the company of the current membership | jodapp-api at 67a301979, app/domains/org/companies/employers_index_manager.rb:26-33 |
| The employer update check accepts a membership on the parent company for a child company | app/domains/org/companies/employers_update_validator.rb:113-126 |
| Creating a child company creates no membership for the creator | app/domains/org/companies/employers_create_manager.rb:33-51 |
| verbal agreement on "Org::Company access should be provided by explicit Org::Membership, and Org::Company parent->child relation does not provide access | during IPM 10-11-2026 |