Skip to content

Commit

Permalink
flow:improve test (#846)
Browse files Browse the repository at this point in the history
* flow:improve test

* iam: fix ldap sync
  • Loading branch information
ZzIsGod1019 authored Sep 20, 2024
1 parent 99b871d commit fbc48f9
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 183 deletions.
9 changes: 6 additions & 3 deletions backend/middlewares/flow/src/dto/flow_transition_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub struct FlowTransitionSortStateInfoReq {
}

/// 后置动作配置信息
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Default, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowTransitionPostActionInfo {
/// 后置动作类型,目前有状态修改和字段修改两种。
pub kind: FlowTransitionActionChangeKind,
Expand All @@ -318,6 +318,9 @@ pub struct FlowTransitionPostActionInfo {
pub changed_val: Option<Value>,
/// 修改方式(清空,更改内容,更改为其他字段的值,加减值等)
pub changed_kind: Option<FlowTransitionActionByVarChangeInfoChangedKind>,

/// 是否可修改(前端用于判断当前配置是否可编辑)
pub is_edit: Option<bool>,
}

impl From<FlowTransitionPostActionInfo> for FlowTransitionActionChangeAgg {
Expand Down Expand Up @@ -364,10 +367,11 @@ pub struct FlowTransitionActionChangeAgg {
}

/// 后置动作类型,目前有状态修改和字段修改两种。
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum, EnumIter, sea_orm::DeriveActiveEnum)]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Default, Serialize, poem_openapi::Enum, EnumIter, sea_orm::DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(Some(255))")]
pub enum FlowTransitionActionChangeKind {
/// 字段修改
#[default]
#[sea_orm(string_value = "var")]
Var,
/// 状态变更
Expand Down Expand Up @@ -543,7 +547,6 @@ impl TryFrom<FlowTransitionInitInfo> for FlowTransitionAddReq {
action_by_post_changes: Some(value.action_by_post_changes),
action_by_front_changes: Some(value.action_by_front_changes),
double_check: value.double_check,

sort: value.sort,
})
}
Expand Down
47 changes: 40 additions & 7 deletions backend/middlewares/flow/src/serv/flow_model_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
FlowModelModifyReq, FlowModelSummaryResp,
},
flow_state_dto::{FlowStateAggResp, FlowStateDetailResp, FlowStateFilterReq, FlowStateRelModelExt, FlowStateRelModelModifyReq},
flow_transition_dto::{FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionInitInfo, FlowTransitionModifyReq},
flow_transition_dto::{FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionInitInfo, FlowTransitionModifyReq, FlowTransitionPostActionInfo},
},
flow_config::FlowBasicInfoManager,
flow_constants,
Expand Down Expand Up @@ -327,6 +327,15 @@ impl RbumItemCrudOperation<flow_model::ActiveModel, FlowModelAddReq, FlowModelMo
};
let child_model_transitions = child_model.transitions();
let mut modify_req_clone = modify_req.clone();
if let Some(ref mut add_transitions) = &mut modify_req_clone.add_transitions {
for add_transition in add_transitions.iter_mut() {
if let Some(ref mut action_by_post_changes) = &mut add_transition.action_by_post_changes {
for action_by_post_change in action_by_post_changes.iter_mut() {
action_by_post_change.is_edit = Some(false); // 引用复制时,置为不可编辑
}
}
}
}
if let Some(ref mut modify_transitions) = &mut modify_req_clone.modify_transitions {
for modify_transition in modify_transitions.iter_mut() {
let parent_model_transition = parent_model_transitions.iter().find(|trans| trans.id == modify_transition.id.to_string()).unwrap();
Expand Down Expand Up @@ -954,7 +963,19 @@ impl FlowModelServ {
name: state_name,
ext,
is_init: model_detail.init_state_id == state_id,
transitions: model_detail.transitions().into_iter().filter(|transition| transition.from_flow_state_id == state_id.clone()).collect_vec(),
transitions: model_detail.transitions().into_iter().filter(|transition| transition.from_flow_state_id == state_id.clone()).map(|transition| {
let mut action_by_post_changes = vec![];
for action_by_post_change in transition.action_by_post_changes() {
action_by_post_changes.push(FlowTransitionPostActionInfo {
is_edit: Some(false), // 引用复制时,置为不可编辑
..action_by_post_change.clone()
});
}
FlowTransitionDetailResp {
action_by_post_changes: TardisFuns::json.obj_to_json(&action_by_post_changes).unwrap_or_default(),
..transition.clone()
}
}).collect_vec(),
};
states.push(state_detail);
}
Expand Down Expand Up @@ -1097,10 +1118,19 @@ impl FlowModelServ {
let result = match op {
FlowModelAssociativeOperationKind::Reference => {
if is_create_copy.unwrap_or(false) {
let mut add_transitions = rel_model.transitions().into_iter().map(FlowTransitionAddReq::from).collect_vec();
for add_transition in add_transitions.iter_mut() {
if let Some(ref mut action_by_post_changes) = &mut add_transition.action_by_post_changes {
for action_by_post_change in action_by_post_changes.iter_mut() {
action_by_post_change.is_edit = Some(false); // 引用复制时,置为不可编辑
}
}
}
Self::add_item(
&mut FlowModelAddReq {
rel_model_id: Some(rel_model_id.to_string()),
rel_template_ids: None,
transitions: Some(add_transitions),
..rel_model.clone().into()
},
funs,
Expand Down Expand Up @@ -1290,12 +1320,12 @@ impl FlowModelServ {
Ok(())
}

pub async fn bind_state(flow_model_id: &str, req: &FlowModelBindStateReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
async fn bind_state(flow_model_id: &str, req: &FlowModelBindStateReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let global_ctx = TardisContext {
own_paths: "".to_string(),
..ctx.clone()
};
if FlowStateServ::get_item(
if let Ok(state) = FlowStateServ::get_item(
&req.state_id,
&FlowStateFilterReq {
basic: RbumBasicFilterReq {
Expand All @@ -1307,9 +1337,12 @@ impl FlowModelServ {
funs,
&global_ctx,
)
.await
.is_err()
{
.await {
let model_detail = Self::get_item(flow_model_id, &FlowModelFilterReq::default(), funs, ctx).await?;
if !state.tags.is_empty() && !state.tags.split(',').collect_vec().contains(&model_detail.tag.as_str()) {
return Err(funs.err().internal_error("flow_model_serv", "bind_state", "The flow state is not found", "404-flow-state-not-found"));
}
} else {
return Err(funs.err().internal_error("flow_model_serv", "bind_state", "The flow state is not found", "404-flow-state-not-found"));
}
FlowRelServ::add_simple_rel(
Expand Down
108 changes: 10 additions & 98 deletions backend/middlewares/flow/tests/test_flow_scenes_fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,7 @@ pub async fn test(flow_client: &mut TestHttpClient) -> TardisResult<()> {
FlowTransitionModifyReq {
id: trans_start.id.clone().into(),
name: Some(format!("{}-modify", &trans_start.name).into()),
from_flow_state_id: None,
to_flow_state_id: None,
transfer_by_auto: Some(true),
transfer_by_timer: None,
guard_by_creator: None,
guard_by_his_operators: None,
guard_by_assigned: None,
guard_by_spec_account_ids: None,
guard_by_spec_role_ids: None,
guard_by_spec_org_ids: None,
guard_by_other_conds: None,
vars_collect: Some(vec![
FlowVarInfo {
name: "assigned_to".to_string(),
Expand All @@ -223,8 +213,6 @@ pub async fn test(flow_client: &mut TestHttpClient) -> TardisResult<()> {
..Default::default()
},
]),
action_by_pre_callback: None,
action_by_post_callback: None,
action_by_post_changes: Some(vec![FlowTransitionPostActionInfo {
kind: FlowTransitionActionChangeKind::State,
describe: "".to_string(),
Expand All @@ -245,35 +233,19 @@ pub async fn test(flow_client: &mut TestHttpClient) -> TardisResult<()> {
var_name: "".to_string(),
changed_val: None,
changed_kind: None,
..Default::default()
}]),
action_by_post_var_changes: None,
action_by_post_state_changes: None,
double_check: Some(FlowTransitionDoubleCheckInfo {
is_open: true,
content: Some("再次确认该操作生效".to_string()),
}),
is_notify: None,
action_by_front_changes: None,
sort: None,
..Default::default()
},
FlowTransitionModifyReq {
id: trans_complate.id.clone().into(),
name: Some(format!("{}-modify", &trans_complate.name).into()),
from_flow_state_id: None,
to_flow_state_id: None,
transfer_by_auto: Some(true),
transfer_by_timer: None,
guard_by_creator: None,
guard_by_his_operators: None,
guard_by_assigned: None,
guard_by_spec_account_ids: None,
guard_by_spec_role_ids: Some(vec!["admin".to_string()]),
guard_by_spec_org_ids: None,
guard_by_other_conds: None,
vars_collect: None,
action_by_pre_callback: None,
action_by_post_callback: None,
action_by_front_changes: None,
action_by_post_changes: Some(vec![
FlowTransitionPostActionInfo {
kind: FlowTransitionActionChangeKind::Var,
Expand All @@ -287,6 +259,7 @@ pub async fn test(flow_client: &mut TestHttpClient) -> TardisResult<()> {
var_name: "id".to_string(),
changed_val: None,
changed_kind: Some(FlowTransitionActionByVarChangeInfoChangedKind::AutoGetOperateTime),
..Default::default()
},
FlowTransitionPostActionInfo {
kind: FlowTransitionActionChangeKind::Var,
Expand All @@ -300,38 +273,15 @@ pub async fn test(flow_client: &mut TestHttpClient) -> TardisResult<()> {
var_name: "id1".to_string(),
changed_val: Some(json!("status")),
changed_kind: Some(FlowTransitionActionByVarChangeInfoChangedKind::SelectField),
..Default::default()
},
]),
action_by_post_var_changes: None,
action_by_post_state_changes: None,
double_check: None,
is_notify: None,
sort: None,
..Default::default()
},
FlowTransitionModifyReq {
id: trans_close.id.clone().into(),
name: None,
from_flow_state_id: None,
to_flow_state_id: None,
transfer_by_auto: None,
transfer_by_timer: None,
guard_by_creator: None,
guard_by_his_operators: None,
guard_by_assigned: Some(true),
guard_by_spec_account_ids: None,
guard_by_spec_role_ids: None,
guard_by_spec_org_ids: None,
guard_by_other_conds: None,
vars_collect: None,
action_by_pre_callback: None,
action_by_post_callback: None,
action_by_post_changes: None,
action_by_post_var_changes: None,
action_by_post_state_changes: None,
action_by_front_changes: None,
double_check: None,
is_notify: None,
sort: None,
..Default::default()
},
]),
..Default::default()
Expand Down Expand Up @@ -363,22 +313,6 @@ pub async fn test(flow_client: &mut TestHttpClient) -> TardisResult<()> {
&FlowModelModifyReq {
modify_transitions: Some(vec![FlowTransitionModifyReq {
id: proj_trans.id.clone().into(),
name: None,
from_flow_state_id: None,
to_flow_state_id: None,
transfer_by_auto: None,
transfer_by_timer: None,
guard_by_creator: None,
guard_by_his_operators: None,
guard_by_assigned: None,
guard_by_spec_account_ids: None,
guard_by_spec_role_ids: None,
guard_by_spec_org_ids: None,
guard_by_other_conds: None,
vars_collect: None,
action_by_pre_callback: None,
action_by_post_callback: None,
action_by_front_changes: None,
action_by_post_changes: Some(vec![FlowTransitionPostActionInfo {
kind: FlowTransitionActionChangeKind::State,
describe: "".to_string(),
Expand All @@ -391,12 +325,9 @@ pub async fn test(flow_client: &mut TestHttpClient) -> TardisResult<()> {
var_name: "".to_string(),
changed_val: None,
changed_kind: None,
..Default::default()
}]),
action_by_post_var_changes: None,
action_by_post_state_changes: None,
double_check: None,
is_notify: None,
sort: None,
..Default::default()
}]),
..Default::default()
},
Expand All @@ -410,22 +341,6 @@ pub async fn test(flow_client: &mut TestHttpClient) -> TardisResult<()> {
&FlowModelModifyReq {
modify_transitions: Some(vec![FlowTransitionModifyReq {
id: ticket_trans.id.clone().into(),
name: None,
from_flow_state_id: None,
to_flow_state_id: None,
transfer_by_auto: None,
transfer_by_timer: None,
guard_by_creator: None,
guard_by_his_operators: None,
guard_by_assigned: None,
guard_by_spec_account_ids: None,
guard_by_spec_role_ids: None,
guard_by_spec_org_ids: None,
guard_by_other_conds: None,
vars_collect: None,
action_by_pre_callback: None,
action_by_post_callback: None,
action_by_front_changes: None,
action_by_post_changes: Some(vec![FlowTransitionPostActionInfo {
kind: FlowTransitionActionChangeKind::State,
describe: "".to_string(),
Expand All @@ -438,12 +353,9 @@ pub async fn test(flow_client: &mut TestHttpClient) -> TardisResult<()> {
var_name: "".to_string(),
changed_val: None,
changed_kind: None,
..Default::default()
}]),
action_by_post_var_changes: None,
action_by_post_state_changes: None,
double_check: None,
is_notify: None,
sort: None,
..Default::default()
}]),
..Default::default()
},
Expand Down
12 changes: 12 additions & 0 deletions backend/middlewares/flow/tests/test_flow_scenes_fsm1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,17 @@ pub async fn test(flow_client: &mut TestHttpClient, search_client: &mut TestHttp
assert!(req_models.iter().any(|mdoel| mdoel.id == req_model_template_id));
assert!(req_models.iter().all(|mdoel| mdoel.id != req_model_uninit_template_id));

let req_models: Vec<FlowModelSummaryResp> = flow_client.get("/cc/model/find_by_rel_template_id?tag=REQ&template=true").await;
assert_eq!(req_models.len(), 2);
assert!(req_models.iter().any(|mdoel| mdoel.id == req_default_model_template_id));
assert!(req_models.iter().all(|mdoel| mdoel.id != req_model_template_id));
ctx.owner = "u001".to_string();
ctx.own_paths = "t2".to_string();
flow_client.set_auth(&ctx)?;
search_client.set_auth(&ctx)?;
let req_models: Vec<FlowModelSummaryResp> = flow_client.get("/cc/model/find_by_rel_template_id?tag=REQ&template=true").await;
assert_eq!(req_models.len(), 2);
assert!(req_models.iter().any(|mdoel| mdoel.id == req_default_model_template_id));
assert!(req_models.iter().all(|mdoel| mdoel.id != req_model_template_id));
Ok(())
}
2 changes: 1 addition & 1 deletion backend/supports/iam/src/basic/dto/iam_account_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub struct IamAccountBoneResp {
pub icon: String,
}

#[derive(poem_openapi::Object, sea_orm::FromQueryResult, Serialize, Deserialize, Debug)]
#[derive(poem_openapi::Object, sea_orm::FromQueryResult, Serialize, Deserialize, Debug, Clone)]
pub struct IamAccountSummaryResp {
pub id: String,
pub name: String,
Expand Down
Loading

0 comments on commit fbc48f9

Please sign in to comment.