Skip to content

feat(slugField): prevent non-admins from changing slugs after creation - #364

Merged
Ardnived merged 4 commits into
mainfrom
feat/360-slug-lock-non-superadmin
May 13, 2026
Merged

Ardnived merged 4 commits into
mainfrom
feat/360-slug-lock-non-superadmin

Conversation

@Ardnived

@Ardnived Ardnived commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #360

Problem

The slug field is a stable app-readable identifier the mobile client relies on (e.g. quick-meditation--10-min). Non-admin editors could:

  1. Click "Unlock" to switch the field to editable state
  2. Click "Generate" to overwrite the slug value in the form
  3. Save — changing the slug silently breaks all client references

Solution — two layers

Layer What it does
UI (LockedSlugField component) Non-admins see only a read-only label + input — no Unlock or Generate buttons at all
API (access.update: adminOnlyFieldAccess) Server strips slug changes on save even if submitted directly via the API

create stays open

Non-admins can still set the slug when creating a new document (first save). Only update is restricted.

Changes

  • src/components/admin/LockedSlugField/index.tsx — new 'use client' component; renders full SlugField for admins, plain read-only TextInput for everyone else
  • src/fields/slugField.ts — registers LockedSlugField as admin.components.Field and passes useAsSlug via admin.custom; locks checkbox (generateSlug) to admin-only on update
  • src/collections/tags/UserChoices.ts — simplified overrides (redundant per-field lock removed)
  • tests/int/role-based-access.int.spec.ts — two new cases verifying API-layer slug protection

Affected collections (automatic via slugField factory)

Pages, Authors, Meditations, SongTags, UserChoices

Test Results

  • Integration tests: 656 passed (2 flaky perf-benchmark failures unrelated to this change)
  • Build: ✓ (lint passes)

🤖 Generated with Claude Code

Ardnived and others added 4 commits May 8, 2026 14:37
… update

Non-admin managers can no longer change a slug after it is set.
The generateSlug checkbox is hidden from non-admin UIs and its update
access is blocked at the API layer. The slug text field update is
likewise restricted. create access is left open so editors with
collection-level create permission can still populate the slug on
first save.

Simplifies UserChoices.ts: the explicit inner-field locking is now
redundant with the new slugField default.

Closes #360

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Adds two integration tests to the Slug field access describe block:
- meditations-editor cannot change the slug of a user-choice
- admin manager can change the slug

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…kedSlugField

Adds a custom LockedSlugField client component registered as admin.components.Field
on the slug text field. Admins get the full SlugField UI (unlock/generate buttons);
non-admins see only a read-only label + input with no interactive controls.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Standalone component with no sub-components — matches the flat-file
convention used by AppCardViewSchedule.tsx, TimestampInput.tsx, etc.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@Ardnived
Ardnived merged commit 7702cb0 into main May 13, 2026
@Ardnived
Ardnived deleted the feat/360-slug-lock-non-superadmin branch May 13, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent non-super admins from unlocking the slug

1 participant