Skip to main content

Module admin

Module admin 

Source
Expand description

The auto-generated admin UI.

Structs§

Admin
Builder for the admin. Register models with .model::<M>(), then hand it to the router via register_admin_routes.
AdminAction
One action-log row as loaded from the DB. The user_email is joined in by recent and for_object so the timeline can render the acting user without a second round-trip.
AdminEntry
Runtime metadata about one admin-registered model.
AdminField
AdminRelation
FieldUI
Everything a form / list renderer needs to present one field to a human. All strings are plain text (no HTML) — the caller escapes before emitting.
FilterDef
One filter the list page should show for a model. Produced by infer_filters.
InverseRelation
One reverse (HasMany) relation — an incoming edge pointing at a given target model. Produced by inverting every stored BelongsTo at registry-build time. Consumed by the inverse-panel renderer and the delete guard.
LogEntry
What callers hand to record. Kept as a borrow-friendly struct so handlers don’t need to clone field strings.
RelationRegistry
Relation lookup tables for one snapshot of the schema.
ResolvedRelation
One forward (BelongsTo) relation resolved against the schema.
SiteBranding
Per-project admin branding. Defaults are RustIO-flavoured; projects override via Admin::site_branding.
Suggestion
One proposed action shown next to a dashboard alert.
UserProfileRow
One key-value row inside a UserProfileSection. Both fields are String so projects can format whatever shape they need (numbers, dates, comma-joined lists). Rendered escaped — pass plain text; for arbitrary HTML, projects override the template block instead.
UserProfileSection
One labeled section rendered in the project-extension area of the built-in user profile page (admin/user_view.html — {% block project_user_fields %}). A project’s extension closure returns Vec<UserProfileSection> so it can contribute multiple disjoint areas (e.g. “Halal certification” + “Restaurant assignments”) in a single registration.

Enums§

ActionType
The three classes of admin mutation we track. delete covers both individual and bulk deletions — each bulk-delete row writes its own Delete entry so object history is per-row complete.
Confidence
How sure the suggestion engine is that this is the right action.
FieldRole
The role a field plays in the admin UI. One field maps to exactly one role; the ordering of branches in classify_field resolves overlaps (e.g. an email column is FieldRole::Email, not FieldRole::PlainText).
FieldType
FilterKind
What shape of filter the admin list page should render for a given field. Each variant maps to a concrete HTML control.
RegistryError
Why a RelationRegistry declaration was rejected. Each variant names the enclosing relation so CLI tooling (rustio schema, ai validate) can point a user straight at the bad declaration.
SearchIntent
What the user probably typed into the list-page search box. Letting the handler branch on this gives cleaner narrow-match behaviour than “grep every String field”.

Constants§

RELATION_FILTER_DROPDOWN_CAP
Soft cap on the number of rows a relation filter will expose as a <select> dropdown. Above this threshold the admin renders a numeric-id input instead, with a muted hint explaining why.

Traits§

AdminModel
What the #[derive(RustioAdmin)] macro produces for each struct.

Functions§

classify_field
Assign a FieldRole to one field, taking context into account.
classify_search
Guess what the user meant by the text in the list-page search box. Order of tries: numeric → email → personnummer → text.
classify_search_for_field
0.8.0 — variant of classify_search that knows the field is a relation. When the query parses as a non-negative integer, emits SearchIntent::RelationId carrying the target model; otherwise falls through to classify_search for the usual shape-based routing. Called by the admin search handler when the user is searching a specific FK column.
context_global
Process-global cache for the project’s rustio.context.json.
derive_relation_suggestions
0.8.0 — propose linking an orphan <thing>_id column to a known model when the schema has no Relation recorded for it. Fired from &Schema directly because relation metadata lives there (not on admin entries).
derive_suggestions
Enumerate every suggestion for the current project. Empty when no context is loaded or when no model overlaps the industry’s convention list. Deterministic: iteration follows the order of entries then industry_schema.required_fields.
derive_suggestions_from_entries
0.7.3 schema-backed variant. Same rules as derive_suggestions but reads field names from [DynamicAdminEntry], which the admin builds fresh from [crate::admin::schema_cache] on every dashboard render. When the cache sees an updated rustio.schema.json — e.g. after rustio ai apply + rustio schema + [Reload schema] — the suggestion for the just-added field disappears on the next response, without restarting the process.
ensure_table
Ensure the rustio_admin_actions table and its indexes exist. Idempotent — uses CREATE TABLE IF NOT EXISTS + CREATE INDEX IF NOT EXISTS. Depends on rustio_users existing first (the FK target); callers should run auth::init_user_tables before this.
field_ui_metadata
Package a field’s display metadata for the admin form / list renderers. All strings are plain text — escape before emitting.
field_ui_metadata_with_relation
0.8.0 — like field_ui_metadata but relation-aware. Pass the singular display name of the target model (e.g. "Applicant") when the schema records a relation for this field; the returned FieldUI then carries relation_label and a form hint of the form “Foreign key to Applicant”. Passing None is equivalent to calling field_ui_metadata.
find_relation_suggestion
Companion to derive_relation_suggestions — locate one by (admin_name, field). Same rejection-of-crafted-URLs story as find_suggestion.
find_suggestion
Look up a specific suggestion by (admin_name, field). Returns None if the pair isn’t in the current derived set — this is how the route handlers reject crafted URLs. An operator can only click through suggestions the engine actually produced.
find_suggestion_from_entries
Schema-backed counterpart to find_suggestion.
for_object
All actions for one (model, object_id), newest first.
format_relation_cell
Render “Target #42” for a foreign-key cell on a list view. Falls back to the raw id when the caller doesn’t have a target name. Kept as a free function so the admin list renderer doesn’t have to reach into FieldUI directly for the common case.
infer_filters
Infer the filter controls for a model’s list page from its fields plus active context. Order follows the order of fields; every filter references a field that actually exists on the model.
infer_filters_with_relations
0.8.0 — like infer_filters but invokes relation_target_of for each field to detect relation columns. If the callback returns Some(target), the filter is emitted as FilterKind::RelationSelect instead of the numeric-exact fallback.
mask_pii
Produce a masked display string for a sensitive value. Keeps the first few characters so a reviewer can tell which row they’re looking at, replaces the rest with . Length of the output matches the input so the layout doesn’t jump when a user toggles visibility.
recent
Fetch the most recent limit admin actions, newest first. Optional filters by model_name and by action_type string (the UI passes both through as URL query params, so we take them as &str rather than typed enums).
record
Write one row to the action log.
register_admin_routes