Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
next steps:
 - convert all calls with SYSTEM_USER(_ID) to runWithRequestContext
 - think about converting tests
  • Loading branch information
geropl committed Nov 7, 2023
1 parent e2d9077 commit 772a49f
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 110 deletions.
6 changes: 3 additions & 3 deletions components/server/src/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import {
} from "@gitpod/public-api/lib/gitpod/experimental/v1/user_pb";
import { UserAuthentication } from "../user/user-authentication";
import { WorkspaceService } from "../workspace/workspace-service";
import { SYSTEM_USER } from "../authorization/authorizer";
import { validate } from "uuid";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
import { StopWorkspacePolicy } from "@gitpod/ws-manager/lib";
import { SYSTEM_USER_ID } from "../authorization/authorizer";

@injectable()
export class APIUserService implements ServiceImpl<typeof UserServiceInterface> {
Expand Down Expand Up @@ -76,15 +76,15 @@ export class APIUserService implements ServiceImpl<typeof UserServiceInterface>
const trace = {};
// TODO for now we use SYSTEM_USER, since it is only called by internal componenets like usage
// and not exposed publically, but there should be better way to get an authenticated user
await this.userService.blockUser(SYSTEM_USER, userId, true);
await this.userService.blockUser(SYSTEM_USER_ID, userId, true);
log.info(`Blocked user ${userId}.`, {
userId,
reason,
});

const stoppedWorkspaces = await this.workspaceService.stopRunningWorkspacesForUser(
trace,
SYSTEM_USER,
SYSTEM_USER_ID,
userId,
reason,
StopWorkspacePolicy.IMMEDIATELY,
Expand Down
17 changes: 0 additions & 17 deletions components/server/src/auth/subject-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,11 @@ export class SubjectId implements ISubjectId {
}
}

/**
* A helper method meant for backwards compatibility with the old userId.
* @param subjectId
* @returns
* @deprecated Because we should not rely on the userId anymore.
*/
export function toUserId(subjectId: string | SubjectId | undefined): string | undefined {
if (!subjectId) {
return undefined;
}
if (typeof subjectId === "string") {
return subjectId;
}
return subjectId.userId();
}

// The following codes is meant for backwards-compatibility with the existing express types, or other code, that relies on `userId: string` or `User`
/**
* Interface type meant for backwards compatibility
*/
export type Subject = string | SubjectId;
export type MaybeSubject = Subject | undefined;
export namespace Subject {
export function toId(subject: Subject): SubjectId {
if (SubjectId.is(subject)) {
Expand Down
Loading

0 comments on commit 772a49f

Please sign in to comment.