63 lines
2.6 KiB
Python
63 lines
2.6 KiB
Python
"""ORM model for sidebar-menu overrides (菜单管理).
|
|
|
|
``menu_overrides`` stores the administrator's shared default. Personal layouts
|
|
live separately in ``user_menu_override_configs`` as complete snapshots. The
|
|
static menu tree (icons / routes / adminOnly) lives in the frontend code; the
|
|
default table stores per-node **overrides** keyed by the static node id (or an
|
|
injected iframe light-app node id ``light-app-<appId>``):
|
|
|
|
- ``parent_id`` — the effective parent node id (NULL = top level). Re-parenting
|
|
a node moves its whole subtree.
|
|
- ``sort_order`` — position among siblings under the effective parent.
|
|
- ``label`` — rename; NULL keeps the code-defined label.
|
|
- ``disabled`` — hide the node (and its subtree) from the sidebar.
|
|
|
|
A node with no row here renders exactly as the code defines it. ``updated_by``
|
|
is audit-only.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import Boolean, Integer, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from deerflow.persistence.base import Base
|
|
from deerflow.persistence.types import BeijingDateTime, PortableJSON
|
|
|
|
|
|
class MenuOverrideRow(Base):
|
|
__tablename__ = "menu_overrides"
|
|
|
|
node_id: Mapped[str] = mapped_column(String(128), primary_key=True)
|
|
# Effective parent node id; NULL = top-level menu.
|
|
parent_id: Mapped[str | None] = mapped_column(String(128), index=True)
|
|
sort_order: Mapped[int] = mapped_column(Integer, default=0)
|
|
# Rename override; NULL keeps the code-defined label.
|
|
label: Mapped[str | None] = mapped_column(String(255))
|
|
disabled: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
updated_by: Mapped[str | None] = mapped_column(String(64))
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
BeijingDateTime(), default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC)
|
|
)
|
|
|
|
|
|
class UserMenuOverrideConfigRow(Base):
|
|
"""A complete personal sidebar-menu snapshot.
|
|
|
|
Keeping the snapshot in one row is deliberate: the presence of a row is
|
|
the ``has_user_override`` bit, while the node ids in ``overrides`` are the
|
|
user's known-node set. This lets us distinguish an administrator-added
|
|
node from an old node the user intentionally left at its default value.
|
|
"""
|
|
|
|
__tablename__ = "user_menu_override_configs"
|
|
|
|
user_id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
overrides: Mapped[list[dict]] = mapped_column(PortableJSON(), nullable=False, default=list)
|
|
updated_by: Mapped[str | None] = mapped_column(String(64))
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
BeijingDateTime(), default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC)
|
|
)
|