Skip to main content

Module view_restriction

Module view_restriction 

Source
Expand description

PageViewRestriction — gate published pages behind a password, a login requirement, or a group membership check.

Restrictions inherit down the subtree: a restriction on /members covers every descendant unless a descendant declares its own restriction. The public renderer walks the ancestor chain at request time and applies the nearest restriction it finds.

Four kinds (including #members):

  • password — anonymous visitor sees a prompt form, enters the password, gets a signed cookie that skips the prompt on subsequent visits.
  • login — anonymous visitor redirected to /members/login?next=<url>. Any authenticated member/admin passes.
  • groups — logged-in visitor must be a member of at least one of the named roles (raw role_id match). Anonymous → /members/login; logged-in but not in any allowed group → 403.
  • permission — logged-in visitor must hold at least one of the named permission codenames, resolved through the framework permission engine (has_any_perm_pool — superuser + per-user grant/deny baked in). This is the members-area gate; roles carry the codenames, admins assign the roles.

A page-type can also declare a login/permission restriction for every page of that type (see TypeViewRestriction + effective_or_type_for_page).

Structs§

AccessContext
A resolve-once, in-memory oracle for “can this viewer see page X?”. Built per render by access_context and reused for viewer-aware menu hiding and the can_view / visible Tera helpers (so a template can guard any hand-written page link or nested list with the same protection the built-in menus apply). Holds the viewer’s resolved facts + every tenant view-restriction (page/subtree and per-type), so AccessContext::can_view answers with zero further queries.
PageViewRestriction
TypeViewRestriction
A page-type-level view restriction declared by a crate::page_type::PageTypeHandler::view_restriction hook. Only Login and Permission kinds make sense at the type level (password + groups need per-page configuration). Applied only when a page carries no page/subtree restriction of its own.
ViewerFacts
A viewer’s resolved access facts, independent of what is being guarded.

Enums§

RestrictionKind

Functions§

access_context
Build the per-render AccessContext for viewer: load every tenant restriction (+ the restricted pages’ paths) and per-type restriction, and resolve the viewer’s codenames + role ids. Bounded, fixed number of queries; the viewer lookups are skipped entirely when nothing is gated or the viewer is a superuser.
denied_page_ids
Given a batch of pages and a viewer, return the subset of page ids the viewer may not access — for viewer-aware menu hiding shared by auto_menu and the curated navigation resolver. pages are (page_id, materialized_path, page_type_id) triples. Thin wrapper over access_context + AccessContext::can_view.
direct_for_page
Look up a direct (non-inherited) restriction on a single page.
effective_for_page
Walk the page + every ancestor in path order (current page first, then parent, then grand-parent, …) and return the nearest restriction found. Used by the public renderer middleware.
effective_or_type_for_page
The page’s effective restriction (own + inherited from any ancestor), OR — when none is set anywhere on the branch — the restriction its page type declares via crate::page_type::PageTypeHandler::view_restriction. A concrete page/subtree restriction is more specific and always wins over the type-level one.
effective_restrictions_for
Bulk-resolve the effective page/subtree restriction for many pages at once — for viewer-aware menu filtering, where calling effective_for_page per item would be an N+1 on every render.
only_anonymous_visible
Narrow a page query to what an anonymous visitor may see.
type_restriction_for_type
Resolve the type-level restriction for a page-type id, if the handler declares one. Used by menu filtering to hide type-gated pages; synthesizes a PageViewRestriction so callers share one predicate (viewer_satisfies).
viewer_facts
Resolve a viewer’s permissions and roles.
viewer_satisfies
Decide whether a viewer may see a restricted item, using pre-resolved viewer facts (so menu filtering avoids per-item queries). is_authed = a member/admin is signed in; is_super = superuser; perm_set = the viewer’s permission codenames (from user_permissions_pool); role_ids = the viewer’s role ids.