Skip to content

Commit 9d2d729

Browse files
authored
[server] Implement tsAddMembersToOrg (#16638)
1 parent 32adcb9 commit 9d2d729

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
278278
tsReassignSlot(teamSubscriptionId: string, teamSubscriptionSlotId: string, newIdentityStr: string): Promise<void>;
279279
tsDeactivateSlot(teamSubscriptionId: string, teamSubscriptionSlotId: string): Promise<void>;
280280
tsReactivateSlot(teamSubscriptionId: string, teamSubscriptionSlotId: string): Promise<void>;
281+
tsAddMembersToOrg(teamSubscriptionId: string, organizationId: string): Promise<void>;
281282

282283
getGithubUpgradeUrls(): Promise<GithubUpgradeURL[]>;
283284

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,45 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
17311731
return this.teamSubscriptionService.findTeamSubscriptionSlotsBy(user.id, new Date());
17321732
}
17331733

1734+
async tsAddMembersToOrg(ctx: TraceContext, teamSubscriptionId: string, organizationId: string): Promise<void> {
1735+
const user = this.checkUser("tsAddMembersToOrg");
1736+
1737+
// Add logging to help us identify trouble with this operation very easily
1738+
try {
1739+
log.info({ userId: user.id }, "tsAddMembersToOrg: Started", { teamSubscriptionId, organizationId });
1740+
1741+
// TeamSubscription
1742+
const ts = await this.teamSubscriptionDB.findTeamSubscriptionById(teamSubscriptionId);
1743+
if (!ts || ts.userId !== user.id) {
1744+
throw new ResponseError(ErrorCodes.NOT_FOUND, "Cannot find TeamSubscription");
1745+
}
1746+
1747+
// Organization
1748+
const { team, members } = await this.guardTeamOperation(organizationId, "update", "org_write");
1749+
const teamOwner = members.find((m) => m.userId === user.id && m.role === "owner");
1750+
if (!teamOwner) {
1751+
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "You are not an owner of this Organization");
1752+
}
1753+
1754+
// Take all slots, identify the members, and add to the Organization
1755+
const slots = await this.teamSubscriptionDB.findSlotsByTeamSubscriptionId(teamSubscriptionId);
1756+
const adds = [];
1757+
for (const slot of slots) {
1758+
if (!slot.assigneeId) {
1759+
// Totally ok, it's just not assigned atm.
1760+
continue;
1761+
}
1762+
adds.push(this.teamDB.addMemberToTeam(slot.assigneeId, team.id));
1763+
}
1764+
await Promise.all(adds);
1765+
1766+
log.info({ userId: user.id }, "tsAddMembersToOrg: DONE", { teamSubscriptionId, organizationId });
1767+
} catch (err) {
1768+
log.error({ userId: user.id }, "tsAddMembersToOrg: ERROR", err, { teamSubscriptionId, organizationId });
1769+
throw err;
1770+
}
1771+
}
1772+
17341773
async tsGetUnassignedSlot(
17351774
ctx: TraceContext,
17361775
teamSubscriptionId: string,

components/server/src/auth/rate-limiter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ const defaultFunctions: FunctionsConfig = {
221221
listUsage: { group: "default", points: 1 },
222222
getBillingModeForTeam: { group: "default", points: 1 },
223223
getBillingModeForUser: { group: "default", points: 1 },
224+
tsAddMembersToOrg: { group: "default", points: 1 },
224225

225226
trackEvent: { group: "default", points: 1 },
226227
trackLocation: { group: "default", points: 1 },

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,6 +3403,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
34033403
async tsGetSlots(ctx: TraceContext): Promise<TeamSubscriptionSlotResolved[]> {
34043404
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
34053405
}
3406+
async tsAddMembersToOrg(ctx: TraceContext, teamSubscriptionId: string, organizationId: string): Promise<void> {
3407+
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
3408+
}
34063409
async tsGetUnassignedSlot(
34073410
ctx: TraceContext,
34083411
teamSubscriptionId: string,

0 commit comments

Comments
 (0)