Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[projects] associate with a project only if team member #6097

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: second ?. obsolete?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

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