Skip to content

Commit

Permalink
[old api] Use runWithSubjectId where necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
geropl committed Nov 22, 2023
1 parent 51e5507 commit 1f6dd3b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ import {
suggestionFromUserRepo,
} from "./suggested-repos-sorter";
import { runWithSubjectId } from "../util/request-context";
import { SubjectId } from "../auth/subject-id";

// shortcut
export const traceWI = (ctx: TraceContext, wi: Omit<LogContext, "userId">) => TraceContext.setOWI(ctx, wi); // userId is already taken care of in WebsocketConnectionManager
Expand Down Expand Up @@ -303,17 +304,20 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
}

private async getAccessibleProjects() {
if (!this.userID) {
const userId = this.userID;
if (!userId) {
return [];
}

// update all project this user has access to
const allProjects: Project[] = [];
const teams = await this.organizationService.listOrganizationsByMember(this.userID, this.userID);
for (const team of teams) {
allProjects.push(...(await this.projectsService.getProjects(this.userID, team.id)));
}
return allProjects;
return runWithSubjectId(SubjectId.fromUserId(userId), async () => {
const allProjects: Project[] = [];
const teams = await this.organizationService.listOrganizationsByMember(userId, userId);
for (const team of teams) {
allProjects.push(...(await this.projectsService.getProjects(userId, team.id)));
}
return allProjects;
});
}

private async findPrebuiltWorkspace(
Expand Down Expand Up @@ -397,9 +401,11 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {

private forwardInstanceUpdateToClient(ctx: TraceContext, instance: WorkspaceInstance) {
// gpl: We decided against tracing updates here, because it create far too much noise (cmp. history)
if (this.userID) {
this.workspaceService
.getWorkspace(this.userID, instance.workspaceId)
const userId = this.userID;
if (userId) {
runWithSubjectId(SubjectId.fromUserId(userId), () =>
this.workspaceService.getWorkspace(userId, instance.workspaceId),
)
.then((ws) => {
this.client?.onInstanceUpdate(this.censorInstance(instance));
})
Expand Down

0 comments on commit 1f6dd3b

Please sign in to comment.