diff --git a/middleware/flow/src/dto/flow_model_dto.rs b/middleware/flow/src/dto/flow_model_dto.rs index 90e0c7123..e86610241 100644 --- a/middleware/flow/src/dto/flow_model_dto.rs +++ b/middleware/flow/src/dto/flow_model_dto.rs @@ -122,6 +122,7 @@ pub struct FlowModelFilterReq { pub rel_template_id: Option, pub template: Option, pub own_paths: Option>, + pub specified_state_ids: Option>, } impl RbumItemFilterFetcher for FlowModelFilterReq { diff --git a/middleware/flow/src/flow_initializer.rs b/middleware/flow/src/flow_initializer.rs index 60b2d59cb..e7c1cd463 100644 --- a/middleware/flow/src/flow_initializer.rs +++ b/middleware/flow/src/flow_initializer.rs @@ -8,10 +8,7 @@ use bios_sdk_invoke::invoke_initializer; use tardis::{ basic::{dto::TardisContext, field::TrimString, result::TardisResult}, - db::{ - reldb_client::TardisActiveModel, - sea_orm::sea_query::Table, - }, + db::{reldb_client::TardisActiveModel, sea_orm::sea_query::Table}, log::info, web::web_server::TardisWebServer, TardisFuns, TardisFunsInst, @@ -27,9 +24,7 @@ use crate::{ dto::{ flow_model_dto::FlowModelFilterReq, flow_state_dto::FlowSysStateKind, - flow_transition_dto::{ - FlowTransitionDoubleCheckInfo, FlowTransitionInitInfo, - }, + flow_transition_dto::{FlowTransitionDoubleCheckInfo, FlowTransitionInitInfo}, }, flow_config::{BasicInfo, FlowBasicInfoManager, FlowConfig}, flow_constants, diff --git a/middleware/flow/src/serv/flow_config_serv.rs b/middleware/flow/src/serv/flow_config_serv.rs index 271bb4c70..5f55eb5b1 100644 --- a/middleware/flow/src/serv/flow_config_serv.rs +++ b/middleware/flow/src/serv/flow_config_serv.rs @@ -1,3 +1,4 @@ +use bios_basic::rbum::rbum_enumeration::RbumScopeLevelKind; use bios_sdk_invoke::clients::spi_kv_client::{KvItemSummaryResp, SpiKvClient}; use tardis::{ basic::{dto::TardisContext, result::TardisResult}, @@ -12,7 +13,7 @@ pub struct FlowConfigServ; impl FlowConfigServ { pub async fn modify_config(modify_req: &Vec, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { for req in modify_req { - SpiKvClient::add_or_modify_item(&format!("{}:config:{}", flow_constants::DOMAIN_CODE, req.code.clone()), &req.value, None, funs, ctx).await?; + SpiKvClient::add_or_modify_item(&format!("{}:config:{}", flow_constants::DOMAIN_CODE, req.code.clone()), &req.value, None, Some(RbumScopeLevelKind::Root.to_int()), funs, ctx).await?; } Ok(()) } diff --git a/middleware/flow/src/serv/flow_inst_serv.rs b/middleware/flow/src/serv/flow_inst_serv.rs index b40e3a81f..e8d3d95ea 100644 --- a/middleware/flow/src/serv/flow_inst_serv.rs +++ b/middleware/flow/src/serv/flow_inst_serv.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use async_recursion::async_recursion; use bios_basic::{ @@ -534,11 +534,12 @@ impl FlowInstServ { let flow_models = FlowModelServ::find_detail_items( &FlowModelFilterReq { basic: RbumBasicFilterReq { - ids: Some(flow_insts.iter().map(|inst| inst.rel_flow_model_id.to_string()).collect_vec()), + ids: Some(flow_insts.iter().map(|inst| inst.rel_flow_model_id.to_string()).collect::>().into_iter().collect()), with_sub_own_paths: true, own_paths: Some("".to_string()), ..Default::default() }, + specified_state_ids: Some(flow_insts.iter().map(|inst| inst.current_state_id.clone()).collect::>().into_iter().collect()), ..Default::default() }, None, @@ -680,15 +681,7 @@ impl FlowInstServ { } let model_transition = flow_model.transitions(); let next_transition_detail = model_transition.iter().find(|trans| trans.id == transfer_req.flow_transition_id).unwrap().to_owned(); - if FlowModelServ::check_post_action_ring( - next_transition_detail.clone(), - (false, vec![]), - funs, - ctx, - ) - .await? - .0 - { + if FlowModelServ::check_post_action_ring(next_transition_detail.clone(), (false, vec![]), funs, ctx).await?.0 { return Err(funs.err().not_found("flow_inst", "transfer", "this post action exist endless loop", "500-flow-transition-endless-loop")); } @@ -821,7 +814,16 @@ impl FlowInstServ { let post_changes = model_transition.into_iter().find(|model_transition| model_transition.id == next_flow_transition.next_flow_transition_id).unwrap_or_default().action_by_post_changes(); if !post_changes.is_empty() { - Self::do_post_change(&flow_inst_detail, &flow_model, post_changes, updated_instance_list, next_transition_detail.is_notify, ctx, funs).await?; + Self::do_post_change( + &flow_inst_detail, + &flow_model, + post_changes, + updated_instance_list, + next_transition_detail.is_notify, + ctx, + funs, + ) + .await?; } let next_flow_transitions = Self::do_find_next_transitions(&flow_inst_detail, &flow_model, None, &None, skip_filter, funs, ctx).await?.next_flow_transitions; diff --git a/middleware/flow/src/serv/flow_model_serv.rs b/middleware/flow/src/serv/flow_model_serv.rs index 61fdda4df..d1051733f 100644 --- a/middleware/flow/src/serv/flow_model_serv.rs +++ b/middleware/flow/src/serv/flow_model_serv.rs @@ -200,7 +200,7 @@ impl RbumItemCrudOperation TardisResult { let mut flow_model = Self::do_get_item(flow_model_id, filter, funs, ctx).await?; - let flow_transitions = Self::find_transitions(flow_model_id, funs, ctx).await?; + let flow_transitions = Self::find_transitions(flow_model_id, filter.specified_state_ids.as_deref(), funs, ctx).await?; flow_model.transitions = Some(TardisFuns::json.obj_to_json(&flow_transitions)?); Ok(flow_model) } @@ -216,7 +216,7 @@ impl RbumItemCrudOperation TardisResult> { let mut flow_models = Self::do_paginate_detail_items(filter, page_number, page_size, desc_sort_by_create, desc_sort_by_update, funs, ctx).await?; for flow_model in &mut flow_models.records { - let flow_transitions = Self::find_transitions(&flow_model.id, funs, ctx).await?; + let flow_transitions = Self::find_transitions(&flow_model.id, filter.specified_state_ids.as_deref(), funs, ctx).await?; flow_model.transitions = Some(TardisFuns::json.obj_to_json(&flow_transitions)?); } Ok(flow_models) @@ -231,7 +231,7 @@ impl RbumItemCrudOperation TardisResult> { let mut flow_models = Self::do_find_detail_items(filter, desc_sort_by_create, desc_sort_by_update, funs, ctx).await?; for flow_model in &mut flow_models { - let flow_transitions = Self::find_transitions(&flow_model.id, funs, ctx).await?; + let flow_transitions = Self::find_transitions(&flow_model.id, filter.specified_state_ids.as_deref(), funs, ctx).await?; flow_model.transitions = Some(TardisFuns::json.obj_to_json(&flow_transitions)?); } Ok(flow_models) @@ -555,7 +555,7 @@ impl FlowModelServ { Ok(()) } - async fn find_transitions(flow_model_id: &str, funs: &TardisFunsInst, _ctx: &TardisContext) -> TardisResult> { + async fn find_transitions(flow_model_id: &str, specified_state_ids: Option<&[String]>, funs: &TardisFunsInst, _ctx: &TardisContext) -> TardisResult> { let from_state_rbum_table = Alias::new("from_state_rbum"); let from_state_table = Alias::new("from_state"); let to_state_rbum_table = Alias::new("to_state_rbum"); @@ -624,7 +624,11 @@ impl FlowModelServ { to_state_table.clone(), Cond::all().add(Expr::col((to_state_table.clone(), ID_FIELD.clone())).equals((flow_transition::Entity, flow_transition::Column::FromFlowStateId))), ) - .and_where(Expr::col((flow_transition::Entity, flow_transition::Column::RelFlowModelId)).eq(flow_model_id)) + .and_where(Expr::col((flow_transition::Entity, flow_transition::Column::RelFlowModelId)).eq(flow_model_id)); + if let Some(specified_state_ids) = specified_state_ids { + query.and_where(Expr::col((flow_transition::Entity, flow_transition::Column::FromFlowStateId)).is_in(specified_state_ids)); + } + query .order_by((flow_transition::Entity, flow_transition::Column::Sort), Order::Asc) .order_by((flow_transition::Entity, flow_transition::Column::CreateTime), Order::Asc) .order_by((flow_transition::Entity, flow_transition::Column::Id), Order::Asc); @@ -1174,7 +1178,7 @@ impl FlowModelServ { funs: &TardisFunsInst, ctx: &TardisContext, ) -> TardisResult> { - Ok(Self::find_transitions(flow_model_id, funs, ctx) + Ok(Self::find_transitions(flow_model_id, None, funs, ctx) .await? .into_iter() .filter(|tran_detail| { diff --git a/sdk/invoke/src/clients/spi_kv_client.rs b/sdk/invoke/src/clients/spi_kv_client.rs index 7eaa0b512..4df8c8331 100644 --- a/sdk/invoke/src/clients/spi_kv_client.rs +++ b/sdk/invoke/src/clients/spi_kv_client.rs @@ -34,13 +34,14 @@ pub struct KvItemDetailResp { } impl SpiKvClient { - pub async fn add_or_modify_item(key: &str, value: &T, info: Option, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { + pub async fn add_or_modify_item(key: &str, value: &T, info: Option, scope_level: Option, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { let kv_url: String = BaseSpiClient::module_url(InvokeModuleKind::Kv, funs).await?; let headers = BaseSpiClient::headers(None, funs, ctx).await?; let json = json!({ "key":key.to_string(), "value":value, - "info":info + "info":info, + "scope_level":scope_level, }); funs.web_client().put_obj_to_str(&format!("{kv_url}/ci/item"), &json, headers.clone()).await?; Ok(()) diff --git a/spi/spi-kv/src/serv/pg/kv_pg_item_serv.rs b/spi/spi-kv/src/serv/pg/kv_pg_item_serv.rs index fa8d77a34..3ad5125f3 100644 --- a/spi/spi-kv/src/serv/pg/kv_pg_item_serv.rs +++ b/spi/spi-kv/src/serv/pg/kv_pg_item_serv.rs @@ -215,15 +215,18 @@ WHERE update_time: item.try_get("", "update_time")?, }) }) - .filter(|item| item.is_ok() && rbum_scope_helper::check_scope( - &item.as_ref().expect("invalid result").own_paths, - Some(item.as_ref().expect("invalid result").scope_level), - &RbumBasicFilterReq { - ignore_scope: false, - ..Default::default() - }, - ctx, - )) + .filter(|item| { + item.is_ok() + && rbum_scope_helper::check_scope( + &item.as_ref().expect("invalid result").own_paths, + Some(item.as_ref().expect("invalid result").scope_level), + &RbumBasicFilterReq { + ignore_scope: false, + ..Default::default() + }, + ctx, + ) + }) .collect::>>()?; Ok(TardisPage { page_size: match_req.page_size as u64, diff --git a/support/iam/src/console_interface/api/iam_ci_cert_api.rs b/support/iam/src/console_interface/api/iam_ci_cert_api.rs index 73e2092fd..a7e831fc1 100644 --- a/support/iam/src/console_interface/api/iam_ci_cert_api.rs +++ b/support/iam/src/console_interface/api/iam_ci_cert_api.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use crate::basic::dto::iam_account_dto::IamAccountExtSysResp; -use crate::basic::dto::iam_cert_dto::{IamCertAkSkAddReq, IamCertAkSkResp, IamOauth2AkSkResp, IamThirdPartyCertExtAddReq, IamCertDecodeRequest}; +use crate::basic::dto::iam_cert_dto::{IamCertAkSkAddReq, IamCertAkSkResp, IamCertDecodeRequest, IamOauth2AkSkResp, IamThirdPartyCertExtAddReq}; use crate::basic::serv::iam_account_serv::IamAccountServ; use crate::basic::serv::iam_cert_ldap_serv::IamCertLdapServ; use crate::basic::serv::iam_cert_serv::IamCertServ; diff --git a/support/iam/src/console_tenant/api/iam_ct_cert_manage_api.rs b/support/iam/src/console_tenant/api/iam_ct_cert_manage_api.rs index 30e9629b8..a4ee9cf67 100644 --- a/support/iam/src/console_tenant/api/iam_ct_cert_manage_api.rs +++ b/support/iam/src/console_tenant/api/iam_ct_cert_manage_api.rs @@ -216,6 +216,4 @@ impl IamCtCertManageApi { ctx.execute_task().await?; TardisResp::ok(rbum_certs) } - - }