Skip to main content

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:

  1. the selected row, but only while it is usable
  2. otherwise the newest usable row
  3. 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​

PartDecisionRuled
The ruleWhile 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: false2026-09-24
When the selected membership stops being usableThe 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 same2026-09-24
When no usable membership is leftThe 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 text2026-09-24
A company that is switched on againIt 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 write2026-09-24
Who reads itGET /identities/users/current/org_memberships returns is_selected on every entry. JodApp Web reads it there, and nowhere else2026-09-24
How the rule runsOne 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 write2026-09-24

Why​

  1. One meaning for one flag. JodApp Web reads is_selected: true as "Rails acts as this membership". It never works out which membership is current in the browser.
  2. 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.
  3. 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.
  4. Clear, not keep, when nothing is usable. A kept flag on an unusable row would give is_selected: true a second meaning. Every reader would then have to check access_status as well, and the row marked selected could differ from the row Org::Memberships::CurrentResolveService answers.

Evidence​

FactWhere
The column and the indexis_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 rowjodapp-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 transactionapp/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 wasapp/domains/org/companies/team_update_manager.rb:59, :64-74
The nightly JodGig company sync changes status with upsert_all, which runs no model codeapp/domains/jod_gig/companies/sync_service.rb:47-63
No model callbacks for side effectsjodapp-api AGENTS.md:194
Production on 2026-09-2478 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 membershipsThey 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.

  • :jodgig means the nightly employer sync, JodGig::Users::EmployersSyncJob, created it. The employer sync may update and revoke it.
  • :jodapp means someone created it in JodApp. Today only company sign-up does this, through POST /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​

CaseWhat the employer sync doesRuled
A :jodapp membership on a company that JodGig does not grant to that personNever changes it and never revokes it2026-10-01
A :jodapp membership on a company that JodGig grants to that personTakes 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 membership2026-10-01
is_owner on a membership the employer sync takes overKeeps its value. The employer sync writes is_owner: false only when it creates a membership2026-10-01
is_selected on a membership the employer sync takes overFollows Org D3 — The employer sync selects a membership only when the person has no usable selected one2026-10-01
The run reportThe person's row in jodgig_users_employers_sync_reports carries the reason :takeover_jodapp_membership. It appears on the run that takes the membership over2026-10-01

Why​

  1. 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 :jodgig every time.
  2. 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.
  3. 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.
  4. The report reason keeps the takeover visible. A dry run counts the takeovers without blocking anyone.
  5. is_owner is the only true owner record. Company sign-up sets is_owner: true on 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 writes is_owner on every run would undo their updates every night.

Evidence​

FactWhere
The employer sync took over :jodapp memberships on companies JodGig does not grant. The next run revoked themjodapp-api#2110
The fix that stops planning those memberships. Its description gives the reasoning for a takeoverjodapp-api#2112
The writer finds a membership by person and company only, then overwrites itjodapp-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 runemployers_sync_service.rb:212
Company sign-up sets is_owner: trueapp/domains/org/memberships/employers_create_manager.rb:81
The company sync links a JodApp-created company to its JodGig copy when the slugs matchjodapp-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 hasWhat the employer sync does with is_selectedRuled
A usable selected membership that the run keeps usableLeaves is_selected where it is. This holds for a :jodgig membership and for a :jodapp one2026-10-01
A selected membership that the run revokesMoves is_selected as Org D1 — is_selected always marks the membership Rails acts as states2026-10-01
No selected membershipSelects 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 it2026-10-01

Why​

  1. The selection is the person's choice. Org D1 — is_selected always 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.
  2. For an external super-HQ user, users.company_id is 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.
  3. 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.
  4. The selection must land on a membership the run plans. When jodgig.users.company_id is not a valid grant, no planned membership matches it. The fallback to the highest jodgig.user_company.id makes sure one does.

Evidence​

FactWhere
Opening a company in the JodGig portal writes users.company_id. Leaving it sets the column to NULLPORTAL_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 notjodapp-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 runemployers_sync_service.rb:189-196 and :231-243
How many people hold two or more companies64 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::Membership has one of three roles: hq_manager, area_manager or outlet_manager.
  • An Org::OutletAssignment links one membership to one Org::Outlet the person can manage.
  • An Org::Invite carries the role and the outlets as Org::InviteOutlet rows.
    • Acceptance turns each Org::InviteOutlet row into one Org::OutletAssignment.

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​

PartDecisionRuled
hq_managerZero outlets. The role can already manage every outlet in the company2026-11-05
area_managerZero or more outlets2026-11-05
outlet_managerZero or more outlets. The same rule as area_manager2026-11-05
Where the rule appliesEverywhere a role gets outlets: a new invite, a new membership, adding or removing an assignment, and a role change2026-11-05
A scoped membership with zero outletsIt can see no outlet until an hq_manager or an admin assigns one2026-11-05

Why​

  1. An hq_manager can add a person before deciding their outlets.
    • The invite or the membership comes first, and the outlets come later.
  2. 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_manager role.
  3. It clears a known blocker in JodGig, the previous app.
  4. 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​

FactWhere
The issue that states the rule for invitesjodapp-api#2243
The invite validator lists the outlets allowed per rolejodapp-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 twotest/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​

PartDecision
Access to a companyOnly an active Org::Membership on that company gives access to it
The parent linkIt groups divisions under one legal entity, and it gives no access in either direction
A member of a root companyThey can see and manage the root company only, and each child company needs its own membership
A member of a child companyThey can see and manage that child company only
An employer creates a child companyThe system creates a membership for the creator on the new child company, with is_owner: true
An admin creates a child companyThe system creates no membership, and the admin adds members with Org::Membership UC-3
Delete a child companyOnly a membership with is_owner: true on that child company can delete it
Members who had access through the parent linkA 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_manager
  • is_owner: true
  • is_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::Membership for the same Identities::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 company
  • status: the same status as the membership on the root company
  • is_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 gets is_owner: false.
  • is_selected: false
  • no Org::OutletAssignment rows, because the outlets of the root company are not the outlets of the child company

Why​

  1. One record per company answers "who can access this company?"
    • The table org_memberships lists every person with access, and nothing else adds to the list.
  2. An hq_manager can 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.
  3. A person who should manage several companies already has a way to do it.
  4. 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.
  5. 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​

FactWhere
The issue that states the rule and the backfilljodapp-api#2316
The employer company list adds every child of the company of the current membershipjodapp-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 companyapp/domains/org/companies/employers_update_validator.rb:113-126
Creating a child company creates no membership for the creatorapp/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 accessduring IPM 10-11-2026