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

chore: delete project api tokens when last mapped project is removed #7503

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: if flag enabled - delete orphaned tokens when deleting projects…
…. else just delete projects
daveleek committed Jul 7, 2024

Verified

This commit was signed with the committer’s verified signature.
daveleek David Leek
commit 35ea6e2f6ba3b8ec9ead0e8cb85ceab77b011c5b
32 changes: 18 additions & 14 deletions src/lib/features/project/project-service.ts
Original file line number Diff line number Diff line change
@@ -564,22 +564,26 @@ export default class ProjectService {
auditUser,
);

const allTokens = await this.apiTokenStore.getAll();
const projectTokens = allTokens.filter(
(token) =>
(token.projects &&
token.projects.length === 1 &&
token.projects[0] === id) ||
token.project === id,
);
if (this.flagResolver.isEnabled('cleanApiTokenWhenOrphaned')) {
const allTokens = await this.apiTokenStore.getAll();
const projectTokens = allTokens.filter(
(token) =>
(token.projects &&
token.projects.length === 1 &&
token.projects[0] === id) ||
token.project === id,
);

await this.projectStore.delete(id);
await this.projectStore.delete(id);

await Promise.all(
projectTokens.map((token) =>
this.apiTokenStore.delete(token.secret),
),
);
await Promise.all(
projectTokens.map((token) =>
this.apiTokenStore.delete(token.secret),
),
);
} else {
await this.projectStore.delete(id);
}

await this.eventService.storeEvent(
new ProjectDeletedEvent({