4
4
* See License-AGPL.txt in the project root for license information.
5
5
*/
6
6
7
- import { DBWithTracing , TracedWorkspaceDB , WorkspaceDB , ProjectDB } from '@gitpod/gitpod-db/lib' ;
7
+ import { DBWithTracing , TracedWorkspaceDB , WorkspaceDB , ProjectDB , TeamDB } from '@gitpod/gitpod-db/lib' ;
8
8
import { AdditionalContentContext , CommitContext , IssueContext , PullRequestContext , Repository , SnapshotContext , User , Workspace , WorkspaceConfig , WorkspaceContext , WorkspaceProbeContext } from '@gitpod/gitpod-protocol' ;
9
9
import { ErrorCodes } from '@gitpod/gitpod-protocol/lib/messaging/error' ;
10
10
import { generateWorkspaceID } from '@gitpod/gitpod-protocol/lib/util/generate-workspace-id' ;
@@ -20,6 +20,7 @@ export class WorkspaceFactory {
20
20
21
21
@inject ( TracedWorkspaceDB ) protected readonly db : DBWithTracing < WorkspaceDB > ;
22
22
@inject ( ProjectDB ) protected readonly projectDB : ProjectDB ;
23
+ @inject ( TeamDB ) protected readonly teamDB : TeamDB ;
23
24
@inject ( ConfigProvider ) protected configProvider : ConfigProvider ;
24
25
@inject ( ImageSourceProvider ) protected imageSourceProvider : ImageSourceProvider ;
25
26
@@ -152,13 +153,26 @@ export class WorkspaceFactory {
152
153
}
153
154
}
154
155
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
+
155
169
const id = await generateWorkspaceID ( ) ;
156
170
const newWs : Workspace = {
157
171
id,
158
172
type : "regular" ,
159
173
creationTime : new Date ( ) . toISOString ( ) ,
160
174
contextURL : normalizedContextURL ,
161
- projectId : project ?. id ,
175
+ projectId,
162
176
description : this . getDescription ( context ) ,
163
177
ownerId : user . id ,
164
178
context,
0 commit comments