Skip to content

Commit 95317e9

Browse files
committed
fix
1 parent 3eb4df7 commit 95317e9

File tree

2 files changed

+76
-340
lines changed

2 files changed

+76
-340
lines changed

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

Lines changed: 0 additions & 326 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import { ResponseError } from "vscode-jsonrpc";
3939
import {
4040
AdmissionLevel,
4141
ControlAdmissionRequest,
42-
StopWorkspacePolicy,
4342
DescribeWorkspaceRequest,
4443
SetTimeoutRequest,
4544
} from "@gitpod/ws-manager/lib";
@@ -358,331 +357,6 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
358357
});
359358
}
360359

361-
async adminGetUsers(ctx: TraceContext, req: AdminGetListRequest<User>): Promise<AdminGetListResult<User>> {
362-
traceAPIParams(ctx, { req: censor(req, "searchTerm") }); // searchTerm may contain PII
363-
364-
await this.guardAdminAccess("adminGetUsers", { req }, Permission.ADMIN_USERS);
365-
366-
try {
367-
const res = await this.userDB.findAllUsers(
368-
req.offset,
369-
req.limit,
370-
req.orderBy,
371-
req.orderDir === "asc" ? "ASC" : "DESC",
372-
req.searchTerm,
373-
);
374-
res.rows = res.rows.map(this.censorUser);
375-
return res;
376-
} catch (e) {
377-
throw new ResponseError(ErrorCodes.INTERNAL_SERVER_ERROR, e.toString());
378-
}
379-
}
380-
381-
async adminGetUser(ctx: TraceContext, userId: string): Promise<User> {
382-
traceAPIParams(ctx, { userId });
383-
384-
await this.guardAdminAccess("adminGetUser", { id: userId }, Permission.ADMIN_USERS);
385-
386-
let result: User | undefined;
387-
try {
388-
result = await this.userDB.findUserById(userId);
389-
} catch (e) {
390-
throw new ResponseError(ErrorCodes.INTERNAL_SERVER_ERROR, e.toString());
391-
}
392-
393-
if (!result) {
394-
throw new ResponseError(ErrorCodes.NOT_FOUND, "not found");
395-
}
396-
return this.censorUser(result);
397-
}
398-
399-
async adminBlockUser(ctx: TraceContext, req: AdminBlockUserRequest): Promise<User> {
400-
traceAPIParams(ctx, { req });
401-
402-
await this.guardAdminAccess("adminBlockUser", { req }, Permission.ADMIN_USERS);
403-
404-
const targetUser = await this.userService.blockUser(req.id, req.blocked);
405-
406-
const stoppedWorkspaces = await this.workspaceStarter.stopRunningWorkspacesForUser(
407-
ctx,
408-
req.id,
409-
"user blocked by admin",
410-
StopWorkspacePolicy.IMMEDIATELY,
411-
);
412-
413-
log.info(`Stopped ${stoppedWorkspaces.length} workspaces in response to admin initiated block.`, {
414-
userId: targetUser.id,
415-
workspaceIds: stoppedWorkspaces.map((w) => w.id),
416-
});
417-
418-
// For some reason, returning the result of `this.userDB.storeUser(target)` does not work. The response never arrives the caller.
419-
// Returning `target` instead (which should be equivalent).
420-
return this.censorUser(targetUser);
421-
}
422-
423-
async adminVerifyUser(ctx: TraceContext, userId: string): Promise<User> {
424-
await this.guardAdminAccess("adminVerifyUser", { id: userId }, Permission.ADMIN_USERS);
425-
try {
426-
const user = await this.userDB.findUserById(userId);
427-
if (!user) {
428-
throw new ResponseError(ErrorCodes.NOT_FOUND, `No user with id ${userId} found.`);
429-
}
430-
this.verificationService.markVerified(user);
431-
await this.userDB.updateUserPartial(user);
432-
return user;
433-
} catch (e) {
434-
throw new ResponseError(ErrorCodes.INTERNAL_SERVER_ERROR, e.toString());
435-
}
436-
}
437-
438-
async adminDeleteUser(ctx: TraceContext, userId: string): Promise<void> {
439-
traceAPIParams(ctx, { userId });
440-
441-
await this.guardAdminAccess("adminDeleteUser", { id: userId }, Permission.ADMIN_USERS);
442-
443-
try {
444-
await this.userDeletionService.deleteUser(userId);
445-
} catch (e) {
446-
throw new ResponseError(ErrorCodes.INTERNAL_SERVER_ERROR, e.toString());
447-
}
448-
}
449-
450-
async adminGetBlockedRepositories(
451-
ctx: TraceContext,
452-
req: AdminGetListRequest<BlockedRepository>,
453-
): Promise<AdminGetListResult<BlockedRepository>> {
454-
traceAPIParams(ctx, { req: censor(req, "searchTerm") }); // searchTerm may contain PII
455-
456-
await this.guardAdminAccess("adminGetBlockedRepositories", { req }, Permission.ADMIN_USERS);
457-
458-
try {
459-
const res = await this.blockedRepostoryDB.findAllBlockedRepositories(
460-
req.offset,
461-
req.limit,
462-
req.orderBy,
463-
req.orderDir === "asc" ? "ASC" : "DESC",
464-
req.searchTerm,
465-
);
466-
return res;
467-
} catch (e) {
468-
throw new ResponseError(ErrorCodes.INTERNAL_SERVER_ERROR, e.toString());
469-
}
470-
}
471-
472-
async adminCreateBlockedRepository(
473-
ctx: TraceContext,
474-
urlRegexp: string,
475-
blockUser: boolean,
476-
): Promise<BlockedRepository> {
477-
traceAPIParams(ctx, { urlRegexp, blockUser });
478-
479-
await this.guardAdminAccess("adminCreateBlockedRepository", { urlRegexp, blockUser }, Permission.ADMIN_USERS);
480-
481-
return await this.blockedRepostoryDB.createBlockedRepository(urlRegexp, blockUser);
482-
}
483-
484-
async adminDeleteBlockedRepository(ctx: TraceContext, id: number): Promise<void> {
485-
traceAPIParams(ctx, { id });
486-
487-
await this.guardAdminAccess("adminDeleteBlockedRepository", { id }, Permission.ADMIN_USERS);
488-
489-
await this.blockedRepostoryDB.deleteBlockedRepository(id);
490-
}
491-
492-
async adminModifyRoleOrPermission(ctx: TraceContext, req: AdminModifyRoleOrPermissionRequest): Promise<User> {
493-
traceAPIParams(ctx, { req });
494-
495-
await this.guardAdminAccess("adminModifyRoleOrPermission", { req }, Permission.ADMIN_USERS);
496-
497-
const target = await this.userDB.findUserById(req.id);
498-
if (!target) {
499-
throw new ResponseError(ErrorCodes.NOT_FOUND, "not found");
500-
}
501-
502-
const rolesOrPermissions = new Set((target.rolesOrPermissions || []) as string[]);
503-
req.rpp.forEach((e) => {
504-
if (e.add) {
505-
rolesOrPermissions.add(e.r as string);
506-
} else {
507-
rolesOrPermissions.delete(e.r as string);
508-
}
509-
});
510-
target.rolesOrPermissions = Array.from(rolesOrPermissions.values()) as RoleOrPermission[];
511-
512-
await this.userDB.storeUser(target);
513-
// For some reason, neither returning the result of `this.userDB.storeUser(target)` nor returning `target` work.
514-
// The response never arrives the caller.
515-
// Returning the following works at the cost of an additional DB query:
516-
return this.censorUser((await this.userDB.findUserById(req.id))!);
517-
}
518-
519-
async adminModifyPermanentWorkspaceFeatureFlag(
520-
ctx: TraceContext,
521-
req: AdminModifyPermanentWorkspaceFeatureFlagRequest,
522-
): Promise<User> {
523-
traceAPIParams(ctx, { req });
524-
525-
await this.guardAdminAccess("adminModifyPermanentWorkspaceFeatureFlag", { req }, Permission.ADMIN_USERS);
526-
const target = await this.userDB.findUserById(req.id);
527-
if (!target) {
528-
throw new ResponseError(ErrorCodes.NOT_FOUND, "not found");
529-
}
530-
531-
const featureSettings: UserFeatureSettings = target.featureFlags || {};
532-
const featureFlags = new Set(featureSettings.permanentWSFeatureFlags || []);
533-
534-
req.changes.forEach((e) => {
535-
if (e.add) {
536-
featureFlags.add(e.featureFlag);
537-
} else {
538-
featureFlags.delete(e.featureFlag);
539-
}
540-
});
541-
featureSettings.permanentWSFeatureFlags = Array.from(featureFlags);
542-
target.featureFlags = featureSettings;
543-
544-
await this.userDB.storeUser(target);
545-
// For some reason, returning the result of `this.userDB.storeUser(target)` does not work. The response never arrives the caller.
546-
// Returning `target` instead (which should be equivalent).
547-
return this.censorUser(target);
548-
}
549-
550-
async adminGetTeamMembers(ctx: TraceContext, teamId: string): Promise<TeamMemberInfo[]> {
551-
await this.guardAdminAccess("adminGetTeamMembers", { teamId }, Permission.ADMIN_WORKSPACES);
552-
553-
const team = await this.teamDB.findTeamById(teamId);
554-
if (!team) {
555-
throw new ResponseError(ErrorCodes.NOT_FOUND, "Team not found");
556-
}
557-
const members = await this.teamDB.findMembersByTeam(team.id);
558-
return members;
559-
}
560-
561-
async adminGetTeams(ctx: TraceContext, req: AdminGetListRequest<Team>): Promise<AdminGetListResult<Team>> {
562-
await this.guardAdminAccess("adminGetTeams", { req }, Permission.ADMIN_WORKSPACES);
563-
564-
return await this.teamDB.findTeams(
565-
req.offset,
566-
req.limit,
567-
req.orderBy,
568-
req.orderDir === "asc" ? "ASC" : "DESC",
569-
req.searchTerm as string,
570-
);
571-
}
572-
573-
async adminGetTeamById(ctx: TraceContext, id: string): Promise<Team | undefined> {
574-
await this.guardAdminAccess("adminGetTeamById", { id }, Permission.ADMIN_WORKSPACES);
575-
return await this.teamDB.findTeamById(id);
576-
}
577-
578-
async adminSetTeamMemberRole(
579-
ctx: TraceContext,
580-
teamId: string,
581-
userId: string,
582-
role: TeamMemberRole,
583-
): Promise<void> {
584-
await this.guardAdminAccess("adminSetTeamMemberRole", { teamId, userId, role }, Permission.ADMIN_WORKSPACES);
585-
return this.teamDB.setTeamMemberRole(userId, teamId, role);
586-
}
587-
588-
async adminGetWorkspaces(
589-
ctx: TraceContext,
590-
req: AdminGetWorkspacesRequest,
591-
): Promise<AdminGetListResult<WorkspaceAndInstance>> {
592-
traceAPIParams(ctx, { req });
593-
594-
await this.guardAdminAccess("adminGetWorkspaces", { req }, Permission.ADMIN_WORKSPACES);
595-
596-
return await this.workspaceDb
597-
.trace(ctx)
598-
.findAllWorkspaceAndInstances(
599-
req.offset,
600-
req.limit,
601-
req.orderBy,
602-
req.orderDir === "asc" ? "ASC" : "DESC",
603-
req,
604-
);
605-
}
606-
607-
async adminGetWorkspace(ctx: TraceContext, workspaceId: string): Promise<WorkspaceAndInstance> {
608-
traceAPIParams(ctx, { workspaceId });
609-
610-
await this.guardAdminAccess("adminGetWorkspace", { id: workspaceId }, Permission.ADMIN_WORKSPACES);
611-
612-
const result = await this.workspaceDb.trace(ctx).findWorkspaceAndInstance(workspaceId);
613-
if (!result) {
614-
throw new ResponseError(ErrorCodes.NOT_FOUND, "not found");
615-
}
616-
return result;
617-
}
618-
619-
async adminGetWorkspaceInstances(ctx: TraceContext, workspaceId: string): Promise<WorkspaceInstance[]> {
620-
traceAPIParams(ctx, { workspaceId });
621-
622-
await this.guardAdminAccess("adminGetWorkspaceInstances", { id: workspaceId }, Permission.ADMIN_WORKSPACES);
623-
624-
const result = await this.workspaceDb.trace(ctx).findInstances(workspaceId);
625-
return result || [];
626-
}
627-
628-
async adminForceStopWorkspace(ctx: TraceContext, workspaceId: string): Promise<void> {
629-
traceAPIParams(ctx, { workspaceId });
630-
631-
await this.guardAdminAccess("adminForceStopWorkspace", { id: workspaceId }, Permission.ADMIN_WORKSPACES);
632-
633-
const workspace = await this.workspaceDb.trace(ctx).findById(workspaceId);
634-
if (workspace) {
635-
await this.internalStopWorkspace(ctx, workspace, "stopped by admin", StopWorkspacePolicy.IMMEDIATELY, true);
636-
}
637-
}
638-
639-
async adminRestoreSoftDeletedWorkspace(ctx: TraceContext, workspaceId: string): Promise<void> {
640-
traceAPIParams(ctx, { workspaceId });
641-
642-
await this.guardAdminAccess(
643-
"adminRestoreSoftDeletedWorkspace",
644-
{ id: workspaceId },
645-
Permission.ADMIN_WORKSPACES,
646-
);
647-
648-
await this.workspaceDb.trace(ctx).transaction(async (db) => {
649-
const ws = await db.findById(workspaceId);
650-
if (!ws) {
651-
throw new ResponseError(ErrorCodes.NOT_FOUND, `No workspace with id '${workspaceId}' found.`);
652-
}
653-
if (!ws.softDeleted) {
654-
return;
655-
}
656-
if (!!ws.contentDeletedTime) {
657-
throw new ResponseError(ErrorCodes.NOT_FOUND, "The workspace content was already garbage-collected.");
658-
}
659-
// @ts-ignore
660-
ws.softDeleted = null;
661-
ws.softDeletedTime = "";
662-
ws.pinned = true;
663-
await db.store(ws);
664-
});
665-
}
666-
667-
async adminGetProjectsBySearchTerm(
668-
ctx: TraceContext,
669-
req: AdminGetListRequest<Project>,
670-
): Promise<AdminGetListResult<Project>> {
671-
await this.guardAdminAccess("adminGetProjectsBySearchTerm", { req }, Permission.ADMIN_PROJECTS);
672-
return await this.projectDB.findProjectsBySearchTerm(
673-
req.offset,
674-
req.limit,
675-
req.orderBy,
676-
req.orderDir === "asc" ? "ASC" : "DESC",
677-
req.searchTerm as string,
678-
);
679-
}
680-
681-
async adminGetProjectById(ctx: TraceContext, id: string): Promise<Project | undefined> {
682-
await this.guardAdminAccess("adminGetProjectById", { id }, Permission.ADMIN_PROJECTS);
683-
return await this.projectDB.findProjectById(id);
684-
}
685-
686360
protected async findPrebuiltWorkspace(
687361
parentCtx: TraceContext,
688362
user: User,

0 commit comments

Comments
 (0)