-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
user-service.ts
64 lines (48 loc) · 2.43 KB
/
user-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
* Licensed under the Gitpod Enterprise Source Code License,
* See License.enterprise.txt in the project root folder.
*/
import { UserService, CheckSignUpParams, CheckTermsParams } from "../../../src/user/user-service";
import { User, WorkspaceTimeoutDuration } from "@gitpod/gitpod-protocol";
import { inject } from "inversify";
import { LicenseEvaluator } from "@gitpod/licensor/lib";
import { Feature } from "@gitpod/licensor/lib/api";
import { AuthException } from "../../../src/auth/errors";
import { EligibilityService } from "./eligibility-service";
export class UserServiceEE extends UserService {
@inject(LicenseEvaluator) protected readonly licenseEvaluator: LicenseEvaluator;
@inject(EligibilityService) protected readonly eligibilityService: EligibilityService;
async getDefaultWorkspaceTimeout(user: User, date: Date): Promise<WorkspaceTimeoutDuration> {
// todo@at: how to select the timeout for SaaS?
// return this.eligibilityService.getDefaultWorkspaceTimeout(user, date);
if (!this.licenseEvaluator.isEnabled(Feature.FeatureSetTimeout)) {
return "30m";
}
return "60m";
}
async checkSignUp(params: CheckSignUpParams) {
// todo@at: check if we need an optimization for SaaS here. used to be a no-op there.
// 1. check the license
const userCount = await this.userDb.getUserCount(true);
if (!this.licenseEvaluator.hasEnoughSeats(userCount)) {
const msg = `Maximum number of users permitted by the license exceeded`;
throw AuthException.create("Cannot sign up", msg, { userCount, params });
}
// 2. check defaults
await super.checkSignUp(params);
}
async checkTermsAcceptanceRequired(params: CheckTermsParams): Promise<boolean> {
///////////////////////////////////////////////////////////////////////////
// Currently, we don't check for ToS on login.
///////////////////////////////////////////////////////////////////////////
return false;
}
async checkTermsAccepted(user: User) {
// called from GitpodServer implementation
///////////////////////////////////////////////////////////////////////////
// Currently, we don't check for ToS on Gitpod API calls.
///////////////////////////////////////////////////////////////////////////
return true;
}
}