Skip to main content

Module admin

Module admin 

Source
Expand description

R-CMS admin section.

Mounts at /cms-admin/ (distinct from rustango’s /__admin/ — the framework admin’s POST handlers do raw insert_returning against the DB, bypassing our Page::create_root / Page::create_child paths and producing malformed rows with empty path, depth = 0, and no type-whitelist enforcement).

This module owns the page-tree-aware CRUD surface. router is unauthenticated on its own: wrap it in with_login_required, which redirects anonymous visitors to the login URL and requires the cms_admin.access codename (or superuser) of signed-in users.

§Wiring

ⓘ
use std::sync::Arc;
use tera::Tera;

let mut tera = Tera::new("templates/**/*.html")?;
rustango_cms::admin::register_templates(&mut tera)?;
let tera = Arc::new(tera);

let cms_admin = rustango_cms::admin::with_login_required(
    rustango_cms::admin::router(tera.clone()),
    "/login",
);
let router = Router::new()
    .merge(cms_admin)
    .merge(rustango_cms::router(tera));

Modules§

admin_page
Extension point for custom admin pages.
chooser
Generic chooser registry — register a chooser for any #[derive(Model)] type, generalising the three hand-rolled choosers (page / snippet / document).
model_admin
Generic model-admin — a ModelViewSet-style CRUD admin for arbitrary #[derive(Model)] types, rendered inside the CMS admin chrome.
pagination
Shared pagination context for admin list pages.
report
Extensible report framework — a registerable Report trait
resources
Admin-resource registry — single source of truth for the CRUD permissions matrix on /cms-admin/roles/{id}/edit.

Structs§

ListQuery
Query string for the page list / search view.
PageForm
Form payload for the new-page and edit-page POST handlers.

Enums§

MemberLoginError
Why a member sign-in was refused.

Constants§

NOTIFICATION_MANAGE_CODENAME
Permission gating notification destinations — see notifications::CODENAME. Permission required to manage notification destinations.
SITE_MANAGE_CODENAME
Permission gating hostname → root-page mappings — see sites::CODENAME. Permission required to bind hostnames to pages.
TEMPLATE_EDIT_CODENAME
Permission codename gating the per-tenant template editor. Re-exported so seeding and the handler cannot drift apart on the string. Permission required to read or write templates.

Functions§

add_chrome
Fill a template context with the admin chrome — sidebar, branding, locale, the signed-in user.
authenticate_member
Sign a member in by username OR (lowercased) email + password, in tenant_slug (the tenant pool belongs to).
extend_ui_catalog
Merge host-supplied UI-catalog entries into the shared admin translator so a consumer’s own template chrome localizes through the same translate binding without clobbering the admin catalog. Merge extra UI-catalog entries into the shared admin translator’s per-locale catalogs, so a host that also wants to localize its own hardcoded template chrome can feed those strings through the SAME translate(locale=LANG) binding instead of registering a competing one (which would silently clobber the admin catalog — see rcms-blog).
issue_password_reset_link
A one-hour password-reset link for the active user username in the tenant pool belongs to, or None when there is no such user.
public_router
Companion to router — routes that must remain reachable without authentication (password reset). Host apps merge this alongside the protected admin router so anonymous visitors can hit /cms-admin/password-reset* even when the rest of /cms-admin/* is gated by with_login_required.
public_router_with_mailer
Like public_router, with the mailer that sends password-reset emails. Without it /cms-admin/password-reset accepts the request but can’t send anything. Pass the same mailer and From: address as router_with_mailer.
register_templates
Register the bundled admin templates and the Tera helpers they depend on (named URL reversal via {{ url(...) }}, the {% querystring %} filter, humanize filters, and the csrf_input filter) on a Tera instance.
router
Build the admin router. Mount with Router::merge in the host app’s main router.
router_with_invalidator
Like router but takes a page-cache invalidator. Hosts using the public router’s CachePageLayer should wire the same cache backend into a crate::cache_invalidate::BoxedCacheInvalidator so admin saves purge the matching cache keys immediately.
router_with_mailer
Like router but takes both a cache invalidator AND a mailer. The mailer powers workflow notifications — submit / approve / reject / cancel each fire emails to the relevant parties. from_addr is the From: address stamped onto every notification.
with_cms_admin_access
Gate the CMS-admin router on the cms_admin.access codename.
with_codename_gate
Hard-gate router on an arbitrary permission codename — the generalized form of with_cms_admin_access. A non-superuser lacking codename is redirected to no_access_url; superusers pass; anonymous flows fall through to the layered login_required bounce. Static assets + the no-access page itself always pass so the redirect can’t loop and the page can style itself.
with_login_required
Layer rustango::auth_decorators::login_required on top of the supplied router. Every protected route 302s anonymous visitors to login_url with ?next=<original_url> so the framework’s login handler can resume them after auth.