Skip to content

Commit

Permalink
fix: remove cc unsafe_fill_ctx (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Mar 26, 2024
1 parent e1bb17f commit 361e64b
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 87 deletions.
45 changes: 17 additions & 28 deletions middleware/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;

use bios_basic::helper::bios_ctx_helper::unsafe_fill_ctx;
use tardis::web::context_extractor::TardisContextExtractor;
use tardis::web::poem::Request;
use tardis::web::poem_openapi;
Expand All @@ -23,9 +22,8 @@ pub struct FlowCcInstApi;
impl FlowCcInstApi {
/// Start Instance / 启动实例
#[oai(path = "/", method = "post")]
async fn start(&self, add_req: Json<FlowInstStartReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<String> {
async fn start(&self, add_req: Json<FlowInstStartReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<String> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
let result = FlowInstServ::start(&add_req.0, None, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -34,9 +32,8 @@ impl FlowCcInstApi {

/// Abort Instance / 中止实例
#[oai(path = "/:flow_inst_id", method = "put")]
async fn abort(&self, flow_inst_id: Path<String>, abort_req: Json<FlowInstAbortReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
async fn abort(&self, flow_inst_id: Path<String>, abort_req: Json<FlowInstAbortReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowInstServ::abort(&flow_inst_id.0, &abort_req.0, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -45,9 +42,8 @@ impl FlowCcInstApi {

/// Get Instance By Instance Id / 获取实例信息
#[oai(path = "/:flow_inst_id", method = "get")]
async fn get(&self, flow_inst_id: Path<String>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<FlowInstDetailResp> {
async fn get(&self, flow_inst_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<FlowInstDetailResp> {
let funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
let result = FlowInstServ::get(&flow_inst_id.0, &funs, &ctx.0).await?;
TardisResp::ok(result)
}
Expand All @@ -62,11 +58,10 @@ impl FlowCcInstApi {
with_sub: Query<Option<bool>>,
page_number: Query<u32>,
page_size: Query<u32>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<TardisPage<FlowInstSummaryResp>> {
let funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
let result = FlowInstServ::paginate(flow_model_id.0, tag.0, finish.0, with_sub.0, page_number.0, page_size.0, &funs, &ctx.0).await?;
TardisResp::ok(result)
}
Expand All @@ -77,11 +72,10 @@ impl FlowCcInstApi {
&self,
flow_inst_id: Path<String>,
next_req: Json<FlowInstFindNextTransitionsReq>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Vec<FlowInstFindNextTransitionResp>> {
let funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
let result = FlowInstServ::find_next_transitions(&flow_inst_id.0, &next_req.0, &funs, &ctx.0).await?;
TardisResp::ok(result)
}
Expand All @@ -91,11 +85,10 @@ impl FlowCcInstApi {
async fn find_state_and_next_transitions(
&self,
find_req: Json<Vec<FlowInstFindStateAndTransitionsReq>>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Vec<FlowInstFindStateAndTransitionsResp>> {
let funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
let result = FlowInstServ::find_state_and_next_transitions(&find_req.0, &funs, &ctx.0).await?;
TardisResp::ok(result)
}
Expand All @@ -106,11 +99,10 @@ impl FlowCcInstApi {
&self,
flow_inst_id: Path<String>,
transfer_req: Json<FlowInstTransferReq>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<FlowInstTransferResp> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
let mut transfer = transfer_req.0;
FlowInstServ::check_transfer_vars(&flow_inst_id.0, &mut transfer, &funs, &ctx.0).await?;
funs.begin().await?;
Expand All @@ -125,11 +117,10 @@ impl FlowCcInstApi {
&self,
flow_inst_ids: Path<String>,
transfer_req: Json<FlowInstTransferReq>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Vec<FlowInstTransferResp>> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
let mut result = vec![];
let flow_inst_ids: Vec<_> = flow_inst_ids.split(',').collect();
let raw_transfer_req = transfer_req.0;
Expand All @@ -153,11 +144,10 @@ impl FlowCcInstApi {
&self,
flow_inst_id: Path<String>,
modify_req: Json<FlowInstModifyAssignedReq>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowInstServ::modify_assigned(&flow_inst_id.0, &modify_req.0.current_assigned, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -170,11 +160,10 @@ impl FlowCcInstApi {
&self,
flow_inst_id: Path<String>,
modify_req: Json<FlowInstModifyCurrentVarsReq>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0.vars, &funs, &ctx.0).await?;
funs.commit().await?;
Expand Down
52 changes: 19 additions & 33 deletions middleware/flow/src/api/cc/flow_cc_model_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;

use bios_basic::helper::bios_ctx_helper::unsafe_fill_ctx;
use bios_basic::rbum::dto::rbum_filer_dto::RbumBasicFilterReq;
use bios_basic::rbum::serv::rbum_item_serv::RbumItemCrudOperation;
use tardis::web::context_extractor::TardisContextExtractor;
Expand All @@ -27,9 +26,8 @@ pub struct FlowCcModelApi;
impl FlowCcModelApi {
/// Add Model / 添加模型
#[oai(path = "/", method = "post")]
async fn add(&self, mut add_req: Json<FlowModelAddReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<String> {
async fn add(&self, mut add_req: Json<FlowModelAddReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<String> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
let result = FlowModelServ::add_item(&mut add_req.0, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -38,9 +36,8 @@ impl FlowCcModelApi {

/// Modify Model By Model Id / 修改模型
#[oai(path = "/:flow_model_id", method = "patch")]
async fn modify(&self, flow_model_id: Path<String>, mut modify_req: Json<FlowModelModifyReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
async fn modify(&self, flow_model_id: Path<String>, mut modify_req: Json<FlowModelModifyReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowModelServ::modify_model(&flow_model_id.0, &mut modify_req.0, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -49,9 +46,8 @@ impl FlowCcModelApi {

/// Get Model By Model Id / 获取模型
#[oai(path = "/:flow_model_id", method = "get")]
async fn get(&self, flow_model_id: Path<String>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<FlowModelAggResp> {
async fn get(&self, flow_model_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<FlowModelAggResp> {
let funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
let result = FlowModelServ::get_item_detail_aggs(&flow_model_id.0, &funs, &ctx.0).await?;
TardisResp::ok(result)
}
Expand All @@ -70,11 +66,10 @@ impl FlowCcModelApi {
page_size: Query<u32>,
desc_by_create: Query<Option<bool>>,
desc_by_update: Query<Option<bool>>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<TardisPage<FlowModelSummaryResp>> {
let funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
let result = FlowModelServ::paginate_items(
&FlowModelFilterReq {
basic: RbumBasicFilterReq {
Expand Down Expand Up @@ -104,11 +99,10 @@ impl FlowCcModelApi {
&self,
tag_ids: Query<String>,
temp_id: Query<Option<String>>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<HashMap<String, FlowTemplateModelResp>> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
let tag_ids: Vec<_> = tag_ids.split(',').collect();
let result = FlowModelServ::get_models(tag_ids, temp_id.0, &funs, &ctx.0).await?;
Expand All @@ -122,9 +116,8 @@ impl FlowCcModelApi {
///
/// 仅在模型没被使用时有效
#[oai(path = "/:flow_model_id", method = "delete")]
async fn delete(&self, flow_model_id: Path<String>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
async fn delete(&self, flow_model_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowModelServ::delete_item(&flow_model_id.0, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -133,9 +126,8 @@ impl FlowCcModelApi {

/// Bind State By Model Id / 绑定状态
#[oai(path = "/:flow_model_id/bind_state", method = "post")]
async fn bind_state(&self, flow_model_id: Path<String>, req: Json<FlowModelBindStateReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
async fn bind_state(&self, flow_model_id: Path<String>, req: Json<FlowModelBindStateReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowModelServ::bind_state(&FlowRelKind::FlowModelState, &flow_model_id.0, &req.0, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -144,9 +136,8 @@ impl FlowCcModelApi {

/// Unbind State By Model Id / 解绑状态
#[oai(path = "/:flow_model_id/unbind_state", method = "post")]
async fn unbind_state(&self, flow_model_id: Path<String>, req: Json<FlowModelUnbindStateReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
async fn unbind_state(&self, flow_model_id: Path<String>, req: Json<FlowModelUnbindStateReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowModelServ::unbind_state(&FlowRelKind::FlowModelState, &flow_model_id.0, &req, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -155,9 +146,8 @@ impl FlowCcModelApi {

/// Resort states / 状态重新排序
#[oai(path = "/:flow_model_id/resort_state", method = "post")]
async fn resort_state(&self, flow_model_id: Path<String>, req: Json<FlowModelSortStatesReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
async fn resort_state(&self, flow_model_id: Path<String>, req: Json<FlowModelSortStatesReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowModelServ::resort_state(&FlowRelKind::FlowModelState, &flow_model_id.0, &req.0, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -170,11 +160,10 @@ impl FlowCcModelApi {
&self,
flow_model_id: Path<String>,
req: Json<FlowTransitionSortStatesReq>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowModelServ::resort_transition(&flow_model_id.0, &req.0, &funs, &ctx.0).await?;
funs.commit().await?;
Expand All @@ -186,11 +175,10 @@ impl FlowCcModelApi {
async fn add_custom_model(
&self,
req: Json<FlowModelAddCustomModelReq>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Vec<FlowModelAddCustomModelResp>> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
let proj_template_id = req.0.proj_template_id.unwrap_or_default();
let mut result = vec![];
Expand All @@ -208,11 +196,10 @@ impl FlowCcModelApi {
&self,
tag: Query<String>,
rel_template_id: Query<Option<String>>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Vec<FlowModelFindRelStateResp>> {
let funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
let result = FlowModelServ::find_rel_states(tag.0.split(',').collect(), rel_template_id.0, &funs, &ctx.0).await?;

TardisResp::ok(result)
Expand All @@ -225,11 +212,10 @@ impl FlowCcModelApi {
flow_model_id: Path<String>,
state_id: Path<String>,
req: Json<FlowStateRelModelExt>,
mut ctx: TardisContextExtractor,
request: &Request,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
unsafe_fill_ctx(request, &funs, &mut ctx.0).await?;
funs.begin().await?;
FlowModelServ::modify_rel_state(&flow_model_id.0, &state_id.0, &req.0, &funs, &ctx.0).await?;
funs.commit().await?;
Expand Down
Loading

0 comments on commit 361e64b

Please sign in to comment.