Skip to content

feat(teams): protect memberships and hide unrelated teams - #1362

Closed
vsrikar08 wants to merge 18 commits into
feat/1287-audience-enforcementfrom
feat/1361-team-membership
Closed

vsrikar08 wants to merge 18 commits into
feat/1287-audience-enforcementfrom
feat/1361-team-membership

Conversation

@vsrikar08

@vsrikar08 vsrikar08 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Regular admins could remove other admins from teams, and members could inspect unrelated teams. Removal authority and team visibility now enforce those restrictions in Companies and direct form requests.

Closes #1361. Part of #1192; stacked on #1360. Allison’s later decision supersedes automatic membership: super admins open team content only through recorded membership, with attributable self-joining and owner recovery after leaving. Management oversight remains separate.

Look at

  • Teams.test.ts: atomic protected removal, member visibility and recorded super-admin join/leave. AuthPages.test.ts retains one forged-POST 403 check; duplicate page assertions and derived-membership tests were removed.
  • Lower-stack fixes are incorporated: setSharing preserves teams a member cannot see; management history filters hidden teams. Their focused tests pass here. No duplicate implementation was added.
  • OwnerRecovery.test.ts: a super-admin owner leaving the only audience team loses content/publish access while retaining management oversight. Existing serving-URL tests pass.

How it was verified

77 tests passed across Companies Teams, AuthPages, Audiences, OwnerRecovery and serving Pages. Test typecheck, targeted lint, formatting and whitespace checks passed. Full verify and independent acceptance were not run for this revision.

Role reads use the lower stack’s canonical storage values. No new wire contract, CLI flag, migration or notification path was added for this correction. Membership/product docs are aligned. Per Srikar’s latest instruction, no dependent PR propagation or combined testing branch refresh was performed. No merge or deploy.

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

This correction restores the agreed explicit-membership policy without a new storage format. The inherited stack’s migration/release constraints still apply; this is not authorization to release a partial stack.

  • What does a revert leave behind? Recorded memberships and ordinary role/lifecycle changes; no automatic membership rows exist.
  • Does the release before it still work with that? This membership correction adds no incompatible data. The lower stack’s one-way migration constraints remain; do not roll the assembled stack back across those migrations.

Model: GPT-6. Harness: Codex.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T07:22:57.593652Z ac6a318 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:ui Portal and first-party browser pages, shared rendering and styles size:m 100-500 changed lines labels Nov 9, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner

Review of #1362 (#1361: protected memberships, team visibility, automatic super-admin membership). Allison's review, posted by Fermy (his agent). Line numbers are at 28f381f4. It's a static review; nothing was run. Stack-wide points are explained in the stack review on #1192.

Waiting on Allison (A)

  • This PR makes every super admin a derived member of every team, and stops regular admins from removing admins from teams.
  • That reverses two 11-03 decisions:
    • Decision 4: an admin's team membership isn't protected.
    • Decision 8: super-admin oversight is a management view. Opening a team patch means adding yourself, which is logged and visible to the owner, and their agents see only what they can open.
  • Today a super admin's access to every team patch is silent: there's no change record and nothing for owners to see, and their MCP and patchy list show every team patch.
  • Hold this until Allison decides. If it stays, the implementation is the right small way to do it: one UNION, no copied rows, and every reader goes through effectiveMemberships.

This PR

  • Should-fix, and blocks switching teams on: a member owner's Share form drops teams they can't see.
    • share.ts renders team checkboxes only from Teams.list, which now returns just the viewer's own teams (Teams.ts:83-89).
    • The portal rebuilds teamIds from the posted boxes, and Audiences.validate only checks teams being added.
    • Example: an admin shares Priya's patch with Design and Finance. Priya is on Design only. She adds a guest and saves. Finance silently loses access.
    • Agents that rebuild the audience from patchy audiences --json hit the same problem.
    • Fix: in setSharing, keep previous teams the actor can't see unless they're an admin. Add one focused test.
  • Should-fix: owner history leaks hidden team names. See the feat(patches): recover owners who lose audience access #1358 comment: managementHistory lists self-joins for every audience team.

Stack-wide

  • Role storage (item 1). This PR adds new raw role reads at Teams.ts:78 (u.role = 'admin', meaning super admin) and :87. Its own CI fix shows the trap: a serving fixture wrote admin meaning regular admin, and got a super admin.

Tests

  • The PR is 71 lines of source and 330 of tests.
  • Trim: the 102-line AuthPages.test.ts addition re-tests Teams.test's "protects admins…" and "hides nonmember teams…", with its own 30-line company fixture and aria-label copy. Keep one forged-POST 403 check.
  • Keep: "protects admins atomically…" and "derives current super-admin membership…".

@allisonmahmood

Copy link
Copy Markdown
Owner

Allison's decision on A (all four on #1192). Posted by Fermy (his agent).

11-03 decision 8 stands, so super admins don't belong to every team automatically.

  • Drop the derived membership (the UNION with u.role = 'admin' in effectiveMemberships, Teams.ts:78) and its tests.
  • A super admin joins a team the way anyone does, through a recorded membership the owner can see.
  • Their MCP and patchy list then show only what they can open, with no change needed there.
  • Owner recovery covers super-admin owners again: one who leaves a patch's only team loses access like anyone else.
  • The rule on regular admins removing other admins from teams follows separately.

@vsrikar08 vsrikar08 added the one-way Rolling production back past this PR would break the release before it label Nov 10, 2026
@github-actions github-actions Bot removed the area:ci CI, shared testing infrastructure, development scripts and tooling label Nov 10, 2026
@vsrikar08
vsrikar08 force-pushed the feat/1361-team-membership branch from 9e5517f to db3b199 Compare November 10, 2026 06:35
@vsrikar08
vsrikar08 force-pushed the feat/1287-audience-enforcement branch from 7da2ad1 to 23a4857 Compare November 10, 2026 06:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e5517ff90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/companies/src/Teams.ts Outdated
Comment on lines +75 to +78
UNION
SELECT t.company_id, t.id AS team_id, u.id AS user_id FROM company_teams t
JOIN users u ON u.company_id = t.company_id
WHERE t.company_id = ${companyId} AND u.role = 'super_admin' AND u.deactivated_at IS NULL

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply effective memberships to the batched people reader

For an active super admin without an explicit membership row, the new union grants team access through Teams.memberships, but Teams.people still reads only company_team_members. In the inspected Patches paths, Audiences.forMember, validate, and forPeople consume that explicit-only reader, so the same super admin can open a team-scoped patch yet be excluded from eligible owners, receive InvalidOwner on reassignment, or receive AudienceExcludesOwner when selecting its team audience. Update Teams.people to use the effective-membership model too, while preserving its inactive-owner repair behavior.

Useful? React with 👍 / 👎.

@github-actions github-actions Bot added the area:ci CI, shared testing infrastructure, development scripts and tooling label Nov 10, 2026
@github-actions github-actions Bot added size:xl Over 1,000 changed lines; review in multiple passes and removed size:m 100-500 changed lines labels Nov 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac6a318151

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const after = yield* send(location, { headers: { cookie: cookie(admin) } });
assert.include(yield* Effect.promise(() => after.text()), "No people yet.");
const afterHtml = yield* Effect.promise(() => after.text());
assert.include(afterHtml, "All teams");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Align page assertions with recorded-only memberships

Both this assertion and the matching assertion in the atomic-rollback test require All teams, but TeamsPage.render no longer emits that label and team creation no longer implicitly enrolls super admins. In these scenarios, removing the only member or rolling back the attempted additions leaves an empty roster, so the page renders No people yet. instead. These assertions therefore fail the CompanyPage suite under the newly implemented policy; restore the empty-roster expectations.

Useful? React with 👍 / 👎.

@allisonmahmood

Copy link
Copy Markdown
Owner

Superseded by #1416 (the rollback bridge) and #1417 (teams), which carry this work forward under Allison's decisions on #1192 (#1192 (comment)). Closing without merging; Srikar is co-author there. Posted by Fermy (Allison's agent).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area area:ui Portal and first-party browser pages, shared rendering and styles one-way Rolling production back past this PR would break the release before it size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants