PhoenixKit 1.7.182: Admin follows the permission matrix, and sub-permissions
PhoenixKit 1.7.182 makes the Admin role follow the permission matrix like every other role. Only Owner keeps full access no matter what.
Admin still starts with every permission, and new module permissions are granted to it at boot. But when an Owner takes a permission away from Admin, it now stays away, also on a fresh page load. Stripping a role of every permission no longer gives it full access back.
Modules can now declare sub-permissions under their own key, such as viewing other people’s calendars. The matrix shows them indented under their module; granting one grants the module too, and revoking the module removes them. Role changes are checked on the server: someone who is not an Owner cannot give or take away Owner or Admin, and the last Owner can never be removed, even with two admins working at once. A checkbox tied to a form field now shows its saved value instead of always unchecked.
Upgrading
Run mix phoenix_kit.update for V141 (calendar events) and V142. Check Admin’s row in the permission matrix: permissions an Owner removed now really apply.
Full release notes: PhoenixKit 1.7.182
1.7.182 · 10 July 2026
Added
- Fine-grained sub-permissions. Modules can declare additive permissions under
their base key via the optional
sub_permissionsfield ofpermission_metadata/0(e.g."calendar.view_others"), stored inphoenix_kit_role_permissions.module_keyas composed dotted keys. A sub-permission implies its base: granting a sub auto-grants the base, revoking the base cascades its subs off, and every write path (grant_permission/3,revoke_permission/3,set_permissions/3) normalizes the set so no orphan sub-key row can persist. Modules check sub-grants withScope.can?/2(key held and module enabled). The permission matrix renders subs as indented rows under their module. (#627) V141— personal calendar events + participants for the standalonephoenix_kit_calendarmodule:phoenix_kit_calendar_events(one implicit personal calendar per user, timed/all-day exclusive-end pairs with a CHECK, cascade on user delete, looselocation_uuidlink) andphoenix_kit_calendar_event_participants(loosekind/target_uuidrefs with a snapshotteddisplay_name, visibility resolved live against staff/CRM tables). (#627)- Reusable core UI components.
SearchPicker(client-instant typeahead with browse-on-focus, per-instance event scoping,direction=up, cross-source dedup, load-more paging),PopoverPanel(anchored rich-content popover, client-side open/close with click-away), and thePkDialogDraftJS hook (preserves an open form’s draft across a LiveView reconnect). Both function components are imported intoPhoenixKitWeb. (#627)
Changed
- Admin is now genuinely permission-gated. Only
Owneris hard-coded as all-access;Admin(and every other role) is governed by the permission matrix. Admin defaults to all keys via seeding/auto-grant, and a boot-time Task (auto_grant_new_keys_to_admin/0) fills newly-installed module keys — but an Owner’s revocation now sticks everywhere, including fresh mounts (previously the system-role bypass ignored revocations on fresh mounts). The full-access fallback keys on table presence (permissions_table_ready?/0), not row count, so stripping a role bare can no longer restore access, and a DB blip fails closed. (#627) V142widensphoenix_kit_role_permissions.module_keyVARCHAR(50) → VARCHAR(120)so composed sub-permission keys fit. (#627)- Role changes are authorized in the context.
sync_user_roles/3takes an:actorand drops changes the actor isn’t allowed to make (a non-Owner can’t grant or strip Owner/Admin); the last Owner can never be removed. The quick role-toggle and the permission-matrix revoke route through the same guards. The function now returns{:ok, %{assignments, roles_before, roles_after}}so audit logs record the delta actually applied, not the submitted set. (#627) Checkboxcheckeddefault is nownil(“derive from the field’s value”) — a non-nil attr default defeated the field clause’sassign_new, so a field-bound checkbox always rendered unchecked. (#627)AdminPageHeaderaccepts aclassto override its default bottom margin (e.g."mb-0"when the page owns spacing). (#627)
Fixed
- Role/permission mutations are race-free under concurrent admins.
Transaction-scoped Postgres advisory locks + in-transaction re-reads: the last
Owner can never reach zero (shared lock at
count_remaining_owners), the matrix revoke re-reads the role’s held keys under a(role, base)lock and rejects (:unauthorized) if a cascaded sub falls outside the actor’s grantable set, andset_permissions/3locks theRolerow so two concurrent calls can’t leave the union of disjoint desired sets. (#627) - Post-merge review: refactored
grant_permission/3to satisfycredo --strict(removed a redundantwithclause and one nesting level) — the base-then-sub cascade and rollback behavior are unchanged. (#627)
PhoenixKit 1.7.182. Install or update: {:phoenix_kit, "~> 1.7"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.