Skip to content

Commit 5b74af7

Browse files
csweichelroboquat
authored andcommitted
[server] Tie increased resource access to payment status
1 parent b67e3ec commit 5b74af7

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

components/server/ee/src/user/eligibility-service.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,27 @@ export class EligibilityService {
247247
return subscriptions.filter(s => eligblePlans.includes(s.planId!)).length > 0;
248248
}
249249

250+
/**
251+
* Returns true if the user ought to land on a workspace cluster that provides more resources
252+
* compared to the default case.
253+
*/
254+
async userGetsMoreResources(user: User): Promise<boolean> {
255+
if (!this.config.enablePayment) {
256+
// when payment is disabled users can do everything
257+
return true;
258+
}
259+
260+
const subscriptions = await this.subscriptionService.getNotYetCancelledSubscriptions(user, new Date().toISOString());
261+
const eligblePlans = [
262+
Plans.PROFESSIONAL_EUR,
263+
Plans.PROFESSIONAL_USD,
264+
Plans.TEAM_PROFESSIONAL_EUR,
265+
Plans.TEAM_PROFESSIONAL_USD,
266+
].map(p => p.chargebeeId);
267+
268+
return subscriptions.filter(s => eligblePlans.includes(s.planId!)).length > 0;
269+
}
270+
250271
protected async getUser(user: User | string): Promise<User> {
251272
if (typeof user === 'string') {
252273
const realUser = await this.userDb.findUserById(user);

components/server/ee/src/user/user-service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ export class UserServiceEE extends UserService {
3636
return "60m";
3737
}
3838

39+
async userGetsMoreResources(user: User): Promise<boolean> {
40+
if (this.config.enablePayment) {
41+
return this.eligibilityService.userGetsMoreResources(user);
42+
}
43+
44+
return false;
45+
}
46+
3947
async checkSignUp(params: CheckSignUpParams) {
4048

4149
// todo@at: check if we need an optimization for SaaS here. used to be a no-op there.

components/server/src/user/user-service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ export class UserService {
158158
return "30m";
159159
}
160160

161+
/**
162+
* Returns true if the user ought land in a cluster which offers more resources than
163+
* the default.
164+
*
165+
* @param user user to check for
166+
* @returns
167+
*/
168+
async userGetsMoreResources(user: User): Promise<boolean> {
169+
return false;
170+
}
171+
161172
/**
162173
* This might throw `AuthException`s.
163174
*

components/server/src/workspace/workspace-starter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { EnvVarWithValue } from "@gitpod/gitpod-protocol/src/protocol";
3535
import { WithReferrerContext } from "@gitpod/gitpod-protocol/lib/protocol";
3636
import { IDEOption } from "@gitpod/gitpod-protocol/lib/ide-protocol";
3737
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred";
38+
import { ExtendedUser } from "@gitpod/ws-manager/lib/constraints";
3839

3940
export interface StartWorkspaceOptions {
4041
rethrow?: boolean;
@@ -174,10 +175,16 @@ export class WorkspaceStarter {
174175
startRequest.setSpec(spec);
175176
startRequest.setServicePrefix(workspace.id);
176177

178+
// we add additional information to the user to help with cluster selection
179+
const euser: ExtendedUser = {
180+
...user,
181+
getsMoreResources: await this.userService.userGetsMoreResources(user),
182+
}
183+
177184
// tell the world we're starting this instance
178185
let resp: StartWorkspaceResponse.AsObject | undefined;
179186
let lastInstallation = "";
180-
const clusters = await this.clientProvider.getStartClusterSets(user, workspace, instance);
187+
const clusters = await this.clientProvider.getStartClusterSets(euser, workspace, instance);
181188
for await (let cluster of clusters) {
182189
try {
183190
// getStartManager will throw an exception if there's no cluster available and hence exit the loop

0 commit comments

Comments
 (0)