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-textclass, which daisyUI 5 does not style, on the sign-in pages and across the admin. They now usefieldset-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 betweenslugify/2andensure_unique/2that 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 statesget_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:scopefor per-owner uniqueness. The probe is an allocator, not an integrity boundary — callers still declareunique_constraint/3, which is what makes it true (#711).Adopters must pin
{:phoenix_kit, "~> 2.4"}:~> 2.0resolves to a core without this function, and the failure lands in the consumer’s app. -
PhoenixKit.Activity.full_log_access?/1andown_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/activitycrashed on any entry whose metadata held a map. A field-change diff (%{"qty" => %{"from" => 1, "to" => 2}}) was interpolated straight into the template, raisingProtocol.UndefinedErrorforString.Charson a Map. Rendered as1 → 2now, viaActivity.humanize_metadata_value/1; legacy rows that stored aninspect-ed Decimal are unwrapped to the number rather than leaking Elixir syntax (#712). -
The full activity log was visible to every holder of the
dashboardpermission. 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_uuidwas NOT NULL while the public entity form is deliberately unauthenticated, so every submission raised anot_null_violationout of an unauthenticated controller. V169 relaxes the column, resolving a split where long-lived installs already measuredis_nullable = YESand fresh onesNO. 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/2declarations could never match. Ecto matches by name and this chain names most foreign keysfk_<table>_<column>, not the<table>_<column>_fkeythe bare declaration derives — so violations escaped as rawEcto.ConstraintError500s 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/2overflowed a:max_lengththe caller had already applied —slugify(title, max_length: 20)plus-2is 22 characters, which silently defeats an SEO cap and raises againstvarchar(n). It now trims the base per candidate, since-10needs one more character than-9(#711). -
V169.down/1locked a table it never checked existed.up/1guards itsphoenix_kit_entity_datawork on table existence;down/1reached straight forLOCK TABLE, which has noIF EXISTSform — so rolling back on an install without the entity tables aborted withrelation does not exist, having had nothing to undo. Found in post-merge review;lock_table_guard_test.exsnow pins the rule for everyLOCK TABLEin the chain.
Migrations
-
V167 —
phoenix_kit_posts_slug_indexbecomes unique. It had been a plain btree since V135 while its siblingpost_tags.slugwas unique, soPost‘sunique_constraint(:slug)had no index to translate andget_post_by_slug/2(which fetches withone()) raisedEcto.MultipleResultsErroron any shared URL. Existing duplicates are suffixed by the same ruleensure_unique/2applies 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_ticketshad a plain btree;phoenix_kit_post_groupshad no slug index at all whilePostGroupnamed 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_uuidforeign key described above. The legacyphoenix_kit_ai_requests_prompt_uuid_fkeyis the survivor, since it is what the installed base carries and what Ecto derives by default, so no live database is renamed.The
DROPbefore eachCREATE UNIQUE INDEXis load-bearing:CREATE UNIQUE INDEX IF NOT EXISTSmatches 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.