From ce7549a6911571b18d3a2208c3c4ce58d24bfbba Mon Sep 17 00:00:00 2001 From: ZzIsGod1019 <1498852723@qq.com> Date: Mon, 1 Jul 2024 10:35:27 +0800 Subject: [PATCH] fix compile error (#792) * flow: check rel template * fix compile error * flow: flow template share * flow: code fmt * spi-search: fix bug search result not found * flow: add model api find_rel_name_by_template_ids --------- Co-authored-by: hermitCode <297984816@qq.com> --- .../flow/src/api/ci/flow_ci_model_api.rs | 2 +- .../flow/src/api/ct/flow_ct_model_api.rs | 31 ++++++++++++++++++- .../flow/src/dto/flow_model_dto.rs | 9 +++++- .../flow/src/serv/clients/search_client.rs | 30 +++++++++--------- .../src/api/ci/plugin_ci_exec_api.rs | 1 + .../spi/spi-plugin/tests/test_plugin_exec.rs | 1 + .../src/serv/pg/search_pg_item_serv.rs | 23 +++++++++----- .../iam/src/basic/serv/iam_cert_ldap_serv.rs | 25 +++++++++++++++ 8 files changed, 96 insertions(+), 26 deletions(-) diff --git a/backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs b/backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs index 41d44cdb1..39c1ecaab 100644 --- a/backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs +++ b/backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs @@ -233,7 +233,7 @@ impl FlowCiModelApi { TardisResp::ok(Void) } - /// batch delete models by rel_template_id + /// Check if there is an association by template ID, return the associated template ID /// /// 通过模板ID检查是否存在关联,返回关联的模板ID #[oai(path = "/exist_rel_by_template_ids", method = "post")] diff --git a/backend/middlewares/flow/src/api/ct/flow_ct_model_api.rs b/backend/middlewares/flow/src/api/ct/flow_ct_model_api.rs index fb2158bb5..260714615 100644 --- a/backend/middlewares/flow/src/api/ct/flow_ct_model_api.rs +++ b/backend/middlewares/flow/src/api/ct/flow_ct_model_api.rs @@ -10,7 +10,10 @@ use tardis::web::{ }; use crate::{ - dto::flow_model_dto::{FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceReq, FlowModelFilterReq}, + dto::flow_model_dto::{ + FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceReq, FlowModelExistRelByTemplateIdsReq, FlowModelFilterReq, + FlowModelFindRelNameByTemplateIdsReq, + }, flow_constants, serv::{ flow_model_serv::FlowModelServ, @@ -136,4 +139,30 @@ impl FlowCtModelApi { ctx.0.execute_task().await?; TardisResp::ok(Void) } + + /// Get associated model names by template ID, multiple comma separated + /// + /// 通过模板ID获取关联的模型名,多个逗号隔开 + #[oai(path = "/find_rel_name_by_template_ids", method = "post")] + async fn find_rel_name_by_template_ids( + &self, + req: Json, + mut ctx: TardisContextExtractor, + request: &Request, + ) -> TardisApiResult>> { + let funs = flow_constants::get_tardis_inst(); + let mut result = HashMap::new(); + for rel_template_id in req.0.rel_template_ids { + result.insert( + rel_template_id.clone(), + FlowRelServ::find_to_simple_rels(&FlowRelKind::FlowModelTemplate, &rel_template_id, None, None, &funs, &ctx.0) + .await? + .into_iter() + .map(|rel| rel.rel_name) + .collect_vec(), + ); + } + + TardisResp::ok(result) + } } diff --git a/backend/middlewares/flow/src/dto/flow_model_dto.rs b/backend/middlewares/flow/src/dto/flow_model_dto.rs index c1a23b0db..2f6c1a2d1 100644 --- a/backend/middlewares/flow/src/dto/flow_model_dto.rs +++ b/backend/middlewares/flow/src/dto/flow_model_dto.rs @@ -76,7 +76,7 @@ pub struct FlowModelModifyReq { pub name: Option, #[oai(validator(min_length = "2", max_length = "2000"))] pub icon: Option, - #[oai(validator(min_length = "2", max_length = "2000"))] + #[oai(validator(max_length = "2000"))] pub info: Option, /// 初始化状态ID pub init_state_id: Option, @@ -354,3 +354,10 @@ pub struct FlowModelExistRelByTemplateIdsReq { /// 关联的模板ID pub rel_template_ids: Vec, } + +/// 获取关联的模型名请求 +#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)] +pub struct FlowModelFindRelNameByTemplateIdsReq { + /// 关联的模板ID + pub rel_template_ids: Vec, +} diff --git a/backend/middlewares/flow/src/serv/clients/search_client.rs b/backend/middlewares/flow/src/serv/clients/search_client.rs index a18f35f39..9a0b36a0f 100644 --- a/backend/middlewares/flow/src/serv/clients/search_client.rs +++ b/backend/middlewares/flow/src/serv/clients/search_client.rs @@ -76,7 +76,15 @@ impl IamSearchClient { // flow model 全局搜索埋点方法 pub async fn add_or_modify_model_search(model_resp: &FlowModelDetailResp, is_modify: Box, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { let model_id = &model_resp.id; - + // 数据共享权限处理 + let mut visit_tenants = rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &model_resp.own_paths).map(|tenant| vec![tenant]).unwrap_or_default(); + let mut visit_apps = rbum_scope_helper::get_path_item(RbumScopeLevelKind::L2.to_int(), &model_resp.own_paths).map(|app| vec![app]).unwrap_or_default(); + let mut own_paths = Some(model_resp.own_paths.clone()); + if model_resp.scope_level == RbumScopeLevelKind::Root { + visit_apps.push("".to_string()); + visit_tenants.push("".to_string()); + own_paths = None; + } let key = model_id.clone(); if *is_modify { let modify_req = SearchItemModifyReq { @@ -85,7 +93,7 @@ impl IamSearchClient { name: Some(model_resp.name.clone()), content: Some(model_resp.name.clone()), owner: Some(model_resp.owner.clone()), - own_paths: Some(model_resp.own_paths.clone()), + own_paths, create_time: Some(model_resp.create_time), update_time: Some(model_resp.update_time), ext: Some(json!({ @@ -98,12 +106,8 @@ impl IamSearchClient { ext_override: Some(true), visit_keys: Some(SearchItemVisitKeysReq { accounts: None, - apps: Some(vec![ - rbum_scope_helper::get_path_item(RbumScopeLevelKind::L2.to_int(), &model_resp.own_paths).unwrap_or_default() - ]), - tenants: Some(vec![ - rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &model_resp.own_paths).unwrap_or_default() - ]), + apps: Some(visit_apps), + tenants: Some(visit_tenants), roles: None, groups: None, }), @@ -131,7 +135,7 @@ impl IamSearchClient { name: Some(model_resp.name.clone()), content: model_resp.name.clone(), owner: Some(model_resp.owner.clone()), - own_paths: Some(model_resp.own_paths.clone()), + own_paths, create_time: Some(model_resp.create_time), update_time: Some(model_resp.update_time), ext: Some(json!({ @@ -143,12 +147,8 @@ impl IamSearchClient { })), visit_keys: Some(SearchItemVisitKeysReq { accounts: None, - apps: Some(vec![ - rbum_scope_helper::get_path_item(RbumScopeLevelKind::L2.to_int(), &model_resp.own_paths).unwrap_or_default() - ]), - tenants: Some(vec![ - rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &model_resp.own_paths).unwrap_or_default() - ]), + apps: Some(visit_apps), + tenants: Some(visit_tenants), roles: None, groups: None, }), diff --git a/backend/spi/spi-plugin/src/api/ci/plugin_ci_exec_api.rs b/backend/spi/spi-plugin/src/api/ci/plugin_ci_exec_api.rs index 725811c02..e023abe9a 100644 --- a/backend/spi/spi-plugin/src/api/ci/plugin_ci_exec_api.rs +++ b/backend/spi/spi-plugin/src/api/ci/plugin_ci_exec_api.rs @@ -37,6 +37,7 @@ impl PluginExecApi { body: Some(tardis::serde_json::Value::String(msg.0)), query: None, header: None, + percent_encode: None, }) } } diff --git a/backend/spi/spi-plugin/tests/test_plugin_exec.rs b/backend/spi/spi-plugin/tests/test_plugin_exec.rs index 07ac0cebe..2a0b91d6b 100644 --- a/backend/spi/spi-plugin/tests/test_plugin_exec.rs +++ b/backend/spi/spi-plugin/tests/test_plugin_exec.rs @@ -27,6 +27,7 @@ pub async fn test(client: &mut TestHttpClient) -> TardisResult<()> { )])), body: Some(json!({ "msg": "object" })), query: None, + percent_encode: None, }, ) .await; diff --git a/backend/spi/spi-search/src/serv/pg/search_pg_item_serv.rs b/backend/spi/spi-search/src/serv/pg/search_pg_item_serv.rs index 86e2bbc2e..9851ad906 100644 --- a/backend/spi/spi-search/src/serv/pg/search_pg_item_serv.rs +++ b/backend/spi/spi-search/src/serv/pg/search_pg_item_serv.rs @@ -281,23 +281,30 @@ pub async fn search(search_req: &mut SearchItemSearchReq, funs: &TardisFunsInst, }) .collect::(); sql_vals.push(Value::from(q.as_str())); - from_fragments = format!(", to_tsquery('public.chinese_zh', ${}) AS query", sql_vals.len()); + from_fragments = format!( + ", plainto_tsquery('public.chinese_zh', ${}) AS query1, plainto_tsquery('simple', ${}) AS query2", + sql_vals.len(), + sql_vals.len() + ); + + let rank_title = "GREATEST(COALESCE(ts_rank(title_tsv, query1), 0 :: float4), COALESCE(ts_rank(title_tsv, query2), 0 :: float4)) AS rank_title"; + let rank_content = "GREATEST(COALESCE(ts_rank(content_tsv, query1), 0 :: float4), COALESCE(ts_rank(content_tsv, query2), 0 :: float4)) AS rank_content"; match search_req.query.q_scope.as_ref().unwrap_or(&SearchItemSearchQScopeKind::Title) { SearchItemSearchQScopeKind::Title => { - select_fragments = ", COALESCE(ts_rank(title_tsv, query), 0::float4) AS rank_title, 0::float4 AS rank_content".to_string(); - where_fragments.push("(query @@ title_tsv)".to_string()); + select_fragments = format!(", {}, 0::float4 AS rank_content", rank_title); + where_fragments.push("(query1 @@ title_tsv OR query2 @@ title_tsv)".to_string()); // sql_vals.push(Value::from(format!("%{q}%"))); // where_fragments.push(format!("(query @@ title_tsv OR title LIKE ${})", sql_vals.len())); } SearchItemSearchQScopeKind::Content => { - select_fragments = ", 0::float4 AS rank_title, COALESCE(ts_rank(content_tsv, query), 0::float4) AS rank_content".to_string(); - where_fragments.push("(query @@ content_tsv)".to_string()); + select_fragments = format!(", 0::float4 AS rank_title, {}", rank_content); + where_fragments.push("(query1 @@ content_tsv OR query2 @@ content_tsv)".to_string()); // sql_vals.push(Value::from(format!("%{q}%"))); // where_fragments.push(format!("(query @@ content_tsv OR content LIKE ${})", sql_vals.len())); } SearchItemSearchQScopeKind::TitleContent => { - select_fragments = ", COALESCE(ts_rank(title_tsv, query), 0::float4) AS rank_title, COALESCE(ts_rank(content_tsv, query), 0::float4) AS rank_content".to_string(); - where_fragments.push("(query @@ title_tsv OR query @@ content_tsv)".to_string()); + select_fragments = format!(", {}, {}", rank_title, rank_content); + where_fragments.push("((query1 @@ title_tsv OR query2 @@ title_tsv) OR (query1 @@ content_tsv OR query2 @@ content_tsv))".to_string()); // sql_vals.push(Value::from(format!("%{q}%"))); // where_fragments.push(format!( // "(query @@ title_tsv OR query @@ content_tsv OR title LIKE ${} OR content LIKE ${})", @@ -794,7 +801,7 @@ pub async fn query_metrics(query_req: &SearchQueryMetricsReq, funs: &TardisFunsI }) .collect::(); params.push(Value::from(q.as_str())); - from_fragments = format!(", to_tsquery('public.chinese_zh', ${}) AS query", params.len()); + from_fragments = format!(", plainto_tsquery('public.chinese_zh', ${}) AS query", params.len()); match query_req.query.q_scope.as_ref().unwrap_or(&SearchItemSearchQScopeKind::Title) { SearchItemSearchQScopeKind::Title => { select_fragments = ", COALESCE(ts_rank(title_tsv, query), 0::float4) AS rank_title, 0::float4 AS rank_content".to_string(); diff --git a/backend/supports/iam/src/basic/serv/iam_cert_ldap_serv.rs b/backend/supports/iam/src/basic/serv/iam_cert_ldap_serv.rs index f09968f27..62e8a853b 100644 --- a/backend/supports/iam/src/basic/serv/iam_cert_ldap_serv.rs +++ b/backend/supports/iam/src/basic/serv/iam_cert_ldap_serv.rs @@ -6,6 +6,7 @@ use super::{iam_account_serv::IamAccountServ, iam_cert_serv::IamCertServ, iam_te use crate::basic::dto::iam_account_dto::{IamAccountAddByLdapResp, IamAccountAggModifyReq, IamAccountExtSysAddReq, IamAccountExtSysBatchAddReq}; use crate::basic::dto::iam_cert_dto::IamCertMailVCodeAddReq; use crate::basic::dto::iam_cert_dto::{IamCertPhoneVCodeAddReq, IamThirdIntegrationConfigDto, IamThirdIntegrationSyncStatusDto}; +use crate::basic::dto::iam_filer_dto::IamAccountFilterReq; use crate::basic::serv::iam_cert_mail_vcode_serv::IamCertMailVCodeServ; use crate::basic::serv::iam_cert_user_pwd_serv::IamCertUserPwdServ; use crate::console_passport::dto::iam_cp_cert_dto::IamCpUserPwdBindWithLdapReq; @@ -804,6 +805,30 @@ impl IamCertLdapServ { ldap_id_to_account_map.remove(&local_ldap_id); continue; } + IamSearchClient::add_or_modify_account_search( + IamAccountServ::get_account_detail_aggs( + &cert.rel_rbum_id, + &IamAccountFilterReq { + basic: RbumBasicFilterReq { + ignore_scope: true, + own_paths: Some("".to_string()), + with_sub_own_paths: true, + ..Default::default() + }, + ..Default::default() + }, + true, + true, + &funs, + ctx, + ) + .await?, + Box::new(true), + "", + &funs, + ctx, + ) + .await?; } if !iam_account_ext_sys_resp.mobile.is_empty() { // 如果有手机号配置那么就更新手机号