File tree 4 files changed +48
-1
lines changed
4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -247,6 +247,27 @@ export class EligibilityService {
247
247
return subscriptions . filter ( s => eligblePlans . includes ( s . planId ! ) ) . length > 0 ;
248
248
}
249
249
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
+
250
271
protected async getUser ( user : User | string ) : Promise < User > {
251
272
if ( typeof user === 'string' ) {
252
273
const realUser = await this . userDb . findUserById ( user ) ;
Original file line number Diff line number Diff line change @@ -36,6 +36,14 @@ export class UserServiceEE extends UserService {
36
36
return "60m" ;
37
37
}
38
38
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
+
39
47
async checkSignUp ( params : CheckSignUpParams ) {
40
48
41
49
// todo@at : check if we need an optimization for SaaS here. used to be a no-op there.
Original file line number Diff line number Diff line change @@ -158,6 +158,17 @@ export class UserService {
158
158
return "30m" ;
159
159
}
160
160
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
+
161
172
/**
162
173
* This might throw `AuthException`s.
163
174
*
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import { EnvVarWithValue } from "@gitpod/gitpod-protocol/src/protocol";
35
35
import { WithReferrerContext } from "@gitpod/gitpod-protocol/lib/protocol" ;
36
36
import { IDEOption } from "@gitpod/gitpod-protocol/lib/ide-protocol" ;
37
37
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred" ;
38
+ import { ExtendedUser } from "@gitpod/ws-manager/lib/constraints" ;
38
39
39
40
export interface StartWorkspaceOptions {
40
41
rethrow ?: boolean ;
@@ -174,10 +175,16 @@ export class WorkspaceStarter {
174
175
startRequest . setSpec ( spec ) ;
175
176
startRequest . setServicePrefix ( workspace . id ) ;
176
177
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
+
177
184
// tell the world we're starting this instance
178
185
let resp : StartWorkspaceResponse . AsObject | undefined ;
179
186
let lastInstallation = "" ;
180
- const clusters = await this . clientProvider . getStartClusterSets ( user , workspace , instance ) ;
187
+ const clusters = await this . clientProvider . getStartClusterSets ( euser , workspace , instance ) ;
181
188
for await ( let cluster of clusters ) {
182
189
try {
183
190
// getStartManager will throw an exception if there's no cluster available and hence exit the loop
You can’t perform that action at this time.
0 commit comments