Skip to content

feat: user delete backend#8878

Merged
csiyang merged 332 commits intomainfrom
siyangcao/nes-1454-deleteuser-backend
Apr 15, 2026
Merged

feat: user delete backend#8878
csiyang merged 332 commits intomainfrom
siyangcao/nes-1454-deleteuser-backend

Conversation

@csiyang
Copy link
Copy Markdown
Contributor

@csiyang csiyang commented Mar 19, 2026

Add user deletion endpoints with interop pattern:

  • api-users: userDeleteCheck mutation, userDeleteConfirm subscription
  • api-journeys-modern: interop mutations for journeys data cleanup
  • Firebase-only account deletion support
  • Audit logging for all deletions
  • Comprehensive test coverage

Summary by CodeRabbit

  • New Features

    • User deletion workflow: pre-check summary, confirm execution, and real-time progress updates with streamed operation logs.
    • Automatic handling of associated journeys and teams with ownership transfer where applicable.
    • Delete users by database ID or email, with audit records persisted for traceability.
    • Safeguards and detailed logs to surface issues during deletion.
  • Chores

    • Adjusted supported messaging platform options.

@csiyang csiyang self-assigned this Mar 19, 2026
@linear
Copy link
Copy Markdown

linear Bot commented Mar 19, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a cross-service user-deletion workflow: gateway schema additions, journeys-side evaluation & deletion services, users-side lookup/firebase/db deletion and subscription orchestration, Prisma audit-log model + migration, inter-service Apollo calls, and unit tests across services.

Changes

Cohort / File(s) Summary
API Gateway Schema
apis/api-gateway/schema.graphql
Added user-delete mutations and subscription fields, new result/log types, and UserDeleteIdType.
API Journeys Modern — schema & registration
apis/api-journeys-modern/schema.graphql, apis/api-journeys-modern/src/schema/schema.ts, apis/api-journeys-modern/src/schema/userDelete/index.ts
Registered new user-delete schema modules; removed discord, signal, weChat from MessagePlatform enum.
API Journeys Modern — services & types
apis/api-journeys-modern/src/schema/userDelete/service/*, .../userDelete/types.ts
Added checkJourneysData and deleteJourneysData with Log types, transaction ownership-transfer logic, cascading deletes, and unit tests.
API Journeys Modern — GraphQL modules
apis/api-journeys-modern/src/schema/userDelete/userDeleteJourneysCheck.ts, .../userDeleteJourneysConfirm.ts
Added GraphQL object types and mutations userDeleteJourneysCheck and userDeleteJourneysConfirm wired to services and auth rules.
API Users — schema, builder & registration
apis/api-users/schema.graphql, apis/api-users/src/schema/builder.ts, apis/api-users/src/schema/schema.ts, apis/api-users/src/schema/userDelete/index.ts
Enabled subscription support, added userDeleteCheck mutation and userDeleteConfirm subscription, and registered userDelete modules.
API Users — services & types
apis/api-users/src/schema/userDelete/service/*
Added lookupUser, deleteFirebaseUser, deleteUserData, journeysInterop (Apollo interop with timeout), logging utilities, barrels, and unit tests.
API Users — GraphQL resolvers & subscription
apis/api-users/src/schema/userDelete/userDeleteCheck.ts, apis/api-users/src/schema/userDelete/userDeleteConfirm.ts
Added userDeleteCheck mutation and userDeleteConfirm subscription that stream progress logs and orchestrate lookup → journeys confirm → Firebase/db deletion → audit-log updates.
Database — Prisma model & migration
libs/prisma/users/db/schema.prisma, libs/prisma/users/db/migrations/.../migration.sql, libs/prisma/users/db/migrations/migration_lock.toml
Added UserDeleteAuditLog Prisma model and migration SQL; minor migration_lock formatting tweak.
Infrastructure
apis/api-users/infrastructure/locals.tf
Added GATEWAY_URL to environment variables list.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant APIUsers as API Users
    participant APIJourneys as API Journeys Modern
    participant PrismaDB as Prisma Database
    participant FirebaseAuth as Firebase Auth

    Client->>APIUsers: userDeleteCheck(idType,id)
    APIUsers->>PrismaDB: lookup user by id/email
    PrismaDB-->>APIUsers: user record or null
    APIUsers->>FirebaseAuth: check Firebase existence/uid
    FirebaseAuth-->>APIUsers: firebase metadata
    APIUsers->>APIJourneys: callJourneysCheck(userId)
    APIJourneys->>PrismaDB: evaluate journeys/teams (counts)
    PrismaDB-->>APIJourneys: counts & logs
    APIJourneys-->>APIUsers: check result + logs
    APIUsers-->>Client: UserDeleteCheckResult + logs

    Client->>APIUsers: subscribe userDeleteConfirm(idType,id)
    APIUsers->>PrismaDB: lookup user & get caller
    APIUsers->>APIJourneys: callJourneysConfirm(userId)
    APIJourneys->>PrismaDB: transfer/delete journeys & cleanup
    APIJourneys-->>APIUsers: confirm result + logs
    APIUsers->>FirebaseAuth: deleteFirebaseUser(uid)
    FirebaseAuth-->>APIUsers: deletion logs/result
    APIUsers->>PrismaDB: create/update UserDeleteAuditLog and delete user row
    APIUsers-->>Client: streamed progress entries (log, done, success)
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'feat: user delete backend' clearly and concisely summarizes the main change—adding backend infrastructure for user deletion across multiple subgraphs with mutations, subscriptions, and supporting services.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch siyangcao/nes-1454-deleteuser-backend

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

Warnings
⚠️ ❗ Big PR (10802 changes)

(change count - 10802): Pull Request size seems relatively large. If Pull Request contains multiple changes, split each into separate PR will helps faster, easier review.

Generated by 🚫 dangerJS against aabd30f

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 19, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit aabd30f

Command Status Duration Result
nx run journeys-e2e:e2e ❌ Failed 4m 8s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-15 07:18:18 UTC

@github-actions github-actions Bot temporarily deployed to Preview - videos-admin March 19, 2026 01:52 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - short-links March 19, 2026 01:52 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - player March 19, 2026 01:52 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - watch March 19, 2026 01:52 Inactive
@github-actions github-actions Bot requested a deployment to Preview - journeys-admin March 19, 2026 01:52 Pending
@github-actions github-actions Bot temporarily deployed to Preview - journeys March 19, 2026 01:52 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - resources March 19, 2026 01:52 Inactive
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys ✅ Ready journeys preview Wed Apr 15 18:05:22 NZST 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
short-links ✅ Ready short-links preview Wed Apr 15 18:04:23 NZST 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
player ✅ Ready player preview Wed Apr 15 18:04:58 NZST 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
videos-admin ✅ Ready videos-admin preview Wed Apr 15 18:05:42 NZST 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
watch ✅ Ready watch preview Wed Apr 15 18:05:59 NZST 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
resources ✅ Ready resources preview Wed Apr 15 18:06:08 NZST 2026

@github-actions github-actions Bot temporarily deployed to Preview - journeys March 19, 2026 01:59 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin March 19, 2026 01:59 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - videos-admin March 19, 2026 01:59 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - short-links March 19, 2026 01:59 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - resources March 19, 2026 01:59 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - watch March 19, 2026 01:59 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - player March 19, 2026 01:59 Inactive
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys-admin ✅ Ready journeys-admin preview Wed Apr 15 18:07:16 NZST 2026

@github-actions github-actions Bot temporarily deployed to Preview - player March 19, 2026 02:24 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - journeys March 19, 2026 02:24 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin March 19, 2026 02:24 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - short-links March 19, 2026 02:24 Inactive
csiyang and others added 2 commits April 15, 2026 15:07
@blacksmith-sh

This comment has been minimized.

@stage-branch-merger
Copy link
Copy Markdown
Contributor

I see you added the "on stage" label, I'll get this merged to the stage branch!

@stage-branch-merger
Copy link
Copy Markdown
Contributor

Merge conflict attempting to merge this into stage. Please fix manually.

…rneys-modern schema (NES-1454)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@stage-branch-merger
Copy link
Copy Markdown
Contributor

Merge conflict attempting to merge this into stage. Please fix manually.

@stage-branch-merger
Copy link
Copy Markdown
Contributor

Merge conflict attempting to merge this into stage. Please fix manually.

autofix-ci Bot and others added 2 commits April 15, 2026 04:02
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@stage-branch-merger
Copy link
Copy Markdown
Contributor

Merge conflict attempting to merge this into stage. Please fix manually.

…ckend' into siyangcao/nes-1454-deleteuser-backend
@jesus-film-bot
Copy link
Copy Markdown

Ran Plan for dir: infrastructure workspace: default

Plan Failed: This project is currently locked by an unapplied plan from pull #8969. To continue, delete the lock from #8969 or apply that plan and merge the pull request.

Once the lock is released, comment atlantis plan here to re-plan.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 15, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
watch-modern ✅ Ready watch-modern preview Wed Apr 15 18:04:30 NZST 2026

… failures

- Remove duplicate `isSuperAdmin: boolean` from AuthScopes interface
  (merge conflict artifact from stage merge — line 82 was the stale copy;
  the lazy `boolean | (() => Promise<boolean>)` on line 84 is correct)
- Move `aria-label` on UserDelete TextField to `inputProps` so it reaches
  the actual <input> element rather than the outer FormControl div
- Fix UserDelete spec assertions using `toHaveValue(expect.stringContaining(...))`
  which silently fails in jest-dom 6.5.0 (lodash isEqualWith doesn't handle
  jest asymmetric matchers); changed to `.value.toContain(...)` instead

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jesus-film-bot
Copy link
Copy Markdown

Ran Plan for dir: infrastructure workspace: default

Plan Failed: This project is currently locked by an unapplied plan from pull #8969. To continue, delete the lock from #8969 or apply that plan and merge the pull request.

Once the lock is released, comment atlantis plan here to re-plan.

@blacksmith-sh

This comment has been minimized.

…NES-1454)

- Add migration 20260415000000 to ADD deletedUserFirebaseUid and
  completedAt columns to UserDeleteAuditLog on existing DBs — these
  fields were added to the Prisma schema but had no corresponding SQL
  migration, so they would be missing on any DB that had already run
  the earlier migrations
- Add self-deletion test to deleteUserData.spec.ts: verifies the audit
  log is created BEFORE user.delete() and that callerEmail is stored,
  so the log is useful even after the user record is removed

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jesus-film-bot
Copy link
Copy Markdown

Ran Plan for dir: infrastructure workspace: default

Plan Failed: This project is currently locked by an unapplied plan from pull #8969. To continue, delete the lock from #8969 or apply that plan and merge the pull request.

Once the lock is released, comment atlantis plan here to re-plan.

…S-1454)

TS2339 type-check failure — getByRole returns HTMLElement which does not
have a .value property; cast to HTMLTextAreaElement (the actual rendered
element from MUI TextField multiline) at the three affected assertions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jesus-film-bot
Copy link
Copy Markdown

Ran Plan for dir: infrastructure workspace: default

Plan Failed: This project is currently locked by an unapplied plan from pull #8969. To continue, delete the lock from #8969 or apply that plan and merge the pull request.

Once the lock is released, comment atlantis plan here to re-plan.

Three ESLint errors blocking journeys-admin:lint:
- import/order: move CircularProgress after Button (alphabetical MUI order)
  in UserDelete.tsx
- import/order: move GET_ME import before UserDelete import
  in pages/users/delete.tsx
- no-void (x2): wrap `void handleCheck()` and `void handleConfirmDelete()`
  in block bodies per allowAsStatement:true rule config

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jesus-film-bot
Copy link
Copy Markdown

Ran Plan for dir: infrastructure workspace: default

Plan Failed: This project is currently locked by an unapplied plan from pull #8969. To continue, delete the lock from #8969 or apply that plan and merge the pull request.

Once the lock is released, comment atlantis plan here to re-plan.

@jesus-film-bot
Copy link
Copy Markdown

Ran Plan for dir: infrastructure workspace: default

Plan Failed: This project is currently locked by an unapplied plan from pull #8969. To continue, delete the lock from #8969 or apply that plan and merge the pull request.

Once the lock is released, comment atlantis plan here to re-plan.

@blacksmith-sh
Copy link
Copy Markdown
Contributor

blacksmith-sh Bot commented Apr 15, 2026

Found 1 test failure on Blacksmith runners:

Failure

Test View Logs
src/e2e/journeys.spec.ts/journeys View Logs

Fix in Cursor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants