Skip to content

Commit 3863329

Browse files
committed
Cascade project deletions to repo recommendations
Tool: gitpod/catfood.gitpod.cloud
1 parent 5abe0c3 commit 3863329

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import type { PrebuildManager } from "../prebuilds/prebuild-manager";
3939
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
4040
import { ContextParser } from "../workspace/context-parser-service";
4141
import { UnauthorizedError } from "../errors";
42+
import { LazyOrganizationService } from "../billing/entitlement-service-ubp";
43+
import { SubjectId } from "../auth/subject-id";
4244

4345
// to resolve circular dependency issues
4446
export const LazyPrebuildManager = Symbol("LazyPrebuildManager");
@@ -58,7 +60,7 @@ export class ProjectsService {
5860
@inject(LazyPrebuildManager) private readonly prebuildManager: LazyPrebuildManager,
5961
@inject(ContextParser) private readonly contextParser: ContextParser,
6062
@inject(WebhookEventDB) private readonly webhookEventDb: WebhookEventDB,
61-
63+
@inject(LazyOrganizationService) private readonly organizationService: LazyOrganizationService,
6264
@inject(InstallationService) private readonly installationService: InstallationService,
6365
) {}
6466

@@ -334,6 +336,8 @@ export class ProjectsService {
334336
async deleteProject(userId: string, projectId: string, transactionCtx?: TransactionalContext): Promise<void> {
335337
await this.auth.checkPermissionOnProject(userId, "delete", projectId);
336338

339+
const organizationService = this.organizationService();
340+
337341
let orgId: string | undefined = undefined;
338342
try {
339343
await this.projectDB.transaction(transactionCtx, async (db) => {
@@ -350,6 +354,19 @@ export class ProjectsService {
350354
await db.deleteProjectEnvironmentVariable(envVar.id);
351355
}
352356

357+
await runWithSubjectId(SubjectId.fromUserId(userId), async () => {
358+
const orgSettings = await organizationService.getSettings(userId, orgId!);
359+
const repoRecommendations = orgSettings.onboardingSettings?.recommendedRepositories;
360+
if (repoRecommendations) {
361+
const updatedRepoRecommendations = repoRecommendations.filter((id) => id !== projectId);
362+
if (updatedRepoRecommendations.length !== repoRecommendations.length) {
363+
await organizationService.updateSettings(userId, orgId!, {
364+
onboardingSettings: { recommendedRepositories: updatedRepoRecommendations },
365+
});
366+
}
367+
}
368+
});
369+
353370
await this.auth.removeProjectFromOrg(userId, orgId, projectId);
354371
});
355372
this.analytics.track({

0 commit comments

Comments
 (0)