Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/gitpod-protocol/src/gitpod-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
tsReassignSlot(teamSubscriptionId: string, teamSubscriptionSlotId: string, newIdentityStr: string): Promise<void>;
tsDeactivateSlot(teamSubscriptionId: string, teamSubscriptionSlotId: string): Promise<void>;
tsReactivateSlot(teamSubscriptionId: string, teamSubscriptionSlotId: string): Promise<void>;
tsAddMembersToOrg(teamSubscriptionId: string, organizationId: string): Promise<void>;

getGithubUpgradeUrls(): Promise<GithubUpgradeURL[]>;

Expand Down
39 changes: 39 additions & 0 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,45 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
return this.teamSubscriptionService.findTeamSubscriptionSlotsBy(user.id, new Date());
}

async tsAddMembersToOrg(ctx: TraceContext, teamSubscriptionId: string, organizationId: string): Promise<void> {
const user = this.checkUser("tsAddMembersToOrg");

// Add logging to help us identify trouble with this operation very easily
try {
log.info({ userId: user.id }, "tsAddMembersToOrg: Started", { teamSubscriptionId, organizationId });

// TeamSubscription
const ts = await this.teamSubscriptionDB.findTeamSubscriptionById(teamSubscriptionId);
if (!ts || ts.userId !== user.id) {
throw new ResponseError(ErrorCodes.NOT_FOUND, "Cannot find TeamSubscription");
}

// Organization
const { team, members } = await this.guardTeamOperation(organizationId, "update", "org_write");
const teamOwner = members.find((m) => m.userId === user.id && m.role === "owner");
if (!teamOwner) {
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "You are not an owner of this Organization");
}

// Take all slots, identify the members, and add to the Organization
const slots = await this.teamSubscriptionDB.findSlotsByTeamSubscriptionId(teamSubscriptionId);
const adds = [];
for (const slot of slots) {
if (!slot.assigneeId) {
// Totally ok, it's just not assigned atm.
continue;
}
adds.push(this.teamDB.addMemberToTeam(slot.assigneeId, team.id));
}
await Promise.all(adds);

log.info({ userId: user.id }, "tsAddMembersToOrg: DONE", { teamSubscriptionId, organizationId });
} catch (err) {
log.error({ userId: user.id }, "tsAddMembersToOrg: ERROR", err, { teamSubscriptionId, organizationId });
throw err;
}
}

async tsGetUnassignedSlot(
ctx: TraceContext,
teamSubscriptionId: string,
Expand Down
1 change: 1 addition & 0 deletions components/server/src/auth/rate-limiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const defaultFunctions: FunctionsConfig = {
listUsage: { group: "default", points: 1 },
getBillingModeForTeam: { group: "default", points: 1 },
getBillingModeForUser: { group: "default", points: 1 },
tsAddMembersToOrg: { group: "default", points: 1 },

trackEvent: { group: "default", points: 1 },
trackLocation: { group: "default", points: 1 },
Expand Down
3 changes: 3 additions & 0 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3403,6 +3403,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
async tsGetSlots(ctx: TraceContext): Promise<TeamSubscriptionSlotResolved[]> {
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
}
async tsAddMembersToOrg(ctx: TraceContext, teamSubscriptionId: string, organizationId: string): Promise<void> {
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
}
async tsGetUnassignedSlot(
ctx: TraceContext,
teamSubscriptionId: string,
Expand Down