Skip to main content

Module permissions

Module permissions 

Source
Expand description

Per-page permission engine.

Three pieces:

  1. PagePermission — (page_id, role_id, permission) grants stored in cms_page_permission. Sites grant fine-grained actions per role per subtree.
  2. user_can — (user_id, page_id, action) → bool. Walks the page’s ancestor chain collecting grants; superusers short-circuit to true.
  3. Action — the canonical set of action strings the engine recognizes. Stored as text so the framework’s permission system can interoperate via codenames if/when we expose them.

Permissions inherit down the tree: a grant on a page applies to every descendant unless overridden by a closer grant. There are no explicit denies — any matching grant in the chain returns true.

Structs§

CollectionPermission
One (collection_id, role_id, permission) grant — the media collection analogue of PagePermission. Same UNIQUE shape and same inheritance semantics (parent collection grants flow to children).
PagePermission
One (page_id, role_id, permission) grant. UNIQUE at the SQL layer so a role can’t be granted the same action twice on the same page.

Enums§

Action
Canonical action set the engine recognizes. Stored as text so authors can extend the surface without a schema change.

Functions§

user_can
Resolve (user_id, page_id, action) → bool against the per-page permission table. Walks ancestors via the cms_page.path materialized prefix and collects matching grants in one query.
user_can_in_collection
Resolve (user_id, collection_id, action) → bool against the per-collection permission table. Walks the collection’s ancestor chain (via parent_id) and short-circuits to true for superusers.
user_can_matrix
Resolve the full action matrix for a user on a page in one shot. Useful for the admin form-state computation where every action is checked together (so the page editor can disable Publish but allow Edit, etc.). Returns a fresh HashMap with one entry per action — true when granted, false when not.
user_codenames
Resolve the full set of role codenames a user inherits via their UserRole memberships. Used by the admin chrome to gate sidebar items + by handlers to enforce CRUD access against the permissions matrix.
viewable_page_ids
Which of pages — (id, parent_id) pairs — user_id may view: the set user_can with Action::View would allow, in a bounded number of queries instead of one walk per page. For list views, so a listing never shows a row its detail view refuses.