Skip to content

Commit 61cac29

Browse files
committed
[server] Refactor checkUser and checkAndBlockUser: Use arguments.callee.name instead of (mis)typing function names
1 parent 1316b8b commit 61cac29

File tree

2 files changed

+74
-74
lines changed

2 files changed

+74
-74
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
171171
traceWI(ctx, { workspaceId });
172172

173173
this.requireEELicense(Feature.FeatureSetTimeout);
174-
const user = this.checkUser("setWorkspaceTimeout");
174+
const user = this.checkUser(arguments.callee.name);
175175

176176
if (!WorkspaceTimeoutValues.includes(duration)) {
177177
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "Invalid duration")
@@ -222,7 +222,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
222222
// Allowed in the free version, because it is read only.
223223
// this.requireEELicense(Feature.FeatureSetTimeout);
224224

225-
const user = this.checkUser("getWorkspaceTimeout");
225+
const user = this.checkUser(arguments.callee.name);
226226

227227
const canChange = await this.maySetTimeout(user);
228228

@@ -307,7 +307,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
307307
traceWI(ctx, { workspaceId });
308308

309309
this.requireEELicense(Feature.FeatureSnapshot);
310-
const user = this.checkAndBlockUser("takeSnapshot");
310+
const user = this.checkAndBlockUser(arguments.callee.name);
311311

312312
const workspace = await this.guardSnaphotAccess(ctx, user.id, workspaceId);
313313

@@ -360,7 +360,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
360360
traceAPIParams(ctx, { snapshotId });
361361

362362
this.requireEELicense(Feature.FeatureSnapshot);
363-
const user = this.checkAndBlockUser("waitForSnapshot");
363+
const user = this.checkAndBlockUser(arguments.callee.name);
364364

365365
const snapshot = await this.workspaceDb.trace(ctx).findSnapshotById(snapshotId);
366366
if (!snapshot) {
@@ -386,7 +386,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
386386
// Allowed in the free version, because it is read only.
387387
// this.requireEELicense(Feature.FeatureSnapshot);
388388

389-
const user = this.checkAndBlockUser("getSnapshots");
389+
const user = this.checkAndBlockUser(arguments.callee.name);
390390

391391
const workspace = await this.workspaceDb.trace(ctx).findById(workspaceId);
392392
if (!workspace || workspace.ownerId !== user.id) {
@@ -722,7 +722,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
722722

723723
// TODO(gpl) This is not part of our API interface, nor can I find any clients. Remove or re-surrect?
724724
// async getLicenseInfo(ctx: TraceContext): Promise<GetLicenseInfoResult> {
725-
// const user = this.checkAndBlockUser("getLicenseInfo");
725+
// const user = this.checkAndBlockUser(arguments.callee.name);
726726

727727
// const { key } = await this.licenseKeySource.getKey();
728728
// const { validUntil, seats } = this.licenseEvaluator.inspect();
@@ -744,7 +744,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
744744
async licenseIncludesFeature(ctx: TraceContext, licenseFeature: LicenseFeature): Promise<boolean> {
745745
traceAPIParams(ctx, { licenseFeature });
746746

747-
this.checkAndBlockUser("licenseIncludesFeature");
747+
this.checkAndBlockUser(arguments.callee.name);
748748

749749
let feature: Feature | undefined;
750750
switch (licenseFeature) {
@@ -763,13 +763,13 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
763763
public async getAccountStatement(ctx: TraceContext, options: GitpodServer.GetAccountStatementOptions): Promise<AccountStatement> {
764764
traceAPIParams(ctx, { options });
765765

766-
const user = this.checkUser("getAccountStatement");
766+
const user = this.checkUser(arguments.callee.name);
767767
const now = options.date || new Date().toISOString();
768768
return this.accountStatementProvider.getAccountStatement(user.id, now);
769769
}
770770

771771
public async getRemainingUsageHours(ctx: TraceContext): Promise<number> {
772-
const user = this.checkUser("getRemainingUsageHours");
772+
const user = this.checkUser(arguments.callee.name);
773773
const runningInstancesPromise = this.workspaceDb.trace(ctx).findRegularRunningInstances(user.id);
774774
return this.accountStatementProvider.getRemainingUsageHours(user.id, new Date().toISOString(), runningInstancesPromise);
775775
}
@@ -798,7 +798,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
798798
}
799799

800800
public async isStudent(ctx: TraceContext): Promise<boolean> {
801-
const user = this.checkUser("isStudent");
801+
const user = this.checkUser(arguments.callee.name);
802802
return this.eligibilityService.isStudent(user);
803803
}
804804

@@ -1342,7 +1342,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
13421342
async adminGetAccountStatement(ctx: TraceContext, userId: string): Promise<AccountStatement> {
13431343
traceAPIParams(ctx, { userId });
13441344

1345-
const user = this.checkAndBlockUser("adminGetAccountStatement");
1345+
const user = this.checkAndBlockUser(arguments.callee.name);
13461346
if (!this.authorizationService.hasPermission(user, Permission.ADMIN_USERS)) {
13471347
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "not allowed");
13481348
}
@@ -1353,7 +1353,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
13531353
async adminSetProfessionalOpenSource(ctx: TraceContext, userId: string, shouldGetProfOSS: boolean): Promise<void> {
13541354
traceAPIParams(ctx, { userId, shouldGetProfOSS });
13551355

1356-
const user = this.checkAndBlockUser("adminSetProfessionalOpenSource");
1356+
const user = this.checkAndBlockUser(arguments.callee.name);
13571357
if (!this.authorizationService.hasPermission(user, Permission.ADMIN_USERS)) {
13581358
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "not allowed");
13591359
}
@@ -1368,7 +1368,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
13681368
async adminIsStudent(ctx: TraceContext, userId: string): Promise<boolean> {
13691369
traceAPIParams(ctx, { userId });
13701370

1371-
const user = this.checkAndBlockUser("adminIsStudent");
1371+
const user = this.checkAndBlockUser(arguments.callee.name);
13721372
if (!this.authorizationService.hasPermission(user, Permission.ADMIN_USERS)) {
13731373
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "not allowed");
13741374
}
@@ -1379,7 +1379,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
13791379
async adminAddStudentEmailDomain(ctx: TraceContext, userId: string, domain: string): Promise<void> {
13801380
traceAPIParams(ctx, { userId, domain });
13811381

1382-
const user = this.checkAndBlockUser("adminAddStudentEmailDomain");
1382+
const user = this.checkAndBlockUser(arguments.callee.name);
13831383
if (!this.authorizationService.hasPermission(user, Permission.ADMIN_USERS)) {
13841384
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "not allowed");
13851385
}
@@ -1393,7 +1393,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
13931393
async adminGrantExtraHours(ctx: TraceContext, userId: string, extraHours: number): Promise<void> {
13941394
traceAPIParams(ctx, { userId, extraHours });
13951395

1396-
const user = this.checkAndBlockUser("adminGrantExtraHours");
1396+
const user = this.checkAndBlockUser(arguments.callee.name);
13971397
if (!this.authorizationService.hasPermission(user, Permission.ADMIN_USERS)) {
13981398
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "not allowed");
13991399
}
@@ -1405,7 +1405,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
14051405
async sendFeedback(ctx: TraceContext, feedback: string): Promise<string | undefined> {
14061406
traceAPIParams(ctx, { }); // feedback is not interesting here, any may contain names
14071407

1408-
const user = this.checkUser("sendFeedback");
1408+
const user = this.checkUser(arguments.callee.name);
14091409
const now = new Date().toISOString();
14101410
const remainingUsageHours = await this.getRemainingUsageHours(ctx);
14111411
const stillEnoughCredits = remainingUsageHours > Math.max(...Accounting.LOW_CREDIT_WARNINGS_IN_HOURS);
@@ -1421,7 +1421,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
14211421
async getProviderRepositoriesForUser(ctx: TraceContext, params: { provider: string, hints?: object }): Promise<ProviderRepository[]> {
14221422
traceAPIParams(ctx, { params });
14231423

1424-
const user = this.checkAndBlockUser("getProviderRepositoriesForUser");
1424+
const user = this.checkAndBlockUser(arguments.callee.name);
14251425

14261426
const repositories: ProviderRepository[] = [];
14271427
const providerHost = params.provider;
@@ -1445,7 +1445,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
14451445
async triggerPrebuild(ctx: TraceContext, projectId: string, branchName: string | null): Promise<StartPrebuildResult> {
14461446
traceAPIParams(ctx, { projectId, branchName });
14471447

1448-
const user = this.checkAndBlockUser("triggerPrebuild");
1448+
const user = this.checkAndBlockUser(arguments.callee.name);
14491449

14501450
const project = await this.projectsService.getProject(projectId);
14511451
if (!project) {
@@ -1491,7 +1491,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
14911491
async cancelPrebuild(ctx: TraceContext, projectId: string, prebuildId: string): Promise<void> {
14921492
traceAPIParams(ctx, { projectId, prebuildId });
14931493

1494-
const user = this.checkAndBlockUser("cancelPrebuild");
1494+
const user = this.checkAndBlockUser(arguments.callee.name);
14951495

14961496
const project = await this.projectsService.getProject(projectId);
14971497
if (!project) {

0 commit comments

Comments
 (0)