feat(config): add missing dictionary item CRUD, setting delete, and numbering delete routes

- Dictionary items: POST/PUT/DELETE endpoints under /config/dictionaries/{dict_id}/items
- Settings: DELETE /config/settings/{key}
- Numbering rules: DELETE /config/numbering-rules/{id}
- Fix workflow Entities: add deleted_at and version_field to process_definition,
  add standard fields to token and process_variable entities
- Update seed data for expanded permissions
This commit is contained in:
iven
2026-04-11 12:52:29 +08:00
parent 82986e988d
commit 184034ff6b
11 changed files with 223 additions and 14 deletions

View File

@@ -10,7 +10,8 @@ use uuid::Uuid;
use crate::config_state::ConfigState;
use crate::dto::{
CreateDictionaryReq, DictionaryItemResp, DictionaryResp, UpdateDictionaryReq,
CreateDictionaryItemReq, CreateDictionaryReq, DictionaryItemResp, DictionaryResp,
UpdateDictionaryItemReq, UpdateDictionaryReq,
};
use crate::service::dictionary_service::DictionaryService;
@@ -156,6 +157,98 @@ where
Ok(Json(ApiResponse::ok(items)))
}
/// POST /api/v1/dictionaries/:dict_id/items
///
/// 向指定字典添加新的字典项。
/// 字典项的 value 在同一字典内必须唯一。
/// 需要 `dictionary.create` 权限。
pub async fn create_item<S>(
State(state): State<ConfigState>,
Extension(ctx): Extension<TenantContext>,
Path(dict_id): Path<Uuid>,
Json(req): Json<CreateDictionaryItemReq>,
) -> Result<Json<ApiResponse<DictionaryItemResp>>, AppError>
where
ConfigState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "dictionary.create")?;
req.validate()
.map_err(|e| AppError::Validation(e.to_string()))?;
let item = DictionaryService::add_item(
dict_id,
ctx.tenant_id,
ctx.user_id,
&req,
&state.db,
)
.await?;
Ok(Json(ApiResponse::ok(item)))
}
/// PUT /api/v1/dictionaries/:dict_id/items/:item_id
///
/// 更新字典项的可编辑字段label、value、sort_order、color
/// 需要 `dictionary.update` 权限。
pub async fn update_item<S>(
State(state): State<ConfigState>,
Extension(ctx): Extension<TenantContext>,
Path((dict_id, item_id)): Path<(Uuid, Uuid)>,
Json(req): Json<UpdateDictionaryItemReq>,
) -> Result<Json<ApiResponse<DictionaryItemResp>>, AppError>
where
ConfigState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "dictionary.update")?;
// 验证 item_id 属于 dict_id
let item = DictionaryService::update_item(
item_id,
ctx.tenant_id,
ctx.user_id,
&req,
&state.db,
)
.await?;
// 确保 item 属于指定的 dictionary
if item.dictionary_id != dict_id {
return Err(AppError::Validation(
"字典项不属于指定的字典".to_string(),
));
}
Ok(Json(ApiResponse::ok(item)))
}
/// DELETE /api/v1/dictionaries/:dict_id/items/:item_id
///
/// 软删除字典项,设置 deleted_at 时间戳。
/// 需要 `dictionary.delete` 权限。
pub async fn delete_item<S>(
State(state): State<ConfigState>,
Extension(ctx): Extension<TenantContext>,
Path((_dict_id, item_id)): Path<(Uuid, Uuid)>,
) -> Result<Json<ApiResponse<()>>, AppError>
where
ConfigState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "dictionary.delete")?;
DictionaryService::delete_item(item_id, ctx.tenant_id, ctx.user_id, &state.db).await?;
Ok(Json(ApiResponse {
success: true,
data: None,
message: Some("字典项已删除".to_string()),
}))
}
/// 按编码查询字典项的查询参数。
#[derive(Debug, serde::Deserialize)]
pub struct ItemsByCodeQuery {

View File

@@ -117,3 +117,28 @@ where
Ok(Json(ApiResponse::ok(result)))
}
/// DELETE /api/v1/numbering-rules/:id
///
/// 软删除编号规则,设置 deleted_at 时间戳。
/// 需要 `numbering.delete` 权限。
pub async fn delete_numbering_rule<S>(
State(state): State<ConfigState>,
Extension(ctx): Extension<TenantContext>,
Path(id): Path<Uuid>,
) -> Result<Json<ApiResponse<()>>, AppError>
where
ConfigState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "numbering.delete")?;
NumberingService::delete(id, ctx.tenant_id, ctx.user_id, &state.db, &state.event_bus)
.await?;
Ok(Json(ApiResponse {
success: true,
data: None,
message: Some("编号规则已删除".to_string()),
}))
}

View File

@@ -76,3 +76,38 @@ pub struct SettingQuery {
pub scope: Option<String>,
pub scope_id: Option<Uuid>,
}
/// DELETE /api/v1/settings/:key
///
/// 软删除设置值,设置 deleted_at 时间戳。
/// 需要 `setting.delete` 权限。
pub async fn delete_setting<S>(
State(state): State<ConfigState>,
Extension(ctx): Extension<TenantContext>,
Path(key): Path<String>,
Query(query): Query<SettingQuery>,
) -> Result<Json<ApiResponse<()>>, AppError>
where
ConfigState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "setting.delete")?;
let scope = query.scope.unwrap_or_else(|| "tenant".to_string());
SettingService::delete(
&key,
&scope,
&query.scope_id,
ctx.tenant_id,
ctx.user_id,
&state.db,
)
.await?;
Ok(Json(ApiResponse {
success: true,
data: None,
message: Some("设置已删除".to_string()),
}))
}

View File

@@ -44,6 +44,15 @@ impl ConfigModule {
"/config/dictionaries/items",
get(dictionary_handler::list_items_by_code),
)
.route(
"/config/dictionaries/{dict_id}/items",
post(dictionary_handler::create_item),
)
.route(
"/config/dictionaries/{dict_id}/items/{item_id}",
put(dictionary_handler::update_item)
.delete(dictionary_handler::delete_item),
)
// Menu routes
.route(
"/config/menus",
@@ -52,7 +61,9 @@ impl ConfigModule {
// Setting routes
.route(
"/config/settings/{key}",
get(setting_handler::get_setting).put(setting_handler::update_setting),
get(setting_handler::get_setting)
.put(setting_handler::update_setting)
.delete(setting_handler::delete_setting),
)
// Numbering rule routes
.route(
@@ -62,7 +73,8 @@ impl ConfigModule {
)
.route(
"/config/numbering-rules/{id}",
put(numbering_handler::update_numbering_rule),
put(numbering_handler::update_numbering_rule)
.delete(numbering_handler::delete_numbering_rule),
)
.route(
"/config/numbering-rules/{id}/generate",