mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 10:27:46 +08:00
refactor: 大规模模块拆分与重组,新增 aether-admin crate
- 新建独立 aether-admin crate 承载 admin 相关共享契约与纯辅助函数 - 拆分 ai_pipeline 下 kiro/private_envelope/conversion/planner 等大文件为子模块目录 - 重组 admin handlers 各业务域(billing/oauth/provider/system/users 等)为目录结构,移除 shared.rs/builders.rs 等反模式 - 移除 ai_pipeline runtime adapters 旧实现(claude/openai/gemini/kiro/vertex/antigravity 等),改由 provider transport 统一承载 - 移除 control_facade/execution_facade/auth_snapshot_facade 等冗余 facade 层 - 拆分 query/billing 与 query/monitoring 模块、state/runtime/payments 与 security 模块 - 扩展架构测试覆盖 admin_billing/admin_model/admin_users 等新模块 - 删除 docs/architecture/refactor-execution-plan.md 已完成的执行计划文档
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
use super::super::build_admin_users_bad_request_response;
|
||||
use super::support::admin_user_id_from_detail_path;
|
||||
use crate::handlers::admin::request::{AdminAppState, AdminRequestContext};
|
||||
use crate::handlers::admin::shared::attach_admin_audit_response;
|
||||
use crate::GatewayError;
|
||||
use axum::{
|
||||
body::Body,
|
||||
http,
|
||||
response::{IntoResponse, Response},
|
||||
Json,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
pub(in super::super) async fn build_admin_delete_user_response(
|
||||
state: &AdminAppState<'_>,
|
||||
request_context: &AdminRequestContext<'_>,
|
||||
) -> Result<Response<Body>, GatewayError> {
|
||||
let Some(user_id) = admin_user_id_from_detail_path(request_context.path()) else {
|
||||
return Ok(build_admin_users_bad_request_response("缺少 user_id"));
|
||||
};
|
||||
let Some(user) = state.find_user_auth_by_id(&user_id).await? else {
|
||||
return Ok((
|
||||
http::StatusCode::NOT_FOUND,
|
||||
Json(json!({ "detail": "用户不存在" })),
|
||||
)
|
||||
.into_response());
|
||||
};
|
||||
|
||||
if user.role.eq_ignore_ascii_case("admin") && state.count_active_admin_users().await? <= 1 {
|
||||
return Ok((
|
||||
http::StatusCode::BAD_REQUEST,
|
||||
Json(json!({ "detail": "不能删除最后一个管理员账户" })),
|
||||
)
|
||||
.into_response());
|
||||
}
|
||||
if state.count_user_pending_refunds(&user_id).await? > 0 {
|
||||
return Ok((
|
||||
http::StatusCode::BAD_REQUEST,
|
||||
Json(json!({ "detail": "用户存在未完结退款,禁止删除" })),
|
||||
)
|
||||
.into_response());
|
||||
}
|
||||
if state.count_user_pending_payment_orders(&user_id).await? > 0 {
|
||||
return Ok((
|
||||
http::StatusCode::BAD_REQUEST,
|
||||
Json(json!({ "detail": "用户存在未完结充值订单,禁止删除" })),
|
||||
)
|
||||
.into_response());
|
||||
}
|
||||
|
||||
if !state.delete_local_auth_user(&user_id).await? {
|
||||
return Ok((
|
||||
http::StatusCode::NOT_FOUND,
|
||||
Json(json!({ "detail": "用户不存在" })),
|
||||
)
|
||||
.into_response());
|
||||
}
|
||||
|
||||
Ok(attach_admin_audit_response(
|
||||
Json(json!({ "message": "用户删除成功" })).into_response(),
|
||||
"admin_user_deleted",
|
||||
"delete_user",
|
||||
"user",
|
||||
&user_id,
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user