Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Jan 4, 2025
2 parents 95dc3a8 + 38bdeb4 commit 652df8c
Show file tree
Hide file tree
Showing 23 changed files with 343 additions and 155 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ strum = { version = "0.26", features = ["derive"] }
# tardis
# tardis = { version = "0.1.0-rc.17" }
# tardis = { version = "0.2.0", path = "../tardis/tardis" }
tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "66d4c63" }
tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "f666d50" }
# asteroid-mq = { git = "https://github.com/4t145/asteroid-mq.git", rev = "d59c64d" }
asteroid-mq = { git = "https://github.com/4t145/asteroid-mq.git", rev = "b26fa4f" }
# asteroid-mq = { version = "0.1.0-alpha.5" }
Expand Down
14 changes: 8 additions & 6 deletions backend/basic/src/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ impl BasicQueryCondInfo {
| BasicQueryOpKind::NotRLike => {
check_val.as_str().map(|check_val_str| cond.value.as_str().map(|cond_val_str| check_val_str.contains(cond_val_str)).unwrap_or(false)).unwrap_or(false)
}
BasicQueryOpKind::In => check_val.as_array().map(|check_val_arr| {
if cond.value.is_array() {
cond.value.as_array().unwrap_or(&vec![]).iter().any(|item| check_val_arr.contains(&item))
} else {
check_val_arr.contains(&cond.value)
}
BasicQueryOpKind::In => check_val
.as_array()
.map(|check_val_arr| {
if cond.value.is_array() {
cond.value.as_array().unwrap_or(&vec![]).iter().any(|item| check_val_arr.contains(&item))
} else {
check_val_arr.contains(&cond.value)
}
})
.unwrap_or(false),
BasicQueryOpKind::NotIn => check_val.as_array().map(|check_val_arr| check_val_arr.contains(&cond.value)).unwrap_or(false),
Expand Down
1 change: 1 addition & 0 deletions backend/gateways/spacegate-plugins/src/plugin/audit_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl AuditLogPlugin {
InvokeConfig {
spi_app_id: self.spi_app_id.clone(),
module_urls: HashMap::from([(InvokeModuleKind::Log.to_string(), self.log_url.clone())]),
..Default::default()
},
)?;
}
Expand Down
13 changes: 11 additions & 2 deletions backend/middlewares/flow/src/dto/flow_state_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ use bios_basic::rbum::{
};
use serde::{Deserialize, Serialize};
use tardis::{
basic::{dto::TardisContext, error::TardisError, field::TrimString},
basic::{dto::TardisContext, error::TardisError, field::TrimString, result::TardisResult},
chrono::{DateTime, Utc},
db::sea_orm::{self, prelude::*, EnumIter},
serde_json::Value,
web::poem_openapi,
TardisFuns,
TardisFuns, TardisFunsInst,
};

use crate::serv::clients::kv_client::FlowKvClient;

use super::flow_transition_dto::FlowTransitionDetailResp;

#[derive(Clone, Serialize, Deserialize, Default, Debug, poem_openapi::Object)]
Expand Down Expand Up @@ -225,6 +227,13 @@ impl FlowGuardConf {
}
false
}

pub async fn get_local_conf(&mut self, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
for role_id in self.guard_by_spec_role_ids.iter_mut() {
*role_id = FlowKvClient::get_role_id(role_id, funs, ctx).await?;
}
Ok(())
}
}

// 节点通知配置
Expand Down
27 changes: 27 additions & 0 deletions backend/middlewares/flow/src/serv/clients/kv_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use bios_basic::rbum::helper::rbum_scope_helper;
use bios_sdk_invoke::clients::spi_kv_client::SpiKvClient;
use itertools::Itertools;
use tardis::{
basic::{dto::TardisContext, result::TardisResult},
TardisFunsInst,
Expand All @@ -14,4 +16,29 @@ impl FlowKvClient {
.unwrap_or_default();
Ok(account_name)
}

pub async fn get_role_id(original_id: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<String> {
let mut role_id = "".to_string();
if let Some(role_id_prefix) = original_id.split(':').collect_vec().first() {
role_id = SpiKvClient::match_items_by_key_prefix(format!("__k_n__:iam_role:{}", role_id_prefix), None, 1, 999, None, funs, ctx).await?
.map(|resp| {
resp.records.into_iter().filter(|record| ctx.own_paths.contains(&record.own_paths)).collect_vec()
})
.map(|records| {
if let Some(item) = records.iter().find(|r| r.own_paths == ctx.own_paths) {
return item.key.split("__k_n__:iam_role:").collect_vec().pop().map(|s| s.to_string()).unwrap_or_default();
}
if let Some(item) = records.iter().find(|r| r.own_paths == rbum_scope_helper::get_path_item(1, &ctx.own_paths).unwrap_or_default()) {
return item.key.split("__k_n__:iam_role:").collect_vec().pop().map(|s| s.to_string()).unwrap_or_default();
}
if let Some(item) = records.iter().find(|r| r.own_paths.is_empty()) {
return item.key.split("__k_n__:iam_role:").collect_vec().pop().map(|s| s.to_string()).unwrap_or_default();
}
"".to_string()
})
.unwrap_or_default();
}

Ok(role_id)
}
}
10 changes: 8 additions & 2 deletions backend/middlewares/flow/src/serv/clients/search_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use itertools::Itertools;
use serde_json::json;
use tardis::{
basic::{dto::TardisContext, field::TrimString, result::TardisResult},
log::debug,
log::{debug, error},
tokio,
web::{poem_openapi::types::ToJSON, web_resp::TardisPage},
TardisFuns, TardisFunsInst,
Expand Down Expand Up @@ -267,11 +267,15 @@ impl FlowSearchClient {
let inst_resp = FlowInstServ::get(inst_id, funs, &mock_ctx).await?;
ctx.add_async_task(Box::new(|| {
Box::pin(async move {
let inst_id_cp = inst_resp.id.clone();
let task_handle = tokio::spawn(async move {
let funs = flow_constants::get_tardis_inst();
let _ = Self::add_or_modify_instance_search(&inst_resp, is_modify, &funs, &ctx_clone).await;
});
task_handle.await.unwrap();
match task_handle.await {
Ok(_) => {}
Err(e) => error!("Flow search_client {} async_add_or_modify_instance_search error:{:?}", inst_id_cp, e),
}
Ok(())
})
}))
Expand Down Expand Up @@ -302,6 +306,7 @@ impl FlowSearchClient {
ext: Some(json!({
"tag": inst_resp.tag,
"current_state_id": inst_resp.current_state_id,
"rel_business_obj_name": name.clone(),
"current_state_name": inst_resp.current_state_name,
"current_state_kind": inst_resp.current_state_kind,
"rel_business_obj_id": inst_resp.rel_business_obj_id,
Expand Down Expand Up @@ -345,6 +350,7 @@ impl FlowSearchClient {
"current_state_id": inst_resp.current_state_id,
"current_state_name": inst_resp.current_state_name,
"current_state_kind": inst_resp.current_state_kind,
"rel_business_obj_name": name.clone(),
"rel_business_obj_id": inst_resp.rel_business_obj_id,
"finish_time": inst_resp.finish_time,
"op_time": inst_resp.update_time,
Expand Down
2 changes: 1 addition & 1 deletion backend/middlewares/flow/src/serv/flow_event_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl FlowEventServ {
&flow_inst_detail.rel_business_obj_id,
&flow_inst_detail.id,
Some(FlowExternalCallbackOp::PostAction),
Some(true),
Some(false),
None,
Some(next_flow_state.name.clone()),
Some(next_flow_state.sys_state.clone()),
Expand Down
41 changes: 27 additions & 14 deletions backend/middlewares/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl FlowInstServ {

let flow_inst_detail = Self::get(flow_inst_id, funs, ctx).await?;
if !flow_inst_detail.main {
// FlowLogServ::add_finish_log(&flow_inst_detail, funs, ctx).await?;
FlowLogServ::add_finish_log(&flow_inst_detail, funs, ctx).await?;
FlowSearchClient::modify_business_obj_search(&flow_inst_detail.rel_business_obj_id, &flow_inst_detail.tag, funs, ctx).await?;
FlowSearchClient::async_add_or_modify_instance_search(&flow_inst_detail.id, Box::new(true), funs, ctx).await?;
}
Expand Down Expand Up @@ -656,6 +656,7 @@ impl FlowInstServ {
&inst.current_state_kind.unwrap_or_default(),
current_state_kind_conf,
artifacts,
inst.finish_time.is_some(),
ctx,
),
current_vars: inst.current_vars.map(|current_vars| TardisFuns::json.json_to_obj(current_vars).unwrap()),
Expand Down Expand Up @@ -1077,7 +1078,7 @@ impl FlowInstServ {
let curr_inst = Self::get(&flow_inst_detail.id, funs, ctx).await?;

if next_flow_state.sys_state == FlowSysStateKind::Finish && !curr_inst.main {
// FlowLogServ::add_finish_log(&curr_inst, funs, ctx).await?;
FlowLogServ::add_finish_log(&curr_inst, funs, ctx).await?;
FlowSearchClient::modify_business_obj_search(&curr_inst.rel_business_obj_id, &curr_inst.tag, funs, ctx).await?;
}

Expand Down Expand Up @@ -1690,6 +1691,9 @@ impl FlowInstServ {
let mut modify_req = FlowInstArtifactsModifyReq { ..Default::default() };
let form_conf = state.kind_conf().unwrap_or_default().form.unwrap_or_default();
let mut guard_custom_conf = form_conf.guard_custom_conf.unwrap_or_default();
if state.own_paths != flow_inst_detail.own_paths {
guard_custom_conf.get_local_conf(funs, ctx).await?;
}
if form_conf.guard_by_creator {
guard_custom_conf.guard_by_spec_account_ids.push(flow_inst_detail.create_ctx.owner.clone());
}
Expand Down Expand Up @@ -1783,6 +1787,9 @@ impl FlowInstServ {
let mut modify_req = FlowInstArtifactsModifyReq { ..Default::default() };
let approval_conf = state.kind_conf().unwrap_or_default().approval.unwrap_or_default();
let mut guard_custom_conf = approval_conf.guard_custom_conf.unwrap_or_default();
if state.own_paths != flow_inst_detail.own_paths {
guard_custom_conf.get_local_conf(funs, ctx).await?;
}
if approval_conf.guard_by_creator {
guard_custom_conf.guard_by_spec_account_ids.push(flow_inst_detail.create_ctx.owner.clone());
}
Expand Down Expand Up @@ -1864,7 +1871,10 @@ impl FlowInstServ {
}
}
FlowStatusAutoStrategyKind::SpecifyAgent => {
let auto_transfer_when_empty_guard_custom_conf = approval_conf.auto_transfer_when_empty_guard_custom_conf.clone().unwrap_or_default();
let mut auto_transfer_when_empty_guard_custom_conf = approval_conf.auto_transfer_when_empty_guard_custom_conf.clone().unwrap_or_default();
if state.own_paths != flow_inst_detail.own_paths {
auto_transfer_when_empty_guard_custom_conf.get_local_conf(funs, ctx).await?;
}
let guard_accounts = FlowSearchClient::search_guard_accounts(&auto_transfer_when_empty_guard_custom_conf, funs, ctx).await?;
modify_req.curr_approval_total = Some(guard_accounts.len());
modify_req.curr_operators = Some(guard_accounts);
Expand Down Expand Up @@ -1895,7 +1905,7 @@ impl FlowInstServ {
&flow_inst_detail.rel_business_obj_id,
&flow_inst_detail.id,
Some(FlowExternalCallbackOp::Auto),
Some(true),
None,
Some("审批通过".to_string()),
None,
None,
Expand Down Expand Up @@ -1926,7 +1936,7 @@ impl FlowInstServ {
&flow_inst_detail.rel_business_obj_id,
&flow_inst_detail.id,
None,
Some(true),
None,
Some("审批通过".to_string()),
None,
None,
Expand Down Expand Up @@ -2057,6 +2067,7 @@ impl FlowInstServ {
state_kind: &FlowStateKind,
kind_conf: Option<FLowStateKindConf>,
artifacts: Option<FlowInstArtifacts>,
finish: bool,
ctx: &TardisContext,
) -> Option<FLowInstStateConf> {
if let Some(kind_conf) = kind_conf {
Expand Down Expand Up @@ -2090,11 +2101,11 @@ impl FlowInstServ {
operators.insert(FlowStateOperatorKind::Pass, approval.pass_btn_name.clone());
operators.insert(FlowStateOperatorKind::Overrule, approval.overrule_btn_name.clone());
operators.insert(FlowStateOperatorKind::Back, approval.back_btn_name.clone());
if approval.referral {
if approval.referral && !finish {
operators.insert(FlowStateOperatorKind::Referral, "".to_string());
}
}
if approval.revoke && ctx.owner == artifacts.prev_non_auto_account_id.unwrap_or_default() {
if approval.revoke && ctx.owner == artifacts.prev_non_auto_account_id.unwrap_or_default() && !finish {
operators.insert(FlowStateOperatorKind::Revoke, "".to_string());
}
FLowInstStateConf {
Expand Down Expand Up @@ -2372,7 +2383,7 @@ impl FlowInstServ {

// 判断审批条件是否满足
async fn check_approval_cond(inst: &FlowInstDetailResp, kind: FlowApprovalResultKind, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<bool> {
let current_state_kind_conf = FlowStateServ::get_item(
let current_state = FlowStateServ::get_item(
&inst.current_state_id,
&FlowStateFilterReq {
basic: RbumBasicFilterReq {
Expand All @@ -2385,10 +2396,8 @@ impl FlowInstServ {
funs,
ctx,
)
.await?
.kind_conf()
.unwrap_or_default()
.approval;
.await?;
let current_state_kind_conf = current_state.kind_conf().unwrap_or_default().approval;
let artifacts = inst.artifacts.clone().unwrap_or_default();
let approval_total = artifacts.approval_total.unwrap_or_default().get(&inst.current_state_id).cloned().unwrap_or_default();
let approval_result = artifacts.approval_result.get(&inst.current_state_id).cloned().unwrap_or_default();
Expand All @@ -2402,19 +2411,23 @@ impl FlowInstServ {
return Ok(true);
}
let countersign_conf = current_state_kind_conf.countersign_conf;
let mut specified_pass_guard_conf = countersign_conf.specified_pass_guard_conf.clone().unwrap_or_default();
if current_state.own_paths != inst.own_paths {
specified_pass_guard_conf.get_local_conf(funs, ctx).await?;
}
// 指定人通过,则通过
if kind == FlowApprovalResultKind::Pass
&& countersign_conf.specified_pass_guard.unwrap_or(false)
&& countersign_conf.specified_pass_guard_conf.is_some()
&& countersign_conf.specified_pass_guard_conf.unwrap().check(ctx)
&& specified_pass_guard_conf.check(ctx)
{
return Ok(true);
}
// 指定人拒绝,则拒绝
if kind == FlowApprovalResultKind::Overrule
&& countersign_conf.specified_overrule_guard.unwrap_or(false)
&& countersign_conf.specified_overrule_guard_conf.is_some()
&& countersign_conf.specified_overrule_guard_conf.unwrap().check(ctx)
&& specified_pass_guard_conf.check(ctx)
{
return Ok(true);
}
Expand Down
11 changes: 6 additions & 5 deletions backend/middlewares/flow/src/serv/flow_log_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ impl FlowLogServ {
..Default::default()
};
if !artifacts.his_operators.as_ref().unwrap_or(&vec![]).contains(&ctx.owner) && !artifacts.curr_operators.as_ref().unwrap_or(&vec![]).contains(&ctx.owner) {
log_content.sub_id = None;
log_content.sub_kind = None;
log_content.operand_id = None;
log_content.operand_kind = None;
}
Expand Down Expand Up @@ -357,7 +359,7 @@ impl FlowLogServ {
subject: Some(subject_text),
name: Some(flow_inst_detail.code.clone()),
sub_id: Some(flow_inst_detail.id.clone()),
sub_kind: Some(FlowLogClient::get_junp_kind("FLOW")),
sub_kind: Some(FlowLogClient::get_junp_kind(&flow_inst_detail.tag)),
operand: Some(operand),
operand_name: Some(current_state.name),
operand_id: Some(flow_inst_detail.rel_business_obj_id.clone()),
Expand All @@ -369,8 +371,7 @@ impl FlowLogServ {
..Default::default()
};
if !artifacts.his_operators.as_ref().unwrap_or(&vec![]).contains(&ctx.owner) && !artifacts.curr_operators.as_ref().unwrap_or(&vec![]).contains(&ctx.owner) {
log_content.sub_id = None;
log_content.sub_kind = None;
log_content.operand_id = None;
}
if operate_req.operate == FlowStateOperatorKind::Referral {
log_content.flow_referral = Some(FlowKvClient::get_account_name(&operate_req.operator.clone().unwrap_or_default(), funs, ctx).await?);
Expand Down Expand Up @@ -448,14 +449,14 @@ impl FlowLogServ {
subject: Some(subject_text),
name: Some(flow_inst_detail.code.clone()),
sub_id: Some(flow_inst_detail.id.clone()),
sub_kind: Some(FlowLogClient::get_junp_kind("FLOW")),
sub_kind: Some(FlowLogClient::get_junp_kind(&flow_inst_detail.tag)),
old_content: "".to_string(),
new_content: "".to_string(),
..Default::default()
};

if !artifacts.his_operators.as_ref().unwrap_or(&vec![]).contains(&ctx.owner) && !artifacts.curr_operators.as_ref().unwrap_or(&vec![]).contains(&ctx.owner) {
log_content.sub_id = None;
log_content.sub_kind = None;
}
FlowLogClient::add_ctx_task(
LogParamTag::ApprovalFlow,
Expand Down
7 changes: 6 additions & 1 deletion backend/spi/spi-log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ tardis = { workspace = true, features = ["reldb-postgres", "web-server"] }
bios-basic = { version = "0.2.0", path = "../../basic", features = ["default"] }
bios-sdk-invoke = { version = "0.2.0", path = "../../../frontend/sdks/invoke", features = [
"event",
"spi_log",
"spi_stats",
], default-features = false }

[dev-dependencies]
tardis = { workspace = true, features = ["test"] }
bios-basic = { version = "0.2.0", path = "../../basic", features = ["default", "test"] }
bios-basic = { version = "0.2.0", path = "../../basic", features = [
"default",
"test",
] }
Loading

0 comments on commit 652df8c

Please sign in to comment.