Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

管理端元数据

Model derive 可在模型和字段元数据中保存可选的管理端标签及能力标志。afastorm 不生成或提供 管理页面,不负责授权,也不会在 Repository 方法中强制执行这些标志。应用集成层需要自行解释元 数据并在服务端实施访问控制。

#[derive(Model)]
#[orm(
    table = "posts",
    admin(label = "文章", list, detail, create, update, delete)
)]
struct Post {
    #[orm(primary_key, auto_increment, admin(label = "ID", list, detail, readonly))]
    id: Option<i64>,
    #[orm(admin(label = "标题", list, detail, create, update, search))]
    title: String,
    #[orm(admin(label = "正文", detail, create, update))]
    body: String,
    #[orm(soft_delete, admin(hidden))]
    deleted_at: Option<String>,
    #[orm(version, admin(label = "版本", detail, readonly))]
    version: i64,
}

模型级选项:label、list、detail、create、update、delete。字段级选项: label、list、detail、create、update、filter、search、readonly、hidden。 它们只作为元数据标签/布尔值保存,不会自动决定 UI 展示内容;hidden 和 readonly 也不是安全 边界。

可从 M::INFO 或 ORM 返回的注册模型元数据中读取这些设置。Web 集成仍应校验提交的字段名和值, 独立执行用户权限检查,并通过 Repository/查询 API 访问数据,不能将客户端控件视为授权机制。