Skip to content

Commit

Permalink
iam: filter cert support ext (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Sep 5, 2024
1 parent cdef4d0 commit beefba7
Show file tree
Hide file tree
Showing 34 changed files with 305 additions and 278 deletions.
2 changes: 0 additions & 2 deletions backend/middlewares/event/src/api/event_listener_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ impl EventListenerApi {
/// 注册事件监听器
#[oai(path = "/", method = "post")]
async fn register(&self, listener: Json<EventListenerRegisterReq>) -> TardisApiResult<EventListenerRegisterResp> {

TardisResp::err(TardisError::not_implemented("unimplemented", "unimplemented"))
}

Expand All @@ -30,6 +29,5 @@ impl EventListenerApi {
#[oai(path = "/:listener_code", method = "delete")]
async fn remove(&self, listener_code: Path<String>, token: Query<String>) -> TardisApiResult<Void> {
TardisResp::err(TardisError::not_implemented("unimplemented", "unimplemented"))

}
}
1 change: 0 additions & 1 deletion backend/middlewares/event/src/api/event_proc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use tardis::web::poem::web::websocket::{BoxWebSocketUpgraded, WebSocket};
use tardis::web::poem_openapi;
use tardis::web::poem_openapi::param::{Path, Query};


#[derive(Clone)]
pub struct EventProcApi;

Expand Down
1 change: 1 addition & 0 deletions backend/middlewares/event/src/serv/event_listener_serv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions backend/middlewares/event/src/serv/event_proc_serv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 0 additions & 1 deletion backend/middlewares/event/tests/test_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use tardis::basic::result::TardisResult;
use tardis::tokio::time::sleep;
use tardis::{testcontainers, tokio, TardisFuns};


#[tokio::test(flavor = "multi_thread")]
async fn test_event() -> TardisResult<()> {
env::set_var("RUST_LOG", "debug,tardis=trace,bios_mw_event=trace,test_event=trace,sqlx::query=off");
Expand Down
39 changes: 37 additions & 2 deletions backend/middlewares/flow/src/api/cc/flow_cc_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void};

use crate::dto::flow_model_dto::{
FlowModelAddCustomModelReq, FlowModelAddCustomModelResp, FlowModelAddReq, FlowModelAggResp, FlowModelBindStateReq, FlowModelFilterReq, FlowModelFindRelStateResp,
FlowModelModifyReq, FlowModelSortStatesReq, FlowModelSummaryResp, FlowModelUnbindStateReq,
FlowModelAddCustomModelReq, FlowModelAddCustomModelResp, FlowModelAddReq, FlowModelAggResp, FlowModelBindStateReq, FlowModelFilterReq, FlowModelFindRelStateResp, FlowModelModifyReq, FlowModelSortStatesReq, FlowModelSummaryResp, FlowModelUnbindStateReq
};
use crate::dto::flow_state_dto::FlowStateRelModelModifyReq;
use crate::dto::flow_transition_dto::{FlowTransitionModifyReq, FlowTransitionSortStatesReq};
Expand Down Expand Up @@ -54,6 +53,42 @@ impl FlowCcModelApi {
TardisResp::ok(Void {})
}

/// Copy Model By Model Id
///
/// 复制模型
#[oai(path = "/copy/:flow_model_id", method = "patch")]
async fn copy(&self, flow_model_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<FlowModelAggResp> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let rel_model = FlowModelServ::get_item(
&flow_model_id.0,
&FlowModelFilterReq {
basic: RbumBasicFilterReq {
own_paths: Some("".to_string()),
with_sub_own_paths: true,
ignore_scope: true,
..Default::default()
},
..Default::default()
},
&funs,
&ctx.0,
)
.await?;
let new_model_id = FlowModelServ::add_item(
&mut FlowModelAddReq {
..rel_model.clone().into()
},
&funs,
&ctx.0,
)
.await?;
let new_model = FlowModelServ::get_item_detail_aggs(&new_model_id, true, &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(new_model)
}

/// Get Model By Model Id
///
/// 获取模型
Expand Down
10 changes: 0 additions & 10 deletions backend/middlewares/flow/src/api/ct/flow_ct_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@ impl FlowCtModelApi {
&ctx.0,
)
.await?;
FlowInstServ::batch_update_when_switch_model(
orginal_models.get(&new_model.tag).map(|orginal_model| orginal_model.id.clone()),
&new_model.tag,
&new_model.id,
new_model.states.clone(),
&new_model.init_state_id,
&funs,
&ctx.0,
)
.await?;
result.insert(from_model.rel_model_id.clone(), new_model);
}
funs.commit().await?;
Expand Down
2 changes: 1 addition & 1 deletion backend/middlewares/flow/src/flow_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bios_basic::{process::ci_processor::AppKeyConfig, rbum::rbum_config::RbumConfig};
use bios_sdk_invoke::{invoke_config::InvokeConfig};
use bios_sdk_invoke::invoke_config::InvokeConfig;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::{fmt::Debug, sync::Mutex};
Expand Down
71 changes: 53 additions & 18 deletions backend/middlewares/flow/src/helper/loop_check_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! }

use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use tardis::log::warn;

use crate::dto::{
Expand Down Expand Up @@ -145,31 +145,66 @@ impl TransactionGraph {
}

pub fn check_state_loop(&self) -> bool {
let mut state_chains: HashSet<Vec<String>> = HashSet::new();
// init trans_chain
let mut trans_chain = vec![];
for ((from_tran_from_state, from_tran_to_state), to_trans) in &self.rels {
state_chains.insert(vec![from_tran_from_state.clone(), from_tran_to_state.clone()]);
for (to_tran_from_state, to_tran_to_state) in to_trans {
state_chains.insert(vec![to_tran_from_state.clone(), to_tran_to_state.clone()]);
for state_tran in state_chains.clone() {
if state_tran.last().unwrap() == to_tran_from_state {
let mut insert_chain = state_tran.clone();
insert_chain.push(to_tran_to_state.clone());
state_chains.insert(insert_chain);
trans_chain.push(Vec::from([(from_tran_from_state.clone(), from_tran_to_state.clone()), (to_tran_from_state.clone(), to_tran_to_state.clone())]));
}
}
warn!("check state loop init trans_chain: {:?}", trans_chain);
// complate trans_chain
loop {
let mut is_modify = false;
let mut new_trans_chain = vec![];
for tran_chain in trans_chain.iter() {
let from_tran = tran_chain.last().cloned().unwrap_or_default();
if let Some(to_trans) = self.rels.get(&from_tran) {
for to_tran in to_trans {
if !tran_chain.contains(to_tran) {
let mut new_tran_chain = tran_chain.clone();
new_tran_chain.push(to_tran.clone());
if !trans_chain.contains(&new_tran_chain) {
is_modify = true;
new_trans_chain.push(new_tran_chain);
}
} else {
new_trans_chain.push(tran_chain.clone());
}
}
} else {
new_trans_chain.push(tran_chain.clone());
}
}
trans_chain = new_trans_chain;
if !is_modify {
break;
}
warn!("check state loop trans_chain: {:?}", trans_chain);
}
warn!("check state loop state_chains: {:?}", state_chains);
for state_chain in state_chains {
let mut tran_chain = vec![];
let mut from_state = state_chain[0].clone();
for state in &state_chain[1..] {
if tran_chain.contains(&(from_state.clone(), state.clone())) {
return false;

#[derive(Debug)]
struct StateChain {
chain: Vec<String>,
current_state: String,
}
for tran_chain in trans_chain {
let mut state_chains:Vec<StateChain> = vec![];
for (from_state, to_state) in tran_chain.iter() {
if let Some(state_chain) = state_chains.iter_mut().find(|state_chain| state_chain.current_state == from_state.clone()) {
if state_chain.chain.iter().any(|state| state == to_state) {
return false;
}
state_chain.chain.push(to_state.clone());
state_chain.current_state = to_state.clone();
} else {
state_chains.push(StateChain {
chain: vec![from_state.clone(), to_state.clone()],
current_state: to_state.clone(),
})
}
tran_chain.push((from_state.clone(), state.clone()));
from_state.clone_from(state);
}
warn!("check state loop state_chains: {:?}, trans_chain: {:?}", state_chains, tran_chain);
}

true
Expand Down
6 changes: 4 additions & 2 deletions backend/middlewares/flow/src/serv/clients/search_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl FlowSearchClient {
if model_resp.scope_level == RbumScopeLevelKind::Root {
visit_apps.push("".to_string());
visit_tenants.push("".to_string());
own_paths = None;
own_paths = Some("".to_string());
}
let key = model_id.clone();
if *is_modify {
Expand All @@ -104,6 +104,7 @@ impl FlowSearchClient {
"info": model_resp.info,
"rel_template_ids": model_resp.rel_template_ids,
"scope_level": model_resp.scope_level,
"tenant_id": model_resp.own_paths.clone(),
})),
ext_override: Some(true),
visit_keys: Some(SearchItemVisitKeysReq {
Expand Down Expand Up @@ -137,6 +138,7 @@ impl FlowSearchClient {
"info": model_resp.info,
"rel_template_ids": model_resp.rel_template_ids,
"scope_level": model_resp.scope_level,
"tenant_id": model_resp.own_paths.clone(),
})),
visit_keys: Some(SearchItemVisitKeysReq {
accounts: None,
Expand All @@ -160,7 +162,7 @@ impl FlowSearchClient {
pub async fn delete_model_search(model_id: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
if let Some(_topic) = get_topic(&SPI_RPC_TOPIC) {
EventCenterClient { topic_code: SPI_RPC_TOPIC }.delete_item_and_name(SEARCH_TAG, model_id, funs, ctx).await?;
} else {
} else {
SpiSearchClient::delete_item_and_name(SEARCH_TAG, model_id, funs, ctx).await?;
}
Ok(())
Expand Down
18 changes: 14 additions & 4 deletions backend/middlewares/flow/src/serv/flow_event_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::{collections::HashMap, str::FromStr};
use async_recursion::async_recursion;
use bios_basic::rbum::dto::rbum_filer_dto::RbumBasicFilterReq;
use bios_sdk_invoke::clients::{
event_client::{get_topic, mq_error, EventAttributeExt}, flow_client::{event::FLOW_AVATAR, FlowFrontChangeReq}
event_client::{get_topic, mq_error, EventAttributeExt},
flow_client::{event::FLOW_AVATAR, FlowFrontChangeReq},
};
use rust_decimal::Decimal;
use serde_json::{json, Value};
Expand All @@ -28,7 +29,8 @@ use crate::{
FlowTransitionActionByStateChangeInfo, FlowTransitionActionByVarChangeInfoChangedKind, FlowTransitionActionChangeAgg, FlowTransitionActionChangeKind,
FlowTransitionFrontActionInfo, FlowTransitionFrontActionRightValue, StateChangeConditionOp, TagRelKind,
},
}, event::FLOW_TOPIC,
},
event::FLOW_TOPIC,
};

use super::{flow_external_serv::FlowExternalServ, flow_inst_serv::FlowInstServ, flow_model_serv::FlowModelServ, flow_state_serv::FlowStateServ};
Expand Down Expand Up @@ -369,8 +371,16 @@ impl FlowEventServ {
)
.await?;
if let Some(topic) = get_topic(&FLOW_TOPIC) {
topic.send_event(FlowFrontChangeReq { inst_id: flow_inst_detail.id.to_string() }.inject_context(funs, ctx).json()).await.map_err(mq_error)?;

topic
.send_event(
FlowFrontChangeReq {
inst_id: flow_inst_detail.id.to_string(),
}
.inject_context(funs, ctx)
.json(),
)
.await
.map_err(mq_error)?;
} else {
FlowEventServ::do_front_change(&flow_inst_detail.id, ctx, funs).await?;
}
Expand Down
11 changes: 2 additions & 9 deletions backend/middlewares/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl FlowInstServ {
if current_state_name.is_empty() {
flow_model.init_state_id.clone()
} else {
FlowStateServ::match_state_id_by_name(&start_req.tag, &flow_model_id, current_state_name, funs, ctx).await?
FlowStateServ::match_state_id_by_name(&flow_model_id, current_state_name, funs, ctx).await?
}
} else {
flow_model.init_state_id.clone()
Expand Down Expand Up @@ -130,14 +130,7 @@ impl FlowInstServ {
current_ctx.owner = rel_business_obj.owner.clone().unwrap_or_default();
let flow_model_id = FlowModelServ::get_model_id_by_own_paths_and_rel_template_id(&batch_bind_req.tag, None, funs, ctx).await?;

let current_state_id = FlowStateServ::match_state_id_by_name(
&batch_bind_req.tag,
&flow_model_id,
&rel_business_obj.current_state_name.clone().unwrap_or_default(),
funs,
ctx,
)
.await?;
let current_state_id = FlowStateServ::match_state_id_by_name(&flow_model_id, &rel_business_obj.current_state_name.clone().unwrap_or_default(), funs, ctx).await?;
let mut inst_id = Self::get_inst_ids_by_rel_business_obj_id(vec![rel_business_obj.rel_business_obj_id.clone().unwrap_or_default()], funs, ctx).await?.pop();
if inst_id.is_none() {
let id = TardisFuns::field.nanoid();
Expand Down
3 changes: 2 additions & 1 deletion backend/middlewares/flow/src/serv/flow_model_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,8 @@ impl FlowModelServ {
}
}

Ok(!loop_check_helper::check(&model_details))
// Ok(!loop_check_helper::check(&model_details))
Ok(false)
}

pub async fn find_rel_states(tags: Vec<&str>, rel_template_id: Option<String>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<Vec<FlowModelFindRelStateResp>> {
Expand Down
Loading

0 comments on commit beefba7

Please sign in to comment.