Menu API
Routes are added to the sidebar navigation via the @menu_entry decorator.
Basic usage
from fastpluggy.core.menu.decorator import menu_entry
@menu_entry(label="Dashboard", icon="ti ti-dashboard")
@router.get("/dashboard", response_class=HTMLResponse)
async def dashboard(request: Request): ...
Decorator parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label |
str |
required | Text shown in the sidebar. |
icon |
str |
"" |
Icon CSS classes, e.g. "ti ti-home" or "fas fa-chart-bar". |
parent |
str \| None |
None |
Name of a parent item to nest under. |
type |
str |
"main" |
"main" (the sidebar) or "admin" (Plugin tools on the admin home). |
position |
int \| None |
None |
Sort order within the parent (lower = higher). |
divider_before |
bool |
False |
Render a separator line above this item. |
divider_after |
bool |
False |
Render a separator line below this item. |
required_role |
str \| None |
None |
Role the current user must hold for this item to render. Checked via the auth backend's user_has_role (see below). |
permission |
str \| None |
None |
Legacy permission string — not enforced by core; use required_role instead. |
group |
str \| None |
None |
Section group name for sidebar rendering (e.g. "Overview", "System"). |
badge |
str \| None |
None |
Badge text shown on the item (e.g. "3", "NEW"). |
badge_color |
str \| None |
None |
Badge colour class: "success", "danger", "warning" or "info". |
badge_animate |
bool |
False |
Make the badge blink (for live indicators). |
Routes with path parameters
The menu link is built by reversing the route by name. That only yields a usable URL when the
route has no path parameter, or when its last path parameter is optional (has a default),
in which case core passes an empty string for it (/browse/{path:path} with a default links to
/browse/). For any other path parameter, core falls back to the literal route path, so a menu
entry on /item/{id} links to /item/{id} and 404s.
Put the menu entry on a parameter-free landing route that redirects to the real page:
@menu_entry(label="Item", icon="ti ti-file")
@router.get("/item", name="item_landing")
async def item_landing(request: Request):
return RedirectResponse(request.url_for("item_detail", id=default_item_id()))
@router.get("/item/{id}", response_class=HTMLResponse, name="item_detail")
async def item_detail(request: Request, id: int): ...
Parent items
To group routes under a collapsible parent, create the parent in after_setup_templates
with add_parent_item and reference its parent_name in @menu_entry(parent=...):
# plugin.py
from fastpluggy.core.menu.schema import MenuItem
def after_setup_templates(self, fast_pluggy):
fast_pluggy.menu_manager.add_parent_item(
menu_type="main",
item=MenuItem(label="My Plugin", url="", icon="ti ti-star", parent_name="my_plugin", position=20),
)
# router.py
@menu_entry(label="Overview", icon="ti ti-layout-dashboard", parent="my_plugin")
@router.get("/overview", response_class=HTMLResponse)
async def overview(request: Request): ...
@menu_entry(label="Reports", icon="ti ti-report", parent="my_plugin", position=2)
@router.get("/reports", response_class=HTMLResponse)
async def reports(request: Request): ...
Admin section
Use type="admin" to list the entry under Plugin tools on the admin home, which the
sidebar's Admin entry opens (shown only to users with is_admin = True, or when auth is
disabled; see the Admin entry):
@menu_entry(label="Plugin Config", icon="ti ti-adjustments", type="admin")
@router.get("/config", response_class=HTMLResponse)
async def config(request: Request): ...
Role-gated menu items
Pass required_role to hide an item unless the current user holds that role. The
check runs for every rendered item via the auth backend's
user_has_role, so the policy lives in the
backend, not in the menu:
@menu_entry(label="My courses", icon="ti ti-chalkboard", required_role="teacher")
@router.get("/teacher/courses", response_class=HTMLResponse)
async def courses(request: Request): ...
required_role is a plain string label — a declarative "who is this for". The
default policy resolves it against request.auth.scopes plus a super-user
short-circuit: a user with is_admin (or any role in the backend's
super_user_roles, {"fp_admin", "admin"} by default) sees every item
regardless of required_role, so the admin console can never hide an item from
the admin who configures it. Apps needing role hierarchies, wildcards, or a
permission→role map override user_has_role — no menu changes required.
required_rolegates rendering, not access. Hiding the link does not protect the route — still gate the route itself withrequire_role(...)(see Auth). A link the user shouldn't reach should be both hidden and guarded.
permissionis a dead field — userequired_role. The olderpermissionparameter is carried throughto_dict()for backward compatibility but core never enforces it. New code should userequired_role.
Menu Management (admin overrides)
System › Menu Management lets an admin hide, move, relabel or role-gate any
entry of the main, user and admin menus without touching the plugin. Each
change is stored as a row of fp_core_menu_item_overrides, keyed by menu type
and URL; Reset deletes the row and the entry goes back to what the plugin
declared. The entries inside a plugin's group are listed under it and take
overrides like the top-level ones (a moved entry moves within its group). A
group without a page of its own has no URL to key an override on: it is listed
for orientation, without controls.
Every worker process keeps its own copy of the overrides. The worker that saves
a change applies it at once; the other workers read the table again at most
every 2 seconds (MENU_OVERRIDES_RECHECK_SECONDS), on the next request they
serve. So with several workers a change can take up to 2 seconds to show
everywhere, and no restart is needed. When the overrides change, the
menu.overrides_changed event is emitted in the worker that applies them.
Search palette (Ctrl K)
Every admin page has a search field in its top bar. Ctrl K (⌘ K on a Mac), or / typed outside a text field, opens it too. It finds:
- Pages: the entries of the sidebar and, for an administrator, the core's admin pages and the Plugin tools of the admin home;
- Plugins, for an administrator: each plugin's page and its Settings, Routes and Raw data tabs;
- Settings, for an administrator: each field of the application's settings and of each
enabled plugin's settings, by its label or its name. The result opens the form with the field
outlined and focused (
#setting-<field>on the page's URL).
The list comes from GET <admin>/search-index.json (route search_index). It is built on each
request and holds only what the caller may open: an entry with a required_role is left out
for a user who lacks the role, as in the sidebar. A plugin needs nothing to appear in it: a
@menu_entry route and a module_settings class are found.