Skip to content

Commit

Permalink
[server] Make sure to re-add project -> org relation on failed deleti…
Browse files Browse the repository at this point in the history
…on (#18055)
  • Loading branch information
geropl authored Jun 26, 2023
1 parent 0111756 commit 8a2be48
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions components/server/src/projects/projects-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,23 @@ export class ProjectsService {
}

async deleteProject(projectId: string): Promise<void> {
let orgId: string | undefined = undefined;
try {
await this.projectDB.transaction(async (db) => {
// TODO(gpl): This is a case where we'd need to extend the service + API to also accept the orgId as first parameter
const project = await db.findProjectById(projectId);
if (!project) {
throw new Error("Project does not exist");
}
orgId = project.teamId;
await db.markDeleted(projectId);

await this.authorizer.writeRelationships(removeProjectFromOrg(project.teamId, projectId));
await this.authorizer.writeRelationships(removeProjectFromOrg(orgId, projectId));
});
} catch (err) {
// As the remove relationships is the last call that might fail, we don't have to do anything here.
if (orgId) {
await this.authorizer.writeRelationships(addProjectToOrg(orgId, projectId));
}
throw err;
}
}
Expand Down

0 comments on commit 8a2be48

Please sign in to comment.