Skip to content

Commit d2b220f

Browse files
authored
[server] remove Project.userId (#18391)
We no longer support user-owned projects. This removes related leftovers.
1 parent 5e7eff4 commit d2b220f

File tree

15 files changed

+47
-106
lines changed

15 files changed

+47
-106
lines changed

components/dashboard/src/admin/ProjectDetail.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,15 @@ export default function ProjectDetail(props: { project: Project; owner: string |
3434
{props.project.name}
3535
</a>
3636
</Property>
37-
{props.project.userId ? (
38-
<Property name="Owner">
39-
<Link
40-
className="text-blue-400 dark:text-blue-600 hover:text-blue-600 dark:hover:text-blue-400 truncate"
41-
to={"/admin/users/" + props.project.userId}
42-
>
43-
{props.owner}
44-
</Link>
45-
<span className="text-gray-400 dark:text-gray-500"> (User)</span>
46-
</Property>
47-
) : (
48-
<Property name="Owner">
49-
<Link
50-
className="text-blue-400 dark:text-blue-600 hover:text-blue-600 dark:hover:text-blue-400 truncate"
51-
to={"/admin/orgs/" + props.project.teamId}
52-
>
53-
{props.owner}
54-
</Link>
55-
<span className="text-gray-400 dark:text-gray-500"> (Organization)</span>
56-
</Property>
57-
)}
37+
<Property name="Owner">
38+
<Link
39+
className="text-blue-400 dark:text-blue-600 hover:text-blue-600 dark:hover:text-blue-400 truncate"
40+
to={"/admin/orgs/" + props.project.teamId}
41+
>
42+
{props.owner}
43+
</Link>
44+
<span className="text-gray-400 dark:text-gray-500"> (Organization)</span>
45+
</Property>
5846
</div>
5947
<div className="flex w-full mt-6">
6048
<Property name="Incremental Prebuilds">

components/dashboard/src/admin/ProjectsSearch.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,10 @@ export function ProjectsSearch() {
5757
useEffect(() => {
5858
(async () => {
5959
if (currentProject) {
60-
if (currentProject.userId) {
61-
const owner = await getGitpodService().server.adminGetUser(currentProject.userId);
60+
const owner = await getGitpodService().server.adminGetTeamById(currentProject.teamId);
61+
if (owner) {
6262
setCurrentProjectOwner(owner.name);
6363
}
64-
if (currentProject.teamId) {
65-
const owner = await getGitpodService().server.adminGetTeamById(currentProject.teamId);
66-
if (owner) {
67-
setCurrentProjectOwner(owner.name);
68-
}
69-
}
7064
}
7165
})();
7266
}, [currentProject]);

components/dashboard/src/data/projects/list-projects-query.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,26 @@ import { useCallback } from "react";
1010
import { listAllProjects } from "../../service/public-api";
1111
import { useCurrentOrg } from "../organizations/orgs-query";
1212

13-
type TeamOrUserID = {
14-
teamId?: string;
15-
userId?: string;
16-
};
17-
1813
export type ListProjectsQueryResults = {
1914
projects: Project[];
2015
};
2116

2217
export const useListProjectsQuery = () => {
23-
const team = useCurrentOrg().data;
24-
25-
const teamId = team?.id;
26-
18+
const org = useCurrentOrg().data;
19+
const orgId = org?.id;
2720
return useQuery<ListProjectsQueryResults>({
2821
// Projects are either tied to current team, otherwise current user
29-
queryKey: getListProjectsQueryKey({ teamId }),
22+
queryKey: getListProjectsQueryKey(orgId || ""),
3023
cacheTime: 1000 * 60 * 60 * 1, // 1 hour
3124
queryFn: async () => {
32-
if (!teamId) {
25+
if (!orgId) {
3326
return {
3427
projects: [],
3528
latestPrebuilds: new Map(),
3629
};
3730
}
3831

39-
const projects = await listAllProjects({ teamId });
32+
const projects = await listAllProjects({ orgId });
4033
return {
4134
projects,
4235
};
@@ -49,24 +42,24 @@ export const useRefreshProjects = () => {
4942
const queryClient = useQueryClient();
5043

5144
return useCallback(
52-
({ teamId, userId }: TeamOrUserID) => {
53-
// Don't refetch if no team/user is provided
54-
if (!teamId && !userId) {
45+
(orgId: string) => {
46+
// Don't refetch if no org is provided
47+
if (!orgId) {
5548
return;
5649
}
5750

5851
queryClient.refetchQueries({
59-
queryKey: getListProjectsQueryKey({ teamId, userId }),
52+
queryKey: getListProjectsQueryKey(orgId),
6053
});
6154
},
6255
[queryClient],
6356
);
6457
};
6558

66-
export const getListProjectsQueryKey = ({ teamId, userId }: TeamOrUserID) => {
67-
if (!teamId && !userId) {
68-
throw new Error("Must provide either a teamId or userId for projects query key");
59+
export const getListProjectsQueryKey = (orgId: string) => {
60+
if (!orgId) {
61+
throw new Error("Must provide either an orgId for projects query key");
6962
}
7063

71-
return ["projects", "list", teamId ? { teamId } : { userId }];
64+
return ["projects", "list", { orgId }];
7265
};

components/dashboard/src/projects/NewProject.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export default function NewProject() {
204204
});
205205

206206
// TODO: After converting this to a mutation, we can handle invalidating/updating the query in a side effect
207-
refreshProjects(project.teamId ? { teamId: project.teamId } : { userId: project.userId || "" });
207+
refreshProjects(project.teamId);
208208

209209
setProject(project);
210210
} catch (error) {

components/dashboard/src/projects/project-context.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,10 @@ export function useCurrentProject(): { project: Project | undefined; loading: bo
7171
return;
7272
}
7373
(async () => {
74-
let projects: Project[];
75-
if (!!org.data) {
76-
projects = await listAllProjects({ teamId: org.data?.id });
77-
} else {
78-
projects = await listAllProjects({ userId: user?.id });
74+
if (!org.data) {
75+
return;
7976
}
77+
let projects = await listAllProjects({ orgId: org.data.id });
8078

8179
// Find project matching with slug, otherwise with name
8280
const project = projects.find((p) => Project.slug(p) === slugs.projectSlug);
@@ -86,21 +84,13 @@ export function useCurrentProject(): { project: Project | undefined; loading: bo
8684
if (t.id === org.data?.id) {
8785
continue;
8886
}
89-
const projects = await listAllProjects({ teamId: t.id });
87+
const projects = await listAllProjects({ orgId: t.id });
9088
const project = projects.find((p) => Project.slug(p) === slugs.projectSlug);
9189
if (project) {
9290
// redirect to the other org
9391
history.push(location.pathname + "?org=" + t.id);
9492
}
9593
}
96-
97-
// check personal projects
98-
const projects = await listAllProjects({ userId: user.id });
99-
const project = projects.find((p) => Project.slug(p) === slugs.projectSlug);
100-
if (project) {
101-
// redirect to the other org
102-
history.push(location.pathname + "?org=0");
103-
}
10494
}
10595
setProject(project);
10696
setLoading(false);

components/dashboard/src/service/public-api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ export function publicApiTeamRoleToProtocol(role: TeamRole): TeamMemberRole {
6666
}
6767
}
6868

69-
export async function listAllProjects(opts: { userId?: string; teamId?: string }): Promise<ProtocolProject[]> {
69+
export async function listAllProjects(opts: { orgId: string }): Promise<ProtocolProject[]> {
7070
let pagination = {
7171
page: 1,
7272
pageSize: 100,
7373
};
7474

7575
const response = await projectsService.listProjects({
76-
teamId: opts.teamId,
76+
teamId: opts.orgId,
7777
pagination,
7878
});
7979
const results = response.projects;
@@ -84,7 +84,7 @@ export async function listAllProjects(opts: { userId?: string; teamId?: string }
8484
page: 1 + pagination.page,
8585
};
8686
const response = await projectsService.listProjects({
87-
teamId: opts.teamId,
87+
teamId: opts.orgId,
8888
pagination,
8989
});
9090
results.push(...response.projects);

components/gitpod-db/src/project-db.spec.db.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class ProjectDBSpec {
4747
name: "some-project",
4848
slug: "some-project",
4949
cloneUrl: "some-random-clone-url",
50-
userId: user.id,
5150
teamId: "team-1",
5251
appInstallationId: "app-1",
5352
});

components/gitpod-db/src/redis/publisher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the GNU Affero General Public License (AGPL).
44
* See License.AGPL.txt in the project root for license information.
55
*/
6+
import "reflect-metadata";
67

78
import { inject, injectable } from "inversify";
89
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";

components/gitpod-db/src/typeorm/entity/db-project.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ export class DBProject {
3232
@Index("ind_teamId")
3333
teamId: string;
3434

35-
@Column({
36-
default: "",
37-
transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED,
38-
})
39-
@Index("ind_userId")
40-
userId?: string;
41-
4235
@Column()
4336
appInstallationId: string;
4437

components/gitpod-protocol/src/encryption/encryption-engine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the GNU Affero General Public License (AGPL).
44
* See License.AGPL.txt in the project root for license information.
55
*/
6+
import "reflect-metadata";
67

78
import * as crypto from "crypto";
89
import { injectable } from "inversify";

components/gitpod-protocol/src/teams-projects-protocol.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export interface Project {
3030
slug?: string;
3131
cloneUrl: string;
3232
teamId: string;
33-
userId?: string;
3433
appInstallationId: string;
3534
settings?: ProjectSettings;
3635
creationTime: string;

components/server/src/prebuilds/prebuild-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,14 @@ export class PrebuildManager {
398398
commit: CommitInfo,
399399
) {
400400
const span = TraceContext.startSpan("storePrebuildInfo", ctx);
401-
const { userId, teamId, name: projectName, id: projectId } = project;
401+
const { teamId, name: projectName, id: projectId } = project;
402402
try {
403403
await this.workspaceDB.trace({ span }).storePrebuildInfo({
404404
id: pws.id,
405405
buildWorkspaceId: pws.buildWorkspaceId,
406406
basedOnPrebuildId: ws.basedOnPrebuildId,
407407
teamId,
408-
userId,
408+
userId: user.id,
409409
projectName,
410410
projectId,
411411
startedAt: pws.creationTime,

components/server/src/projects/projects-service.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export class ProjectsService {
269269
});
270270

271271
// Install the prebuilds webhook if possible
272-
const { userId, teamId, cloneUrl } = project;
272+
const { teamId, cloneUrl } = project;
273273
const parsedUrl = RepoURL.parseRepoUrl(project.cloneUrl);
274274
const hostContext = parsedUrl?.host ? this.hostContextProvider.get(parsedUrl?.host) : undefined;
275275
const authProvider = hostContext && hostContext.authProvider.info;
@@ -286,11 +286,10 @@ export class ProjectsService {
286286
// in the project creation flow, we only propose repositories where the user is actually allowed to
287287
// install a webhook.
288288
if (await repositoryService.canInstallAutomatedPrebuilds(installer, cloneUrl)) {
289-
log.info("Update prebuild installation for project.", {
290-
teamId,
291-
userId,
292-
installerId: installer.id,
293-
});
289+
log.info(
290+
{ organizationId: teamId, userId: installer.id },
291+
"Update prebuild installation for project.",
292+
);
294293
await repositoryService.installAutomatedPrebuilds(installer, cloneUrl);
295294
}
296295
}

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,16 +2843,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
28432843
if (!project) {
28442844
throw new ApplicationError(ErrorCodes.NOT_FOUND, "Project not found");
28452845
}
2846-
// TODO(janx): This if/else block should probably become a GuardedProject.
2847-
if (project.userId) {
2848-
if (user.id !== project.userId) {
2849-
// Projects owned by a single user can only be accessed by that user
2850-
throw new ApplicationError(ErrorCodes.PERMISSION_DENIED, "Not allowed to access this project");
2851-
}
2852-
} else {
2853-
// Anyone who can read a team's information (i.e. any team member) can manage team projects
2854-
await this.guardTeamOperation(project.teamId || "", "get", "not_implemented");
2855-
}
2846+
// Anyone who can read a team's information (i.e. any team member) can manage team projects
2847+
await this.guardTeamOperation(project.teamId, "get", "not_implemented");
28562848
}
28572849

28582850
public async deleteProject(ctx: TraceContext, projectId: string): Promise<void> {

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,10 @@ export class WorkspaceFactory {
240240
};
241241

242242
let projectId: string | undefined;
243-
// associate with a project, if it's the personal project of the current user
244-
if (project?.userId && project?.userId === user.id) {
245-
projectId = project.id;
246-
}
247243
// associate with a project, if the current user is a team member
248-
if (project?.teamId) {
244+
if (project) {
249245
const teams = await this.teamDB.findTeamsByUser(user.id);
250-
if (teams.some((t) => t.id === project?.teamId)) {
246+
if (teams.some((t) => t.id === project.teamId)) {
251247
projectId = project.id;
252248
}
253249
}
@@ -380,14 +376,10 @@ export class WorkspaceFactory {
380376
}
381377

382378
let projectId: string | undefined;
383-
// associate with a project, if it's the personal project of the current user
384-
if (project?.userId && project?.userId === user.id) {
385-
projectId = project.id;
386-
}
387379
// associate with a project, if the current user is a team member
388-
if (project?.teamId) {
380+
if (project) {
389381
const teams = await this.teamDB.findTeamsByUser(user.id);
390-
if (teams.some((t) => t.id === project?.teamId)) {
382+
if (teams.some((t) => t.id === project.teamId)) {
391383
projectId = project.id;
392384
}
393385
}

0 commit comments

Comments
 (0)