diff --git a/packages/backend/src/graphql/mutations/delete-current-user.ee.ts b/packages/backend/src/graphql/mutations/delete-current-user.ee.ts index 05704f77..71a1a030 100644 --- a/packages/backend/src/graphql/mutations/delete-current-user.ee.ts +++ b/packages/backend/src/graphql/mutations/delete-current-user.ee.ts @@ -5,6 +5,7 @@ import flowQueue from '../../queues/flow'; import Flow from '../../models/flow'; import Execution from '../../models/execution'; import ExecutionStep from '../../models/execution-step'; +import appConfig from '../../config/app'; const deleteCurrentUser = async ( _parent: unknown, @@ -14,7 +15,7 @@ const deleteCurrentUser = async ( const id = context.currentUser.id; const flows = await context.currentUser.$relatedQuery('flows').where({ - status: 'active', + active: true, }); const repeatableJobs = await flowQueue.getRepeatableJobs(); @@ -39,6 +40,12 @@ const deleteCurrentUser = async ( await context.currentUser.$relatedQuery('steps').delete(); await Flow.query().whereIn('id', flowIds).delete(); await context.currentUser.$relatedQuery('connections').delete(); + await context.currentUser.$relatedQuery('identities').delete(); + + if (appConfig.isCloud) { + await context.currentUser.$relatedQuery('subscriptions').delete(); + await context.currentUser.$relatedQuery('usageData').delete(); + } await context.currentUser.$query().delete(); diff --git a/packages/backend/src/workers/delete-user.ee.ts b/packages/backend/src/workers/delete-user.ee.ts index 0219c43d..36f9834c 100644 --- a/packages/backend/src/workers/delete-user.ee.ts +++ b/packages/backend/src/workers/delete-user.ee.ts @@ -3,6 +3,7 @@ import { Worker } from 'bullmq'; import * as Sentry from '../helpers/sentry.ee'; import redisConfig from '../config/redis'; import logger from '../helpers/logger'; +import appConfig from '../config/app'; import User from '../models/user'; import Execution from '../models/execution'; import ExecutionStep from '../models/execution-step'; @@ -12,21 +13,34 @@ export const worker = new Worker( async (job) => { const { id } = job.data; - const user = await User.query().findById(id).throwIfNotFound(); + const user = await User.query() + .withSoftDeleted() + .findById(id) + .throwIfNotFound(); const executionIds = ( - await user.$relatedQuery('executions').select('executions.id') + await user + .$relatedQuery('executions') + .withSoftDeleted() + .select('executions.id') ).map((execution: Execution) => execution.id); await ExecutionStep.query() - .hardDelete() - .whereIn('execution_id', executionIds); - await user.$relatedQuery('executions').hardDelete(); - await user.$relatedQuery('steps').hardDelete(); - await user.$relatedQuery('flows').hardDelete(); - await user.$relatedQuery('connections').hardDelete(); + .withSoftDeleted() + .whereIn('execution_id', executionIds) + .hardDelete(); + await user.$relatedQuery('executions').withSoftDeleted().hardDelete(); + await user.$relatedQuery('steps').withSoftDeleted().hardDelete(); + await user.$relatedQuery('flows').withSoftDeleted().hardDelete(); + await user.$relatedQuery('connections').withSoftDeleted().hardDelete(); + await user.$relatedQuery('identities').withSoftDeleted().hardDelete(); - await user.$query().hardDelete(); + if (appConfig.isCloud) { + await user.$relatedQuery('subscriptions').withSoftDeleted().hardDelete(); + await user.$relatedQuery('usageData').withSoftDeleted().hardDelete(); + } + + await user.$query().withSoftDeleted().hardDelete(); }, { connection: redisConfig } );