Skip to content

Commit

Permalink
flow: check rel template (#791)
Browse files Browse the repository at this point in the history
Co-authored-by: hermitCode <297984816@qq.com>
  • Loading branch information
ZzIsGod1019 and LiJieLong authored Jun 27, 2024
1 parent 6b4a4c9 commit d62d5e6
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ strum = { version = "0.26", features = ["derive"] }
# tardis
tardis = { version = "0.1.0-rc.16" }
# tardis = { path = "../tardis/tardis" }
# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "366f128" }
# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "4eb5ef9" }

#spacegate

# spacegate-shell = { path = "../spacegate/crates/shell", features = [
Expand Down
33 changes: 25 additions & 8 deletions backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use std::collections::HashMap;

use crate::dto::flow_model_dto::{
FlowModelAddCustomModelReq, FlowModelAddCustomModelResp, FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceCiReq, FlowModelExistRelByTemplateIdsReq,
FlowModelFilterReq, FlowModelFindRelStateResp,
};
use crate::flow_constants;
use crate::serv::flow_model_serv::FlowModelServ;
use crate::serv::flow_rel_serv::{FlowRelKind, FlowRelServ};
use bios_basic::rbum::dto::rbum_filer_dto::RbumBasicFilterReq;
use bios_basic::rbum::helper::rbum_scope_helper::{self, check_without_owner_and_unsafe_fill_ctx};
use bios_basic::rbum::rbum_enumeration::RbumScopeLevelKind;
use bios_basic::rbum::serv::rbum_item_serv::RbumItemCrudOperation;
use itertools::Itertools;
use std::iter::Iterator;
use tardis::basic::dto::TardisContext;
use tardis::web::context_extractor::TardisContextExtractor;
use tardis::web::poem::Request;
use tardis::web::poem_openapi;
use tardis::web::poem_openapi::param::{Path, Query};
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};

use crate::dto::flow_model_dto::{
FlowModelAddCustomModelReq, FlowModelAddCustomModelResp, FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceCiReq, FlowModelFilterReq,
FlowModelFindRelStateResp,
};
use crate::flow_constants;
use crate::serv::flow_model_serv::FlowModelServ;
use crate::serv::flow_rel_serv::{FlowRelKind, FlowRelServ};
#[derive(Clone)]
pub struct FlowCiModelApi;

Expand Down Expand Up @@ -232,4 +232,21 @@ impl FlowCiModelApi {
ctx.0.execute_task().await?;
TardisResp::ok(Void)
}

/// batch delete models by rel_template_id
///
/// 通过模板ID检查是否存在关联,返回关联的模板ID
#[oai(path = "/exist_rel_by_template_ids", method = "post")]
async fn exist_rel_by_template_ids(&self, req: Json<FlowModelExistRelByTemplateIdsReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Vec<String>> {
let funs = flow_constants::get_tardis_inst();
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
let mut result = vec![];
for rel_template_id in req.0.rel_template_ids {
if !FlowRelServ::find_to_simple_rels(&FlowRelKind::FlowModelTemplate, &rel_template_id, None, None, &funs, &ctx.0).await?.is_empty() {
result.push(rel_template_id.clone());
}
}

TardisResp::ok(result)
}
}
7 changes: 7 additions & 0 deletions backend/middlewares/flow/src/dto/flow_model_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,10 @@ pub struct FlowModelCopyOrReferenceCiReq {
/// 修改的模板ID
pub op: FlowModelAssociativeOperationKind,
}

/// 检查关联模板请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct FlowModelExistRelByTemplateIdsReq {
/// 关联的模板ID
pub rel_template_ids: Vec<String>,
}
5 changes: 2 additions & 3 deletions backend/middlewares/flow/src/flow_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ use bios_basic::rbum::{
use bios_sdk_invoke::invoke_initializer;

use itertools::Itertools;
use serde_json::json;

use tardis::{
basic::{dto::TardisContext, field::TrimString, result::TardisResult},
db::{
reldb_client::TardisActiveModel,
sea_orm::{
ColumnTrait, EntityTrait, QueryFilter,
self,
sea_query::{Expr, Query, Table},
ColumnTrait, EntityTrait, QueryFilter,
},
},
futures::future::join_all,
Expand Down Expand Up @@ -170,7 +169,7 @@ pub async fn merge_state_by_name(funs: &TardisFunsInst, ctx: &TardisContext) ->
None,
false,
true,
Some(json!(rel.rel.ext).to_string()),
Some(rel.rel.ext),
funs,
&mock_ctx,
)
Expand Down
2 changes: 1 addition & 1 deletion backend/services/bios-all/config/locale/zh-cn.flow
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
404-flow-inst-rel-model-not-found 找不到实例关联的模型
404-flow-inst-transfer-state-not-found 没有可流转的状态
500-external-illegal-response 对外接口响应异常
500-flow_model-prohibit-delete 当前模型不可删除
500-flow_model-prohibit-delete 当前模型不可删除
500-flow-transition-endless-loop 状态流转出现死循环
409-rbum-rel-exist 状态关联已存在
12 changes: 6 additions & 6 deletions backend/spi/spi-object/src/serv/s3/object_s3_obj_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn presign_obj_url(
) -> TardisResult<String> {
let bs_inst = inst.inst::<TardisOSClient>();
let client = bs_inst.0;
let bucket_name = get_bucket_name(private, special, obj_exp.clone().map(|_| true), inst);
let bucket_name = get_bucket_name(private, special, obj_exp.map(|_| true), inst);
match presign_kind {
ObjectObjPresignKind::Upload => {
client.object_create_url(&rebuild_path(bucket_name.as_deref(), object_path, obj_exp, client).await?, exp_secs, bucket_name.as_deref()).await
Expand Down Expand Up @@ -66,7 +66,7 @@ pub async fn object_delete(
) -> TardisResult<()> {
let bs_inst = inst.inst::<TardisOSClient>();
let client = bs_inst.0;
let bucket_name = get_bucket_name(private, special, obj_exp.clone().map(|_| true), inst);
let bucket_name = get_bucket_name(private, special, obj_exp.map(|_| true), inst);
client.object_delete(object_path, bucket_name.as_deref()).await
}

Expand Down Expand Up @@ -114,7 +114,7 @@ pub async fn object_exist(
) -> TardisResult<bool> {
let bs_inst = inst.inst::<TardisOSClient>();
let client = bs_inst.0;
let bucket_name = get_bucket_name(private, special, obj_exp.clone().map(|_| true), inst);
let bucket_name = get_bucket_name(private, special, obj_exp.map(|_| true), inst);
client.object_exist(object_path, bucket_name.as_deref()).await
}

Expand Down Expand Up @@ -219,14 +219,14 @@ async fn rebuild_path(bucket_name: Option<&str>, origin_path: &str, obj_exp: Opt
let mut rules = config.rules;
let prefix = if let Some(is_have_prefix) = rules
.iter()
.filter(|r| r.status == "Enabled".to_string() && r.expiration.clone().is_some_and(|exp| exp.days.is_some_and(|days| days == obj_exp)))
.filter(|r| r.status == *"Enabled" && r.expiration.clone().is_some_and(|exp| exp.days.is_some_and(|days| days == obj_exp)))
.filter_map(|r| r.filter.clone())
.find_map(|f| f.prefix)
{
is_have_prefix
} else {
let rand_id = tardis::rand::random::<usize>().to_string();
let prefix=format!("{}/", rand_id);
let prefix = format!("{}/", rand_id);
//add rule
let add_rule = LifecycleRule::builder("Enabled")
.id(&rand_id)
Expand All @@ -245,7 +245,7 @@ async fn rebuild_path(bucket_name: Option<&str>, origin_path: &str, obj_exp: Opt
}
let mut rules = vec![];
let rand_id = tardis::rand::random::<usize>().to_string();
let prefix=format!("{}/", rand_id);
let prefix = format!("{}/", rand_id);
//add rule
let add_rule = LifecycleRule::builder("Enabled")
.id(&rand_id)
Expand Down
2 changes: 1 addition & 1 deletion backend/supports/iam/src/basic/serv/iam_role_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl RbumItemCrudOperation<iam_role::ActiveModel, IamRoleAddReq, IamRoleModifyRe
if !op_describe.is_empty() {
let _ = IamLogClient::add_ctx_task(LogParamTag::IamRole, Some(id.to_string()), op_describe, Some(op_kind), ctx).await;
}
IamKvClient::async_add_or_modify_key_name("iam_role".to_string(),id.to_string(), role.name.clone(), funs, ctx).await?;
IamKvClient::async_add_or_modify_key_name("iam_role".to_string(), id.to_string(), role.name.clone(), funs, ctx).await?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/sdks/invoke/src/dto.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod search_item_dto;
pub mod stats_record_dto;
pub mod stats_record_dto;

0 comments on commit d62d5e6

Please sign in to comment.