Repository navigation
Define custom fields in Settings - #29321
Conversation
WalkthroughThis change introduces member custom fields across the stack: a new shared Possibly related PRs
🚥 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 |
|
It looks like this PR contains a migration 👀 General requirements
Schema changes
Data changes
Reviewed for a new-table + permissions migration: achieved items ticked, items not applicable struck through. |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run @tryghost/admin-x-settings:test:acceptance |
✅ Succeeded | 8m 41s | View ↗ |
nx run ghost:test:ci:integration |
✅ Succeeded | 2m 53s | View ↗ |
nx run ghost:test:integration |
✅ Succeeded | 2m 55s | View ↗ |
nx run-many -t test:unit -p @tryghost/admin-x-f... |
✅ Succeeded | 3m 47s | View ↗ |
nx run ghost:test:legacy |
✅ Succeeded | 2m 53s | View ↗ |
nx run @tryghost/koenig-lexical:test:acceptance |
✅ Succeeded | 2m 23s | View ↗ |
nx run ghost:test:e2e |
✅ Succeeded | 2m 32s | View ↗ |
nx run ghost-admin:test |
✅ Succeeded | 2m 46s | View ↗ |
Additional runs (9) |
✅ Succeeded | ... | View ↗ |
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗
☁️ Nx Cloud last updated this comment at 2026-07-15 19:54:32 UTC
564592d to
cc21b68
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
ghost/core/core/server/services/members-custom-fields/service.ts (2)
56-59: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSurface the specific failing property in validation errors. Both validation blocks hardcode
property: 'custom_fields'for the error response. You can extract the exact property name from the Zod issue path to provide more actionable feedback to API consumers.
ghost/core/core/server/services/members-custom-fields/service.ts#L56-L59: useissue.path[0]?.toString()instead of the hardcoded string in theaddmethod.ghost/core/core/server/services/members-custom-fields/service.ts#L96-L99: useissue.path[0]?.toString()instead of the hardcoded string in theeditmethod.🤖 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/service.ts` around lines 56 - 59, Update both validation error blocks in the add and edit methods of the members custom-fields service to derive the ValidationError property from the first Zod issue path via issue.path[0]?.toString() instead of hardcoding custom_fields. Apply this at ghost/core/core/server/services/members-custom-fields/service.ts lines 56-59 and 96-99.
110-116: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueSkip the database update if the name hasn't changed.
If the provided name is identical to the existing name, you can safely skip the database update and the action log record. This prevents unnecessary writes and noisy audit log entries.
♻️ Proposed refactor
- if (patch.name !== undefined) { + if (patch.name !== undefined && patch.name !== existing.name) { await this.knex('member_custom_fields') .where('id', id) .update({name: patch.name, updated_at: new Date()}); await this.recordAction({context, verb: 'rename', subject: id}); }🤖 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/service.ts` around lines 110 - 116, Update the name-handling branch in the custom-field patch method to first compare patch.name with the existing field name, and only perform the database update and recordAction rename entry when the value actually changes. Preserve the current behavior when patch.name is undefined or different.ghost/core/core/server/services/members-custom-fields/schema.ts (1)
10-17: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAlign schema validation with database constraints.
To catch boundary violations early and return clean validation errors (rather than raw database exceptions), enforce the migration's column lengths directly in the Zod schema.
♻️ Proposed fixes
export const DbCustomField = z.object({ - id: z.string(), - key: z.string(), - name: z.string(), + id: z.string().max(24), + key: z.string().max(191), + name: z.string().max(191), type: FieldTypeSchema, created_at: DbDate, updated_at: DbDate.nullable() });🤖 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/schema.ts` around lines 10 - 17, Update the DbCustomField Zod schema to enforce the database migration’s maximum lengths for the id, key, and name fields, using string length validation so oversized values fail with clean schema validation errors before database writes.
🤖 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/data/migrations/versions/6.53/2026-07-14-16-47-54-add-member-custom-fields.js`:
- Around line 7-8: Update CustomFieldsService.insertWithMintedKey so the
slugified base key is truncated to a safe length before collision suffixes are
appended, ensuring generated keys including the maximum suffix remain within the
key column’s 191-character limit. Preserve existing collision resolution and
unique-key behavior for shorter slugs.
In `@ghost/core/core/server/lib/case-keys.ts`:
- Line 21: Update the toCamel function’s replacement regex to match underscores
followed by any alphanumeric character, case-insensitively, so runtime
conversion aligns with SnakeToCamel for keys such as address_1 and uppercase
variants.
---
Nitpick comments:
In `@ghost/core/core/server/services/members-custom-fields/schema.ts`:
- Around line 10-17: Update the DbCustomField Zod schema to enforce the database
migration’s maximum lengths for the id, key, and name fields, using string
length validation so oversized values fail with clean schema validation errors
before database writes.
In `@ghost/core/core/server/services/members-custom-fields/service.ts`:
- Around line 56-59: Update both validation error blocks in the add and edit
methods of the members custom-fields service to derive the ValidationError
property from the first Zod issue path via issue.path[0]?.toString() instead of
hardcoding custom_fields. Apply this at
ghost/core/core/server/services/members-custom-fields/service.ts lines 56-59 and
96-99.
- Around line 110-116: Update the name-handling branch in the custom-field patch
method to first compare patch.name with the existing field name, and only
perform the database update and recordAction rename entry when the value
actually changes. Preserve the current behavior when patch.name is undefined or
different.
🪄 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: d20dedd1-db1c-406c-932a-912255552565
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (45)
apps/admin-x-framework/package.jsonapps/admin-x-framework/src/api/member-custom-fields.tsapps/admin-x-settings/src/components/settings/membership/custom-fields.tsxapps/admin-x-settings/src/components/settings/membership/custom-fields/custom-field-modal.tsxapps/admin-x-settings/src/components/settings/membership/membership-settings.tsxapps/admin-x-settings/src/components/sidebar.tsxapps/admin-x-settings/test/acceptance/membership/custom-fields.test.tsghost/admin/package.jsonghost/core/core/boot.jsghost/core/core/server/api/endpoints/index.jsghost/core/core/server/api/endpoints/member-custom-fields.tsghost/core/core/server/api/endpoints/utils/serializers/output/index.jsghost/core/core/server/api/endpoints/utils/serializers/output/member-custom-fields.tsghost/core/core/server/data/exporter/table-lists.jsghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-54-add-member-custom-fields.jsghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-56-add-member-custom-fields-permissions.jsghost/core/core/server/data/schema/fixtures/fixtures.jsonghost/core/core/server/data/schema/schema.jsghost/core/core/server/lib/case-keys.tsghost/core/core/server/lib/db-date.tsghost/core/core/server/services/gift-links/codec.tsghost/core/core/server/services/gift-links/schema.tsghost/core/core/server/services/gift-links/serializers.tsghost/core/core/server/services/members-custom-fields/actions.tsghost/core/core/server/services/members-custom-fields/codec.tsghost/core/core/server/services/members-custom-fields/index.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/core/server/services/members-custom-fields/service.tsghost/core/core/server/web/api/endpoints/admin/routes.jsghost/core/core/shared/labs.jsghost/core/package.jsonghost/core/test/e2e-api/admin/member-custom-fields.test.tsghost/core/test/integration/exporter/exporter.test.jsghost/core/test/unit/server/data/schema/integrity.test.jsghost/core/test/utils/fixtures/fixtures.jsonpackages/custom-field-types/README.mdpackages/custom-field-types/eslint.config.mjspackages/custom-field-types/package.jsonpackages/custom-field-types/src/index.tspackages/custom-field-types/test/index.test.tspackages/custom-field-types/test/tsconfig.jsonpackages/custom-field-types/tsconfig.jsonpackages/custom-field-types/vitest.config.ts
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 2
🧹 Nitpick comments (3)
ghost/core/core/server/services/members-custom-fields/service.ts (2)
56-59: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSurface the specific failing property in validation errors. Both validation blocks hardcode
property: 'custom_fields'for the error response. You can extract the exact property name from the Zod issue path to provide more actionable feedback to API consumers.
ghost/core/core/server/services/members-custom-fields/service.ts#L56-L59: useissue.path[0]?.toString()instead of the hardcoded string in theaddmethod.ghost/core/core/server/services/members-custom-fields/service.ts#L96-L99: useissue.path[0]?.toString()instead of the hardcoded string in theeditmethod.🤖 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/service.ts` around lines 56 - 59, Update both validation error blocks in the add and edit methods of the members custom-fields service to derive the ValidationError property from the first Zod issue path via issue.path[0]?.toString() instead of hardcoding custom_fields. Apply this at ghost/core/core/server/services/members-custom-fields/service.ts lines 56-59 and 96-99.
110-116: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueSkip the database update if the name hasn't changed.
If the provided name is identical to the existing name, you can safely skip the database update and the action log record. This prevents unnecessary writes and noisy audit log entries.
♻️ Proposed refactor
- if (patch.name !== undefined) { + if (patch.name !== undefined && patch.name !== existing.name) { await this.knex('member_custom_fields') .where('id', id) .update({name: patch.name, updated_at: new Date()}); await this.recordAction({context, verb: 'rename', subject: id}); }🤖 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/service.ts` around lines 110 - 116, Update the name-handling branch in the custom-field patch method to first compare patch.name with the existing field name, and only perform the database update and recordAction rename entry when the value actually changes. Preserve the current behavior when patch.name is undefined or different.ghost/core/core/server/services/members-custom-fields/schema.ts (1)
10-17: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAlign schema validation with database constraints.
To catch boundary violations early and return clean validation errors (rather than raw database exceptions), enforce the migration's column lengths directly in the Zod schema.
♻️ Proposed fixes
export const DbCustomField = z.object({ - id: z.string(), - key: z.string(), - name: z.string(), + id: z.string().max(24), + key: z.string().max(191), + name: z.string().max(191), type: FieldTypeSchema, created_at: DbDate, updated_at: DbDate.nullable() });🤖 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/schema.ts` around lines 10 - 17, Update the DbCustomField Zod schema to enforce the database migration’s maximum lengths for the id, key, and name fields, using string length validation so oversized values fail with clean schema validation errors before database writes.
🤖 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/data/migrations/versions/6.53/2026-07-14-16-47-54-add-member-custom-fields.js`:
- Around line 7-8: Update CustomFieldsService.insertWithMintedKey so the
slugified base key is truncated to a safe length before collision suffixes are
appended, ensuring generated keys including the maximum suffix remain within the
key column’s 191-character limit. Preserve existing collision resolution and
unique-key behavior for shorter slugs.
In `@ghost/core/core/server/lib/case-keys.ts`:
- Line 21: Update the toCamel function’s replacement regex to match underscores
followed by any alphanumeric character, case-insensitively, so runtime
conversion aligns with SnakeToCamel for keys such as address_1 and uppercase
variants.
---
Nitpick comments:
In `@ghost/core/core/server/services/members-custom-fields/schema.ts`:
- Around line 10-17: Update the DbCustomField Zod schema to enforce the database
migration’s maximum lengths for the id, key, and name fields, using string
length validation so oversized values fail with clean schema validation errors
before database writes.
In `@ghost/core/core/server/services/members-custom-fields/service.ts`:
- Around line 56-59: Update both validation error blocks in the add and edit
methods of the members custom-fields service to derive the ValidationError
property from the first Zod issue path via issue.path[0]?.toString() instead of
hardcoding custom_fields. Apply this at
ghost/core/core/server/services/members-custom-fields/service.ts lines 56-59 and
96-99.
- Around line 110-116: Update the name-handling branch in the custom-field patch
method to first compare patch.name with the existing field name, and only
perform the database update and recordAction rename entry when the value
actually changes. Preserve the current behavior when patch.name is undefined or
different.
🪄 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: d20dedd1-db1c-406c-932a-912255552565
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (45)
apps/admin-x-framework/package.jsonapps/admin-x-framework/src/api/member-custom-fields.tsapps/admin-x-settings/src/components/settings/membership/custom-fields.tsxapps/admin-x-settings/src/components/settings/membership/custom-fields/custom-field-modal.tsxapps/admin-x-settings/src/components/settings/membership/membership-settings.tsxapps/admin-x-settings/src/components/sidebar.tsxapps/admin-x-settings/test/acceptance/membership/custom-fields.test.tsghost/admin/package.jsonghost/core/core/boot.jsghost/core/core/server/api/endpoints/index.jsghost/core/core/server/api/endpoints/member-custom-fields.tsghost/core/core/server/api/endpoints/utils/serializers/output/index.jsghost/core/core/server/api/endpoints/utils/serializers/output/member-custom-fields.tsghost/core/core/server/data/exporter/table-lists.jsghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-54-add-member-custom-fields.jsghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-56-add-member-custom-fields-permissions.jsghost/core/core/server/data/schema/fixtures/fixtures.jsonghost/core/core/server/data/schema/schema.jsghost/core/core/server/lib/case-keys.tsghost/core/core/server/lib/db-date.tsghost/core/core/server/services/gift-links/codec.tsghost/core/core/server/services/gift-links/schema.tsghost/core/core/server/services/gift-links/serializers.tsghost/core/core/server/services/members-custom-fields/actions.tsghost/core/core/server/services/members-custom-fields/codec.tsghost/core/core/server/services/members-custom-fields/index.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/core/server/services/members-custom-fields/service.tsghost/core/core/server/web/api/endpoints/admin/routes.jsghost/core/core/shared/labs.jsghost/core/package.jsonghost/core/test/e2e-api/admin/member-custom-fields.test.tsghost/core/test/integration/exporter/exporter.test.jsghost/core/test/unit/server/data/schema/integrity.test.jsghost/core/test/utils/fixtures/fixtures.jsonpackages/custom-field-types/README.mdpackages/custom-field-types/eslint.config.mjspackages/custom-field-types/package.jsonpackages/custom-field-types/src/index.tspackages/custom-field-types/test/index.test.tspackages/custom-field-types/test/tsconfig.jsonpackages/custom-field-types/tsconfig.jsonpackages/custom-field-types/vitest.config.ts
🛑 Comments failed to post (2)
ghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-54-add-member-custom-fields.js (1)
7-8: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Prevent unique key overflow during collision resolution.
The
keycolumn has a strictmaxlength: 191. InCustomFieldsService.insertWithMintedKey(upstream), a key is minted by slugifying thenameand appending a suffix (up to_1000) upon collisions. If the originalname(and its resulting slug) is close to 191 characters, appending the suffix will exceed this 191-character limit, resulting in anER_DATA_TOO_LONGdatabase exception and a 500 server error.To ensure robustness, ensure the base slug is truncated to a safe length (e.g., 185 characters, leaving room for
_1000) before appending the suffix in the upstream service logic.🤖 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/data/migrations/versions/6.53/2026-07-14-16-47-54-add-member-custom-fields.js` around lines 7 - 8, Update CustomFieldsService.insertWithMintedKey so the slugified base key is truncated to a safe length before collision suffixes are appended, ensuring generated keys including the maximum suffix remain within the key column’s 191-character limit. Preserve existing collision resolution and unique-key behavior for shorter slugs.ghost/core/core/server/lib/case-keys.ts (1)
21-21: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Mismatch between type mapping and runtime behavior for alphanumeric keys.
The
SnakeToCamelTypeScript utility correctly maps keys like"address_1"to"address1"by collapsing the underscore before numbers. However, the runtimetoCamelfunction uses a regex (/_([a-z])/g) that only matches lowercase letters.Because of this discrepancy, keys containing numbers or uppercase letters remain unmapped at runtime (e.g.,
"address_1"stays"address_1"), leading toundefinedproperty access errors when your code attempts to access the strongly-typed camelCase keys. Update the regex to case-insensitively match alphanumeric characters to align runtime behavior with the type system.🐛 Proposed fix for the regex to match alphanumeric characters
-const toCamel = (key: string): string => key.replace(/_([a-z])/g, (_full, letter: string) => letter.toUpperCase()); +const toCamel = (key: string): string => key.replace(/_([a-z0-9])/gi, (_full, char: string) => char.toUpperCase());📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.const toCamel = (key: string): string => key.replace(/_([a-z0-9])/gi, (_full, char: string) => char.toUpperCase());🤖 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/lib/case-keys.ts` at line 21, Update the toCamel function’s replacement regex to match underscores followed by any alphanumeric character, case-insensitively, so runtime conversion aligns with SnakeToCamel for keys such as address_1 and uppercase variants.
c48e2b1 to
38208b2
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #29321 +/- ##
==========================================
+ Coverage 74.00% 74.10% +0.09%
==========================================
Files 1578 1588 +10
Lines 137512 138017 +505
Branches 16646 16735 +89
==========================================
+ Hits 101765 102275 +510
+ Misses 34729 34692 -37
- Partials 1018 1050 +32
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:
|
0172802 to
3769b6e
Compare
3769b6e to
2f2053c
Compare
2f2053c to
ece0bfb
Compare
| // Registered before /members/:id so the literal path isn't captured by :id. | ||
| router.get('/members/custom_fields', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.browse)); | ||
| router.post('/members/custom_fields', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.add)); | ||
| router.get('/members/custom_fields/:key', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.read)); |
| router.get('/members/custom_fields', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.browse)); | ||
| router.post('/members/custom_fields', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.add)); | ||
| router.get('/members/custom_fields/:key', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.read)); | ||
| router.put('/members/custom_fields/:key', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.edit)); |
| router.post('/members/custom_fields', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.add)); | ||
| router.get('/members/custom_fields/:key', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.read)); | ||
| router.put('/members/custom_fields/:key', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.edit)); | ||
| router.delete('/members/custom_fields/:key', mw.authAdminApi, labs.enabledMiddleware('membersCustomFields'), http(api.membersCustomFields.destroy)); |
df60f28 to
dbc0001
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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
`@apps/admin-x-settings/src/components/settings/advanced/labs/private-features.tsx`:
- Around line 74-77: Update the description for the “Member custom fields” entry
in the labs feature definitions to describe only creating and managing custom
field definitions, without implying admins can set or read member values.
In `@ghost/core/core/server/services/members-custom-fields/service.ts`:
- Around line 71-74: Update the validation error handling in both add() at
ghost/core/core/server/services/members-custom-fields/service.ts:71-74 and
edit() at
ghost/core/core/server/services/members-custom-fields/service.ts:121-124 to
derive property from the first Zod issue path, using issue.path.join('.') with
'members_custom_fields' as the fallback when empty, instead of hardcoding
'custom_fields'.
🪄 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: 7a49c4ea-cb9b-4448-8497-2e91e6d594e3
⛔ Files ignored due to path filters (2)
ghost/core/test/e2e-api/admin/__snapshots__/config.test.js.snapis excluded by!**/*.snappnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (44)
apps/admin-x-framework/package.jsonapps/admin-x-framework/src/api/member-custom-fields.tsapps/admin-x-settings/src/components/settings/advanced/labs/private-features.tsxapps/admin-x-settings/src/components/settings/membership/custom-fields.tsxapps/admin-x-settings/src/components/settings/membership/custom-fields/custom-field-modal.tsxapps/admin-x-settings/src/components/settings/membership/membership-settings.tsxapps/admin-x-settings/src/components/sidebar.tsxapps/admin-x-settings/test/acceptance/membership/custom-fields.test.tsghost/admin/app/services/state-bridge.jsghost/admin/package.jsonghost/core/core/boot.jsghost/core/core/server/api/endpoints/index.jsghost/core/core/server/api/endpoints/member-custom-fields.tsghost/core/core/server/api/endpoints/utils/serializers/output/index.jsghost/core/core/server/api/endpoints/utils/serializers/output/member-custom-fields.tsghost/core/core/server/data/exporter/table-lists.jsghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-54-add-members-custom-fields.jsghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-56-add-members-custom-fields-permissions.jsghost/core/core/server/data/schema/fixtures/fixtures.jsonghost/core/core/server/data/schema/schema.jsghost/core/core/server/services/members-custom-fields/actions.tsghost/core/core/server/services/members-custom-fields/codec.tsghost/core/core/server/services/members-custom-fields/index.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/core/server/services/members-custom-fields/service.tsghost/core/core/server/web/api/endpoints/admin/routes.jsghost/core/core/shared/labs.jsghost/core/package.jsonghost/core/test/e2e-api/admin/member-custom-fields.test.tsghost/core/test/integration/exporter/exporter.test.jsghost/core/test/integration/migrations/migration.test.jsghost/core/test/unit/server/data/schema/fixtures/fixture-manager.test.jsghost/core/test/unit/server/data/schema/integrity.test.jsghost/core/test/utils/fixtures/fixtures.jsonpackages/custom-field-types/README.mdpackages/custom-field-types/eslint.config.mjspackages/custom-field-types/package.jsonpackages/custom-field-types/src/index.tspackages/custom-field-types/test/index.test.tspackages/custom-field-types/test/tsconfig.jsonpackages/custom-field-types/tsconfig.jsonpackages/custom-field-types/vitest.config.ts
🚧 Files skipped from review as they are similar to previous changes (31)
- apps/admin-x-framework/package.json
- ghost/core/test/unit/server/data/schema/integrity.test.js
- packages/custom-field-types/eslint.config.mjs
- ghost/core/core/server/data/exporter/table-lists.js
- packages/custom-field-types/test/tsconfig.json
- packages/custom-field-types/README.md
- packages/custom-field-types/vitest.config.ts
- packages/custom-field-types/test/index.test.ts
- ghost/core/core/server/services/members-custom-fields/index.ts
- ghost/core/core/server/services/members-custom-fields/codec.ts
- ghost/core/test/integration/exporter/exporter.test.js
- packages/custom-field-types/package.json
- ghost/core/core/server/data/schema/fixtures/fixtures.json
- apps/admin-x-settings/src/components/settings/membership/membership-settings.tsx
- ghost/core/core/server/data/schema/schema.js
- ghost/core/core/server/services/members-custom-fields/schema.ts
- apps/admin-x-settings/src/components/settings/membership/custom-fields/custom-field-modal.tsx
- ghost/core/core/server/services/members-custom-fields/models.ts
- ghost/core/package.json
- ghost/core/core/server/api/endpoints/utils/serializers/output/member-custom-fields.ts
- ghost/core/core/boot.js
- apps/admin-x-settings/src/components/settings/membership/custom-fields.tsx
- packages/custom-field-types/tsconfig.json
- ghost/core/core/server/services/members-custom-fields/actions.ts
- ghost/core/test/utils/fixtures/fixtures.json
- packages/custom-field-types/src/index.ts
- apps/admin-x-settings/src/components/sidebar.tsx
- apps/admin-x-settings/test/acceptance/membership/custom-fields.test.ts
- ghost/core/core/server/api/endpoints/index.js
- apps/admin-x-framework/src/api/member-custom-fields.ts
- ghost/core/core/server/api/endpoints/member-custom-fields.ts
f42ded8 to
998b15b
Compare
8a14d17 to
c24f38c
Compare
ref BER-3785 case-keys and the DbDate codec were defined inside gift-links but are generic row<->domain helpers, not gift-links concerns. Moving them to server/lib lets the upcoming members-custom-fields service reuse them without depending on gift-links. Pure move plus import updates; no behaviour change.
ref BER-3785 The single source of truth for the two tier-neutral facts about a custom field type: which storage type its value routes to, and how a value is validated (including the composite address type, modelled on Stripe's Address). Ghost core imports it to enforce validation and route storage; admin imports the same schemas for form feedback, so the two never drift. Deliberately pure data — no presentation, no storage codecs, no lookup helpers.
ref BER-3785 The database layer for custom field definitions: a members_custom_fields table (id, unique key, name, type constrained to the known field types, and a status column for archive/soft-delete, matching the newsletters pattern) plus browse/ read/add/edit/destroy permissions on the member_custom_field resource. Administrators and Admin Integrations get full access; Super Editors can browse and read definitions so they can set values. schema.js, the exporter table list and both fixture copies match, with the integrity hashes regenerated and the full permission set pinned in migration.test.js. Member values live in a separate table added later. Adding the cycle's first migration bumped core and admin to 6.53.0-rc.0.
ref BER-3785 A knex + zod service owning custom field definitions: browse (active only), read, add, edit and archive. The immutable key is minted from the name by reading the taken slugs and picking the next free suffix (base, base-2, ...) — the same way tags and labels generate slugs; the unique index is a race backstop, not the primary mechanism. Name, key and type are immutable after creation, so a differing key or type is rejected rather than silently ignored. Delete archives (soft delete via a status column) so a slug is never reused and values stay attached to the right definition. Create, rename and archive are recorded to the activity log. Booted after gift-links; registers the membersCustomFields flag.
ref BER-3785 Exposes the custom field definitions over the Admin API: browse/read/add/edit/ destroy at /members/custom_fields, keyed by the immutable public key (the DB id is never exposed), registered before /members/:id so the literal path isn't captured, and gated by the membersCustomFields flag. Permissions are checked explicitly against the member_custom_field object type (there's no Bookshelf model). HTTP integration tests cover key minting, collision suffixing, duplicate names, immutable key/type, over-long names, an empty body, archive (archived fields leave the list but keep their slug reserved), the added/edited/archived action log, each field type end to end, not-found handling, authorization, that id is never leaked, and the flag off.
ref BER-3785 A Custom fields section in Membership settings (and its sidebar nav entry), both gated by the membersCustomFields feature flag, where admins list, create, rename and archive field definitions. Fields are addressed by their key — the API never exposes the DB id. The type picker offers every field type including address and opens with a fixed menu position so it isn't clipped by the modal. admin-x- framework gains a presentation-only catalog (label, icon, input control) over the shared field types; the create form sends just a name and type since the backend mints the key. A Labs private-features toggle enables the flag, and the Ember state bridge maps the new response type (React-only, no Ember model). Acceptance tests cover the flag gating, listing, create, the duplicate-name guard, rename and archive.
c24f38c to
2ceab58
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/admin-x-framework/src/api/member-custom-fields.ts (1)
66-69: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRename the hook to comply with React rules of hooks.
The
createQueryWithIdfactory returns a custom React hook. However, the namegetMemberCustomFielddoes not start withuse. Renaming it touseGetMemberCustomField(oruseMemberCustomField) ensures that theeslint-plugin-react-hookslinter will correctly enforce the rules of hooks when it is used downstream.♻️ Proposed refactor
-export const getMemberCustomField = createQueryWithId<MemberCustomFieldsResponseType>({ +export const useGetMemberCustomField = createQueryWithId<MemberCustomFieldsResponseType>({ dataType, path: key => `/members/custom_fields/${key}/` });🤖 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 `@apps/admin-x-framework/src/api/member-custom-fields.ts` around lines 66 - 69, Rename the exported createQueryWithId hook from getMemberCustomField to useGetMemberCustomField (or useMemberCustomField), and update all downstream references to the new use-prefixed name.
🤖 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.
Nitpick comments:
In `@apps/admin-x-framework/src/api/member-custom-fields.ts`:
- Around line 66-69: Rename the exported createQueryWithId hook from
getMemberCustomField to useGetMemberCustomField (or useMemberCustomField), and
update all downstream references to the new use-prefixed name.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0cecad88-bd90-4cbb-805d-f126ac8b2fa7
📒 Files selected for processing (33)
apps/admin-x-framework/package.jsonapps/admin-x-framework/src/api/member-custom-fields.tsapps/admin-x-settings/src/components/settings/advanced/labs/private-features.tsxapps/admin-x-settings/src/components/settings/membership/custom-fields.tsxapps/admin-x-settings/src/components/settings/membership/custom-fields/custom-field-modal.tsxapps/admin-x-settings/src/components/settings/membership/membership-settings.tsxapps/admin-x-settings/src/components/sidebar.tsxapps/admin-x-settings/test/acceptance/membership/custom-fields.test.tsghost/admin/app/services/state-bridge.jsghost/admin/package.jsonghost/core/core/boot.jsghost/core/core/server/api/endpoints/index.jsghost/core/core/server/api/endpoints/member-custom-fields.tsghost/core/core/server/api/endpoints/utils/serializers/output/index.jsghost/core/core/server/api/endpoints/utils/serializers/output/member-custom-fields.tsghost/core/core/server/data/exporter/table-lists.jsghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-54-add-members-custom-fields.jsghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-56-add-members-custom-fields-permissions.jsghost/core/core/server/data/schema/fixtures/fixtures.jsonghost/core/core/server/data/schema/schema.jsghost/core/core/server/lib/case-keys.tsghost/core/core/server/lib/db-date.tsghost/core/core/server/services/gift-links/codec.tsghost/core/core/server/services/gift-links/schema.tsghost/core/core/server/services/gift-links/serializers.tsghost/core/core/server/services/members-custom-fields/actions.tsghost/core/core/server/services/members-custom-fields/codec.tsghost/core/core/server/services/members-custom-fields/index.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/core/server/services/members-custom-fields/service.tsghost/core/core/server/web/api/endpoints/admin/routes.js
🚧 Files skipped from review as they are similar to previous changes (23)
- ghost/core/core/server/data/exporter/table-lists.js
- ghost/core/core/server/api/endpoints/utils/serializers/output/index.js
- ghost/core/core/server/lib/db-date.ts
- apps/admin-x-framework/package.json
- ghost/core/core/server/services/members-custom-fields/codec.ts
- ghost/admin/package.json
- ghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-54-add-members-custom-fields.js
- ghost/admin/app/services/state-bridge.js
- ghost/core/core/server/services/gift-links/codec.ts
- ghost/core/core/server/api/endpoints/utils/serializers/output/member-custom-fields.ts
- ghost/core/core/server/services/members-custom-fields/index.ts
- ghost/core/core/server/data/migrations/versions/6.53/2026-07-14-16-47-56-add-members-custom-fields-permissions.js
- ghost/core/core/server/lib/case-keys.ts
- apps/admin-x-settings/src/components/settings/membership/membership-settings.tsx
- ghost/core/core/server/services/members-custom-fields/actions.ts
- apps/admin-x-settings/src/components/settings/advanced/labs/private-features.tsx
- apps/admin-x-settings/src/components/settings/membership/custom-fields.tsx
- ghost/core/core/boot.js
- ghost/core/core/server/api/endpoints/member-custom-fields.ts
- ghost/core/core/server/data/schema/schema.js
- ghost/core/core/server/services/members-custom-fields/serializers.ts
- ghost/core/core/server/data/schema/fixtures/fixtures.json
- ghost/core/core/server/services/members-custom-fields/schema.ts

ref BER-3785
The first vertical of membership custom fields: admins can define the fields their publication needs, ahead of collecting values against members. Ships behind the
membersCustomFieldsflag.What this adds
Admins can create, rename and archive custom fields — short text, long text, and address — in Membership settings, and manage them through the Admin API. Keys are minted from the field name on the server, so a field is referenced by a stable, readable handle. Field names are unique (case-insensitive), so the label is never ambiguous. Archiving is a soft delete that keeps both the key and name reserved forever; rename the archived field to free a name for reuse.
Architecture
The shared catalog is the single source of truth for what a field type is. The frontend layers presentation on top, the backend layers enforcement (validation, key minting, permissions, persistence), and neither re-implements the other's rules.
flowchart TB subgraph FE["Frontend (Admin)"] Settings["Settings UI<br/>define & manage fields"] Presentation["Presentation<br/>labels, icons, inputs"] end subgraph SHARED["Shared"] Catalog["Field Catalog<br/>Field Type → Data Type + validation"] end subgraph BE["Backend (Ghost Core)"] API["Admin API<br/>auth · permissions · flag"] Service["Definitions Service<br/>CRUD · minted keys"] end subgraph DB["Persistence"] Table[("Field definitions")] end Settings --> API --> Service --> Table Presentation -.-> Settings Catalog -.-> Presentation Catalog -.-> ServicePersistence. One row per field. The
typemaps through the catalog to a data type (text/json), which picks the value column when value storage lands in the next vertical. Bothkeyandnameare unique, andstatusis the archive flag (soft delete), so neither a key nor a name is ever reused.erDiagram members_custom_fields { string id PK string key UK string name UK string type string status }Scope
In: defining fields end to end (Settings + Admin API), every field type including the composite address type.
Out (later verticals): setting and reading values against members, the Member Details entry form, and collection through signup/landing forms, Stripe and import. Address is definable here even though the form to enter one arrives with the Member Details work — field type is an additive dimension by design.
Next entities (staff, posts). Fields live in
members_custom_fieldsnow, following themembers_*table convention. Supporting another entity later is one migration that generalises the definitions table (add anentity_type, backfillmember) plus that entity's value table — not a migration per field. The shared catalog and the service are already entity-agnostic, so only the table name is member-specific today.How to review
Six atomic commits, each a single concern building on the last:
Testing
HTTP integration tests drive the definitions API end to end: key minting and collision suffixing (two distinct names deriving the same slug), duplicate-name rejection (globally unique, case-insensitive) plus freeing a name by renaming its archived field, immutable key and type, over-long names, an empty body (400), each field type including address, not-found handling, archive (archived fields leave the list but keep their key and name reserved), the added/edited/archived action log, authorization (a role without the permission is rejected), and the flag off. The full permission role matrix is pinned in the migration test, and acceptance tests cover the Settings UI. Existing suites are unaffected.