Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(projects): use the current organization id to cancel project deletion (#105816)

Yasene106be071351
diff --git a/frontend/src/scenes/projectLogic.test.ts b/frontend/src/scenes/projectLogic.test.ts
new file mode 100644
index 000000000000..543a391caef9
--- /dev/null
+++ b/frontend/src/scenes/projectLogic.test.ts
@@ -0,0 +1,39 @@
+import { MOCK_DEFAULT_PROJECT, MOCK_ORGANIZATION_ID } from 'lib/api.mock'
+
+import { expectLogic } from 'kea-test-utils'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { organizationLogic } from './organizationLogic'
+import { projectLogic } from './projectLogic'
+
+describe('projectLogic', () => {
+ it('cancels project deletion in the current organization when the project has no organization_id', async () => {
+ const requestedOrganizationIds: string[] = []
+ useMocks({
+ post: {
+ '/api/organizations/:organizationId/projects/:id/cancel-deletion/': (req) => {
+ requestedOrganizationIds.push(req.params.organizationId as string)
+ return [200, { ...MOCK_DEFAULT_PROJECT, is_pending_deletion: false }]
+ },
+ },
+ })
+ initKeaTests()
+ const logic = projectLogic()
+ logic.mount()
+ await expectLogic(organizationLogic).toFinishAllListeners()
+
+ const { organization_id: _, ...projectFromCurrentEndpoint } = MOCK_DEFAULT_PROJECT
+ logic.actions.loadCurrentProjectSuccess({
+ ...projectFromCurrentEndpoint,
+ is_pending_deletion: true,
+ } as typeof MOCK_DEFAULT_PROJECT)
+
+ await expectLogic(logic, () => {
+ logic.actions.cancelProjectDeletion()
+ }).toDispatchActions(['cancelProjectDeletionSuccess'])
+
+ expect(requestedOrganizationIds).toEqual([MOCK_ORGANIZATION_ID])
+ })
+})
diff --git a/frontend/src/scenes/projectLogic.ts b/frontend/src/scenes/projectLogic.ts
index 522c746c3ec7..8570d909613a 100644
--- a/frontend/src/scenes/projectLogic.ts
+++ b/frontend/src/scenes/projectLogic.ts
@@ -20,6 +20,7 @@ import { userLogic } from './userLogic'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface projectLogicValues {
+ currentOrganizationId: string // organizationLogic
otherOrganizations: OrganizationBasicType[] // userLogic
currentProject: ProjectType | null
currentProjectId: number | null
@@ -197,7 +198,7 @@ export const projectLogic = kea<projectLogicType>([
organizationLogic,
['loadCurrentOrganization'],
],
- values: [userLogic, ['otherOrganizations']],
+ values: [userLogic, ['otherOrganizations'], organizationLogic, ['currentOrganizationId']],
})),
reducers({
projectBeingDeleted: [
@@ -267,8 +268,10 @@ export const projectLogic = kea<projectLogicType>([
if (!values.currentProject) {
throw new Error('Current project has not been loaded yet, so it cannot be restored!')
}
+ // api/projects/@current returns `organization` instead of `organization_id`, so a reloaded
+ // currentProject has no organization_id and the request would go to /organizations/undefined/
return (await organizationsProjectsCancelDeletionCreate(
- values.currentProject.organization_id,
+ values.currentOrganizationId,
values.currentProject.id
)) as unknown as ProjectType
},