Skip to content

Commit 811a6af

Browse files
AlexTugarevroboquat
authored andcommitted
[projects] associate with a project only if team member
1 parent 4fbc6a9 commit 811a6af

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

components/server/src/workspace/workspace-factory.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See License-AGPL.txt in the project root for license information.
55
*/
66

7-
import { DBWithTracing, TracedWorkspaceDB, WorkspaceDB, ProjectDB } from '@gitpod/gitpod-db/lib';
7+
import { DBWithTracing, TracedWorkspaceDB, WorkspaceDB, ProjectDB, TeamDB } from '@gitpod/gitpod-db/lib';
88
import { AdditionalContentContext, CommitContext, IssueContext, PullRequestContext, Repository, SnapshotContext, User, Workspace, WorkspaceConfig, WorkspaceContext, WorkspaceProbeContext } from '@gitpod/gitpod-protocol';
99
import { ErrorCodes } from '@gitpod/gitpod-protocol/lib/messaging/error';
1010
import { generateWorkspaceID } from '@gitpod/gitpod-protocol/lib/util/generate-workspace-id';
@@ -20,6 +20,7 @@ export class WorkspaceFactory {
2020

2121
@inject(TracedWorkspaceDB) protected readonly db: DBWithTracing<WorkspaceDB>;
2222
@inject(ProjectDB) protected readonly projectDB: ProjectDB;
23+
@inject(TeamDB) protected readonly teamDB: TeamDB;
2324
@inject(ConfigProvider) protected configProvider: ConfigProvider;
2425
@inject(ImageSourceProvider) protected imageSourceProvider: ImageSourceProvider;
2526

@@ -152,13 +153,26 @@ export class WorkspaceFactory {
152153
}
153154
}
154155

156+
let projectId: string | undefined;
157+
// associate with a project, if it's the personal project of the current user
158+
if (project?.userId && project?.userId === user.id) {
159+
projectId = project.id;
160+
}
161+
// associate with a project, if the current user is a team member
162+
if (project?.teamId) {
163+
const teams = await this.teamDB.findTeamsByUser(user.id);
164+
if (teams.some(t => t.id === project?.teamId)) {
165+
projectId = project.id;
166+
}
167+
}
168+
155169
const id = await generateWorkspaceID();
156170
const newWs: Workspace = {
157171
id,
158172
type: "regular",
159173
creationTime: new Date().toISOString(),
160174
contextURL: normalizedContextURL,
161-
projectId: project?.id,
175+
projectId,
162176
description: this.getDescription(context),
163177
ownerId: user.id,
164178
context,

0 commit comments

Comments
 (0)