feat(plugin): 实现插件权限注册,install 时写入 permissions 表、uninstall 时软删除
跨 crate 方案:erp-plugin 使用 raw SQL 操作 permissions 表, 避免直接依赖 erp-auth entity,保持模块间松耦合。 - erp-core: 新增 PermissionDescriptor 类型和 ErpModule::permissions() 方法 - erp-plugin service.rs install(): 解析 manifest.permissions,INSERT ON CONFLICT DO NOTHING - erp-plugin service.rs uninstall(): 软删除 role_permissions 关联 + permissions 记录
This commit is contained in:
@@ -8,4 +8,4 @@ pub mod rbac;
|
||||
pub mod types;
|
||||
|
||||
// 便捷导出
|
||||
pub use module::{ModuleContext, ModuleType};
|
||||
pub use module::{ModuleContext, ModuleType, PermissionDescriptor};
|
||||
|
||||
@@ -7,6 +7,22 @@ use uuid::Uuid;
|
||||
use crate::error::{AppError, AppResult};
|
||||
use crate::events::EventBus;
|
||||
|
||||
/// 权限描述符,用于模块声明自己需要的权限。
|
||||
///
|
||||
/// 各业务模块通过 `ErpModule::permissions()` 返回此列表,
|
||||
/// 由 erp-server 在启动时统一注册到权限表。
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PermissionDescriptor {
|
||||
/// 权限编码,全局唯一,格式建议 `{模块}.{动作}` 如 `plugin.admin`
|
||||
pub code: String,
|
||||
/// 权限显示名称
|
||||
pub name: String,
|
||||
/// 权限描述
|
||||
pub description: String,
|
||||
/// 所属模块名称
|
||||
pub module: String,
|
||||
}
|
||||
|
||||
/// 模块类型
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ModuleType {
|
||||
@@ -90,6 +106,13 @@ pub trait ErpModule: Send + Sync {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 返回此模块需要注册的权限列表。
|
||||
///
|
||||
/// 默认返回空列表,有权限需求的模块(如 plugin)可覆写此方法。
|
||||
fn permissions(&self) -> Vec<PermissionDescriptor> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
/// Downcast support: return `self` as `&dyn Any` for concrete type access.
|
||||
///
|
||||
/// This allows the server crate to retrieve module-specific methods
|
||||
|
||||
Reference in New Issue
Block a user