Skip to content

PhoenixKit 2.4.0: Unique slugs, a private activity log and anonymous forms

PhoenixKit 2.4.0 makes slugs unique where they were meant to be, limits the full activity log to administrators, and fixes public entity forms that failed for visitors who were not signed in.

Slugs that stay unique and stay put

Modules each had their own code to turn a title into a unique slug, with different mistakes in each. Core now offers one helper, PhoenixKit.Utils.Slug.put_slug/3, for changesets. An explicit slug wins, a cleared slug is generated again, and an edit form that does not send a slug leaves it as it is. That last case used to give a page a new address when it was saved. It adds -2, -3 and so on until a slug is free, and keeps within a maximum length the caller set.

Three migrations back this with database indexes:

  • V167 makes post slugs unique. Two posts could share a slug, and then opening that address crashed. Existing duplicates get a number added, keeping a published post over a draft and then the oldest. If two published posts share a slug, the migration stops and names it, so you decide which keeps the address.
  • V168 makes ticket slugs unique, and post group slugs unique per user.
  • V169 is described below.

The activity log is for administrators

Everyone with the dashboard permission could read the whole activity log at /admin/activity. It is now limited to the Owner, Admin and superadmin roles. Everyone else sees only the entries for actions they performed themselves, and the count and pages follow. Opening someone else’s entry answers that it was not found. The log also crashed on any entry whose details held a change, such as a quantity going from 1 to 2. Such changes now show as 1 → 2.

Anonymous entity submissions

On a freshly installed database, every submission of a public entity form by a visitor who was not signed in failed, because the creator column did not allow an empty value. Migration V169 lets it be empty, as it already was on older installs. V169 also removes a duplicate foreign key on AI requests.

Other fixes

  • Eleven foreign key checks in storage, admin notes, OAuth providers and roles never matched the real constraint names, so a violation came back as a server error. They now give a form error.
  • Form labels used daisyUI 4’s label-text class, which daisyUI 5 does not style, on the sign-in pages and across the admin. They now use fieldset-legend.

Upgrading

Run mix phoenix_kit.update for migrations V167 to V169. Modules that use put_slug/3 need {:phoenix_kit, "~> 2.4"}.

Full release notes: PhoenixKit 2.4.0

2.4.0 · 14 August 2026

Slug uniqueness gets both halves it was missing — a changeset helper and the indexes to back it — plus anonymous entity submissions, and an activity log that is no longer readable by every dashboard-holder. Chain moves V166 → V169.

Added

  • PhoenixKit.Utils.Slug.put_slug/3 — the changeset glue between slugify/2 and ensure_unique/2 that core never owned, so it was hand-rolled 14 times across 8 packages and each copy got a different subset right. It distinguishes the three states get_change(:slug) conflates: an explicit slug wins, an explicitly blanked one regenerates, and no slug in the changeset means unchanged — which is what every edit form sends, and why saving one used to move a live URL. Suffixes -2, -3 … until free, excludes the row itself on update, honours a schema prefix, and takes :scope for per-owner uniqueness. The probe is an allocator, not an integrity boundary — callers still declare unique_constraint/3, which is what makes it true (#711).

    Adopters must pin {:phoenix_kit, "~> 2.4"}: ~> 2.0 resolves to a core without this function, and the failure lands in the consumer’s app.

  • PhoenixKit.Activity.full_log_access?/1 and own_entry?/2 — the shared definition of “may read the whole audit log” and “is this entry mine”, deliberately in one place so the list and the detail page cannot drift (#712).

Fixed

  • /admin/activity crashed on any entry whose metadata held a map. A field-change diff (%{"qty" => %{"from" => 1, "to" => 2}}) was interpolated straight into the template, raising Protocol.UndefinedError for String.Chars on a Map. Rendered as 1 → 2 now, via Activity.humanize_metadata_value/1; legacy rows that stored an inspect-ed Decimal are unwrapped to the number rather than leaking Elixir syntax (#712).

  • The full activity log was visible to every holder of the dashboard permission. It is now administrators-only — Admin, Owner, or a "*" superadmin role; everyone else sees only entries they authored. Enforced server-side in the query (the pagination total is scoped too, so it cannot leak the existence of hidden entries), and the detail page answers not found rather than confirming another user’s record exists. “Own” means actor, not target (#712).

  • Anonymous public entity submissions failed on a freshly migrated database. phoenix_kit_entity_data.created_by_uuid was NOT NULL while the public entity form is deliberately unauthenticated, so every submission raised a not_null_violation out of an unauthenticated controller. V169 relaxes the column, resolving a split where long-lived installs already measured is_nullable = YES and fresh ones NO. Auto-filling the first Owner was implemented first and rejected: it puts a named person in front of every anonymous submission and files it in their audit trail (#711, #706).

  • Eleven foreign_key_constraint/2 declarations could never match. Ecto matches by name and this chain names most foreign keys fk_<table>_<column>, not the <table>_<column>_fkey the bare declaration derives — so violations escaped as raw Ecto.ConstraintError 500s across storage, admin notes, OAuth providers, role assignments and role permissions. Names were taken from a migrated database rather than read off the chain, because a renamed column can leave a constraint carrying its old name. A new test pins the rule so the next schema cannot repeat it (#711).

  • ensure_unique/2 overflowed a :max_length the caller had already applied — slugify(title, max_length: 20) plus -2 is 22 characters, which silently defeats an SEO cap and raises against varchar(n). It now trims the base per candidate, since -10 needs one more character than -9 (#711).

  • V169.down/1 locked a table it never checked existed. up/1 guards its phoenix_kit_entity_data work on table existence; down/1 reached straight for LOCK TABLE, which has no IF EXISTS form — so rolling back on an install without the entity tables aborted with relation does not exist, having had nothing to undo. Found in post-merge review; lock_table_guard_test.exs now pins the rule for every LOCK TABLE in the chain.

Migrations

  • V167 — phoenix_kit_posts_slug_index becomes unique. It had been a plain btree since V135 while its sibling post_tags.slug was unique, so Post‘s unique_constraint(:slug) had no index to translate and get_post_by_slug/2 (which fetches with one()) raised Ecto.MultipleResultsError on any shared URL. Existing duplicates are suffixed by the same rule ensure_unique/2 applies at runtime, keeping a reachable post over a draft and then the oldest; two live posts on one slug raises instead, because which one keeps the URL is the operator’s call.

  • V168 — the remaining two. phoenix_kit_tickets had a plain btree; phoenix_kit_post_groups had no slug index at all while PostGroup named a composite [:user_uuid, :slug] index that existed nowhere. Post-group slugs are unique per user, so that index is scoped to the owner.

  • V169 — the nullable creator column and the duplicate prompt_uuid foreign key described above. The legacy phoenix_kit_ai_requests_prompt_uuid_fkey is the survivor, since it is what the installed base carries and what Ecto derives by default, so no live database is renamed.

    The DROP before each CREATE UNIQUE INDEX is load-bearing: CREATE UNIQUE INDEX IF NOT EXISTS matches on name, so building a unique index over a non-unique one of the same name skips with a notice and reports success while uniqueness stays unenforced.


PhoenixKit 2.4.0. Install or update: {:phoenix_kit, "~> 2.4"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.