Skip to content

Commit

Permalink
[projects] associate with a project only if team member
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTugarev authored and roboquat committed Oct 7, 2021
1 parent 4fbc6a9 commit 811a6af
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions components/server/src/workspace/workspace-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License-AGPL.txt in the project root for license information.
*/

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

@inject(TracedWorkspaceDB) protected readonly db: DBWithTracing<WorkspaceDB>;
@inject(ProjectDB) protected readonly projectDB: ProjectDB;
@inject(TeamDB) protected readonly teamDB: TeamDB;
@inject(ConfigProvider) protected configProvider: ConfigProvider;
@inject(ImageSourceProvider) protected imageSourceProvider: ImageSourceProvider;

Expand Down Expand Up @@ -152,13 +153,26 @@ export class WorkspaceFactory {
}
}

let projectId: string | undefined;
// associate with a project, if it's the personal project of the current user
if (project?.userId && project?.userId === user.id) {
projectId = project.id;
}
// associate with a project, if the current user is a team member
if (project?.teamId) {
const teams = await this.teamDB.findTeamsByUser(user.id);
if (teams.some(t => t.id === project?.teamId)) {
projectId = project.id;
}
}

const id = await generateWorkspaceID();
const newWs: Workspace = {
id,
type: "regular",
creationTime: new Date().toISOString(),
contextURL: normalizedContextURL,
projectId: project?.id,
projectId,
description: this.getDescription(context),
ownerId: user.id,
context,
Expand Down

0 comments on commit 811a6af

Please sign in to comment.