feat(plugin): P1-P4 审计修复 — 第三批 (配置变更通知 + 自定义视图)

3.1 配置变更通知:
- update_config 增加 EventBus 参数
- 更新成功后发布 plugin.config.updated 事件
- handler 传入 event_bus

3.2 自定义视图:
- plugin_user_views 表迁移 (id/tenant_id/user_id/plugin_id/entity/view_name/view_config/is_default)
- CRUD API: GET/POST /plugins/{id}/{entity}/views, DELETE /plugins/{id}/{entity}/views/{view_id}
- 默认视图互斥逻辑
This commit is contained in:
iven
2026-04-19 18:25:03 +08:00
parent 0a041c3d22
commit a7a48167ca
8 changed files with 253 additions and 2 deletions

View File

@@ -446,6 +446,7 @@ impl PluginService {
config: serde_json::Value,
expected_version: i32,
db: &sea_orm::DatabaseConnection,
event_bus: Option<&erp_core::events::EventBus>,
) -> AppResult<PluginResp> {
let model = find_plugin(plugin_id, tenant_id, db).await?;
@@ -462,12 +463,26 @@ impl PluginService {
}
let now = Utc::now();
let manifest_id = manifest.metadata.id.clone();
let mut active: plugin::ActiveModel = model.into();
active.config_json = Set(config);
active.updated_at = Set(now);
active.updated_by = Set(Some(operator_id));
let model = active.update(db).await?;
// 发布配置变更事件
if let Some(bus) = event_bus {
let event = erp_core::events::DomainEvent::new(
"plugin.config.updated",
tenant_id,
serde_json::json!({
"plugin_id": manifest_id,
"updated_by": operator_id,
}),
);
bus.publish(event, db).await;
}
let entities = find_plugin_entities(plugin_id, tenant_id, db).await.unwrap_or_default();
Ok(plugin_model_to_resp(&model, &manifest, entities))
}