Skip to content

Commit

Permalink
[server] Prevent changing role for teams of size 1
Browse files Browse the repository at this point in the history
  • Loading branch information
easyCZ committed Oct 11, 2022
1 parent f668ab4 commit 9d221cc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions components/gitpod-db/src/typeorm/team-db-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ export class TeamDBImpl implements TeamDB {
throw new ResponseError(ErrorCodes.NOT_FOUND, "A team with this ID could not be found");
}
const membershipRepo = await this.getMembershipRepo();

if (role != "owner") {
const ownerCount = await membershipRepo.count({
teamId,
role: "owner",
deleted: false,
});
if (ownerCount <= 1) {
throw new ResponseError(ErrorCodes.CONFLICT, "Team must retain at least one owner");
}
}

const membership = await membershipRepo.findOne({ teamId, userId, deleted: false });
if (!membership) {
throw new ResponseError(ErrorCodes.NOT_FOUND, "The user is not currently a member of this team");
Expand Down

0 comments on commit 9d221cc

Please sign in to comment.