Repository navigation
Added archive, restore and delete to member custom fields API - #29393
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (12)
🚧 Files skipped from review as they are similar to previous changes (8)
WalkthroughCustom fields now expose status in database, domain, and API schemas. Browsing accepts NQL filters while defaulting to active fields. Status updates archive or restore fields and record lifecycle actions, while permanent deletion is permitted only for archived fields. Tests cover filtering, lifecycle transitions, value persistence, cascade deletion, and action history. Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run ghost:test:integration |
✅ Succeeded | 3m 6s | View ↗ |
nx run ghost:test:ci:integration |
✅ Succeeded | 5s | View ↗ |
nx run @tryghost/admin:test:acceptance |
✅ Succeeded | 5m 23s | View ↗ |
nx run-many -t test:unit -p @tryghost/admin-x-f... |
✅ Succeeded | 4m 19s | View ↗ |
nx run @tryghost/koenig-lexical:test:acceptance |
✅ Succeeded | 2m 33s | View ↗ |
nx run ghost:test:legacy |
✅ Succeeded | 3m | View ↗ |
nx run ghost:test:e2e |
✅ Succeeded | 2m 45s | View ↗ |
nx run ghost-admin:test |
✅ Succeeded | 3m 4s | View ↗ |
Additional runs (8) |
✅ Succeeded | ... | View ↗ |
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗
☁️ Nx Cloud last updated this comment at 2026-07-17 10:58:44 UTC
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #29393 +/- ##
==========================================
- Coverage 74.30% 74.27% -0.03%
==========================================
Files 1595 1595
Lines 139505 139583 +78
Branches 16946 16949 +3
==========================================
+ Hits 103657 103680 +23
- Misses 34831 34852 +21
- Partials 1017 1051 +34
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
48e2b5b to
8b59c74
Compare
85019c4 to
004c289
Compare
8b59c74 to
f1b7e4b
Compare
004c289 to
48832df
Compare
f1b7e4b to
6905787
Compare
48832df to
ab25788
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@ghost/core/core/server/services/members-custom-fields/definitions-service.ts`:
- Around line 218-227: The lifecycle mutations in definitions-service.ts must be
made atomic: in destroy, delete using both key and archived status, inspect the
affected-row count, and only record the delete action when one row was removed;
in the update path around lines 198-205, constrain the update by key and
expected prior status, then record the action only when exactly one row
transitions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9989b67f-f5b2-4e1b-a8d8-5306acc6dbed
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
ghost/core/core/server/api/endpoints/member-custom-fields.tsghost/core/core/server/services/members-custom-fields/actions.tsghost/core/core/server/services/members-custom-fields/definitions-service.tsghost/core/core/server/services/members-custom-fields/models.tsghost/core/core/server/services/members-custom-fields/schema.tsghost/core/core/server/services/members-custom-fields/serializers.tsghost/core/package.jsonghost/core/test/e2e-api/admin/member-custom-fields.test.tspnpm-workspace.yaml
| async destroy(context: RequestContext, key: string): Promise<void> { | ||
| const field = await this.knex(TABLE).where('key', key).first(); | ||
| if (!field) { | ||
| throw new errors.NotFoundError({message: 'Custom field not found.'}); | ||
| } | ||
| if (field.status !== FIELD_STATUS.archived) { | ||
| await this.knex(TABLE).where('key', key).update({status: FIELD_STATUS.archived, updated_at: new Date()}); | ||
| await this.recordAction({context, verb: 'archive', subject: key}); | ||
| throw new errors.ValidationError({message: 'Only archived custom fields can be deleted. Archive the field first.'}); | ||
| } | ||
| await this.knex(TABLE).where('key', key).del(); | ||
| await this.recordAction({context, verb: 'delete', subject: key}); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Make lifecycle state checks and mutations atomic.
Both paths make decisions from a stale pre-read and then mutate by key alone, allowing concurrent transitions to violate lifecycle guarantees.
ghost/core/core/server/services/members-custom-fields/definitions-service.ts#L218-L227: delete only where both the key and archived status still match; inspect the affected-row count.ghost/core/core/server/services/members-custom-fields/definitions-service.ts#L198-L205: update only from the expected prior status and record an action only when one row actually transitions.
📍 Affects 1 file
ghost/core/core/server/services/members-custom-fields/definitions-service.ts#L218-L227(this comment)ghost/core/core/server/services/members-custom-fields/definitions-service.ts#L198-L205
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@ghost/core/core/server/services/members-custom-fields/definitions-service.ts`
around lines 218 - 227, The lifecycle mutations in definitions-service.ts must
be made atomic: in destroy, delete using both key and archived status, inspect
the affected-row count, and only record the delete action when one row was
removed; in the update path around lines 198-205, constrain the update by key
and expected prior status, then record the action only when exactly one row
transitions.
6905787 to
db23b9d
Compare
ab25788 to
0438e0a
Compare
0438e0a to
83bea3f
Compare
ref BER-3803 Status now travels on the field definition so the list can group active vs archived. Archive and restore are a single PUT status flip over the edit route, matching how newsletters move between states, and the change is only written and logged when the status actually flips. Browse hides archived fields by default and takes a filter option (filter=status:[active,archived]) run through nql -> mongo-knex; a filter not referencing status keeps the active-only default and a malformed filter is a 400. DELETE now permanently removes the row (FK-cascading member values) and is gated on the field already being archived. Each lifecycle change (create, rename, archive, restore, delete) is recorded in the action log with the field's name in the action context, so the timeline stays legible after a hard delete when the row itself is gone; a rename also records the previous name. The Settings history log renders the definition lifecycle events (member_custom_field) with a "Custom field" label instead of the raw resource type, and the field name from the action context shows as the entry description.
83bea3f to
9ad1758
Compare

Problem
Custom field definitions could be archived, but the API had no way to see archived fields or bring them back. Archiving was a one-way soft delete with no path to permanently remove a field, and since field names stay globally unique, an archived field could silently block reuse of its name with no way to reach it. Settings needs to show archived fields alongside active ones, and admins need a safe, deliberate way to permanently delete a field and its data.
Solution
Archived fields are now hidden by default but reachable: the definitions list takes a status filter so Settings can pull active and archived together in one request, and a field carries its status so the UI can group them. Archiving and restoring are a single status change over the existing update route. Deleting a field now permanently removes it and its stored member values, and is only allowed once the field has been archived, so permanent data loss is always a two-step.