Skip to content

fix(platform): clear orphaned sharedWithTeamIds when a project goes org-wide (#2046) - #2266

Merged
yannickmonney merged 1 commit into
mainfrom
tale/xs71nmx0mdrtwjvcey44r0rdrn89ejbf
Jun 29, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
tale/xs71nmx0mdrtwjvcey44r0rdrn89ejbf

Conversation

@larryro

@larryro larryro commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2046. Switching a project's owning team to Org-wide used to leave sharedWithTeamIds intact, so getProjectTeamIds() still returned those teams: the project stayed restricted to them while the Sharing Select, overview header, and projects table all displayed "Org-wide". The orphaned shares were also unreachable from the UI (the "Also shared with" control is hidden when there's no owning team).

A shared-with team is always additional to an owning team, so a project with no owning team cannot retain shares.

Changes

  • Server (convex/projects/access.ts, mutations.ts): new pure normalizeSharing() helper, applied in updateProjectSharing so an effective owning team of null clears sharedWithTeamIds. Authoritative backstop regardless of caller (also cleans legacy orphaned rows on next save).
  • Client (project-sharing-section.tsx): handleOwningTeamChange now clears the shared list when the owning team becomes Org-wide, instead of filter(id => id !== null) which never matched.
  • Tests (access.test.ts): unit coverage for normalizeSharing, including that the result is genuinely org-wide per isOrgWideProject/getProjectTeamIds.

Verification

  • vitest --project server convex/projects/ — 38 passed
  • tsc --noEmit — exit 0
  • oxlint --type-aware on changed files — 0 warnings/errors

Closes #2046

…rg-wide (#2046)

Switching a project's owning team to "Org-wide" left sharedWithTeamIds
intact, so getProjectTeamIds() still returned those teams and the project
stayed team-restricted even though the Sharing Select, overview header and
projects table all reported "Org-wide". The orphaned shares were also
unreachable from the UI (the "Also shared with" control is hidden without
an owning team).

A shared-with team is always additional to an owning team, so a project
with no owning team cannot retain shares. Fix on both layers:

- Server: add normalizeSharing() and apply it in updateProjectSharing so
  an effective owning team of null clears sharedWithTeamIds. This is the
  authoritative backstop regardless of caller.
- Client: handleOwningTeamChange clears the shared list when the owning
  team becomes "Org-wide" instead of filtering by a null id (which never
  matched), keeping the optimistic UI consistent.

Now "Org-wide" genuinely means org-wide and effective access matches the
displayed visibility.

Closes #2046
@larryro

larryro commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Desk Review — Issue #2046 (orphaned sharedWithTeamIds when a project goes Org-wide)

Verdict: READY TO MERGE.

CI

All required checks pass (Type check, Lint, Format, Unit, Build platform/convex, all 16 Playwright platform shards, UI, Browser, Migrations, CodeQL/Opengrep/Trivy scans). Only fork-PR-only and container-test jobs are skipping, which is expected on a same-repo branch. CI is confirmed green.

Tests

Ran the project's own suite from services/platform:
bunx vitest --run --project server convex/projects/ → 38 passed (3 files), including the 30 in access.test.ts with the 5 new normalizeSharing cases. Verified the round-trip test asserting the normalized result satisfies isOrgWideProject / getProjectTeamIds.

What the fix does (and why it's correct)

  • New pure helper normalizeSharing(teamId, sharedWithTeamIds) in convex/projects/access.ts returns {teamId:null, sharedWithTeamIds:[]} when there is no owning team, else passes through. This makes "Org-wide" genuinely org-wide so effective access (getProjectTeamIds → [], isOrgWideProject → true) matches the displayed visibility — exactly the resolution option (1) the issue called for.
  • Server updateProjectSharing resolves requested shares (falling back to stored shares when the arg is omitted), normalizes, then writes a single declarative patch and logs accurate nowOrgWide audit metadata.
  • Client handleOwningTeamChange mirrors the rule: clears all shares on the Org-wide transition, otherwise filters out the new owning team.

Walked every arg combination (teamId omitted/null/set × shares omitted/empty/non-empty). The reproduction path (Team A → Org-wide with sharedWithTeamIds=[B]) now persists {teamId:undefined, sharedWithTeamIds:undefined}. validateSharing still runs before normalization; db.patch is a shallow merge so always-writing the two fields does not disturb others. No regression: changing only the owner preserves existing shares; updating only shares preserves the owner.

Non-blocking observations (not required for merge)

  1. createProject / duplicateProject do not call normalizeSharing (mutations.ts:338, :1470). A direct programmatic API call to createProject with teamId omitted + non-empty sharedWithTeamIds could persist the same orphaned shape, and duplicateProject copies source sharing verbatim. Neither is reachable from the create UI and both are pre-existing — outside this issue's scope — but applying normalizeSharing there too would close the class entirely (defense-in-depth).
  2. Legacy already-orphaned rows (created before this fix) are not back-filled; they self-heal on the next sharing write but the multiselect guard (teamId && …) still hides their shares until then. No migration is included; the issue did not require one.
  3. No mutation-level or component test. Only the pure helper is unit-tested; the mutation's arg-omitted fallback / audit-metadata branches and the client handleOwningTeamChange are exercised only indirectly. Acceptable given the semantic rule lives entirely in the tested helper, but a convex-test mutation test would guard against future regressions.

These are improvements, not blockers. The change is minimal, follows repo conventions, comments are accurate, and it genuinely fixes the reported bug.

@yannickmonney
yannickmonney merged commit fd63ae8 into main Jun 29, 2026
84 of 87 checks passed
@yannickmonney
yannickmonney deleted the tale/xs71nmx0mdrtwjvcey44r0rdrn89ejbf branch June 29, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Switching a project's owning team to "Org-wide" orphans sharedWithTeamIds — project stays team-restricted while the UI shows "Org-wide"

2 participants