feat: implement on_tenant_created/deleted hooks and update ErpModule trait

- ErpModule trait hooks now accept db and event_bus parameters
- AuthModule.on_tenant_created: seeds default roles, permissions,
  and admin user for new tenants using existing seed_tenant_auth()
- AuthModule.on_tenant_deleted: soft-deletes all users for the tenant
- Updated all other modules (config, workflow, message) to match
  the new trait signature
This commit is contained in:
iven
2026-04-15 01:27:33 +08:00
parent e44d6063be
commit d8a0ac7519
5 changed files with 94 additions and 14 deletions

View File

@@ -26,13 +26,26 @@ pub trait ErpModule: Send + Sync {
/// 注册事件处理器
fn register_event_handlers(&self, _bus: &EventBus) {}
/// 租户创建时的初始化钩子
async fn on_tenant_created(&self, _tenant_id: Uuid) -> AppResult<()> {
/// 租户创建时的初始化钩子
///
/// 用于为新建租户创建默认角色、管理员用户等初始数据。
async fn on_tenant_created(
&self,
_tenant_id: Uuid,
_db: &sea_orm::DatabaseConnection,
_event_bus: &EventBus,
) -> AppResult<()> {
Ok(())
}
/// 租户删除时的清理钩子
async fn on_tenant_deleted(&self, _tenant_id: Uuid) -> AppResult<()> {
/// 租户删除时的清理钩子
///
/// 用于软删除该租户下的所有关联数据。
async fn on_tenant_deleted(
&self,
_tenant_id: Uuid,
_db: &sea_orm::DatabaseConnection,
) -> AppResult<()> {
Ok(())
}