Repository navigation
fix(teams): hold the last-owner rule for every caller - #15153
Conversation
…wner's session The console last-owner check compared the caller with the target membership, so an API key (whose user has no sequence) could demote or remove the only owner. It also counted pending owner invites, letting the sole confirmed owner leave while an invite was unanswered. Check the target membership instead, count confirmed owners only, and recount after the write in the same transaction so the refused change rolls back as a whole.
🟢 Tier S · Ready to mergeFor console teams, membership role updates and deletions now preserve at least one confirmed owner regardless of caller, counting only confirmed owner memberships and serializing guarded changes with a team-row lock. The E2E coverage verifies that pending invitations do not satisfy the owner rule and that concurrent owner removals leave one confirmed owner. Latest changes: The latest commits add an E2E race between an owner's demotion and another owner's departure, and relax the persisted-role assertion to check that the owner role remains present.
📂 Walkthrough · 3
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
There was a problem hiding this comment.
This PR strengthens team membership guards so the last confirmed owner of a team cannot be deleted or demoted, wrapping the membership write plus the owner-count check in a transaction on console projects, and adds e2e coverage.
Key findings
- 🟡 Last-owner guard races: count is not serialized across requests — Delete.php:105
Two requests demoting or removing different owners each counted the other as still present and both committed. Locking the team row first makes the second wait and count the first's change.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The findings that requested changes are resolved. See the summary comment for what is still open.
The creator's membership carries the team's default roles alongside owner, so assert owner is kept rather than the exact list.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
The change hardens the Teams membership
Reviewed commit: 31ab407 |
What does this PR do?
The console "at least one owner" rule was tied to the caller, not the target membership:
An API key's user has no sequence, so a key could demote or delete the only owner. The count also included pending owner invites, so the sole confirmed owner could leave while an invite was unanswered.
Now, for console teams,
PATCH/DELETE /v1/teams/:teamId/memberships/:membershipId:owner), whoever callsconfirm = trueowners onlyTest Plan
TeamsConsoleClientTest::testPendingOwnerInviteDoesNotCountAsAnOwner: sole owner + pending owner invite → demote and leave both 400, owner keepsowner, invite still revocable. Old code returns 200 here.TeamsConsoleClientTest/TeamsBaseunchanged.Related PRs and Issues
None.
Checklist
Related: appwrite-labs/cloud#6666