Skip to content

Commit 9d221cc

Browse files
committed
[server] Prevent changing role for teams of size 1
1 parent f668ab4 commit 9d221cc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: components/gitpod-db/src/typeorm/team-db-impl.ts

+12
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ export class TeamDBImpl implements TeamDB {
203203
throw new ResponseError(ErrorCodes.NOT_FOUND, "A team with this ID could not be found");
204204
}
205205
const membershipRepo = await this.getMembershipRepo();
206+
207+
if (role != "owner") {
208+
const ownerCount = await membershipRepo.count({
209+
teamId,
210+
role: "owner",
211+
deleted: false,
212+
});
213+
if (ownerCount <= 1) {
214+
throw new ResponseError(ErrorCodes.CONFLICT, "Team must retain at least one owner");
215+
}
216+
}
217+
206218
const membership = await membershipRepo.findOne({ teamId, userId, deleted: false });
207219
if (!membership) {
208220
throw new ResponseError(ErrorCodes.NOT_FOUND, "The user is not currently a member of this team");

0 commit comments

Comments
 (0)