Skip to content

Commit

Permalink
fix compile error (#792)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ZzIsGod1019 and LiJieLong authored Jul 1, 2024
1 parent d62d5e6 commit ce7549a
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 26 deletions.
2 changes: 1 addition & 1 deletion backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
31 changes: 30 additions & 1 deletion backend/middlewares/flow/src/api/ct/flow_ct_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<FlowModelFindRelNameByTemplateIdsReq>,
mut ctx: TardisContextExtractor,
request: &Request,
) -> TardisApiResult<HashMap<String, Vec<String>>> {
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)
}
}
9 changes: 8 additions & 1 deletion backend/middlewares/flow/src/dto/flow_model_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct FlowModelModifyReq {
pub name: Option<TrimString>,
#[oai(validator(min_length = "2", max_length = "2000"))]
pub icon: Option<String>,
#[oai(validator(min_length = "2", max_length = "2000"))]
#[oai(validator(max_length = "2000"))]
pub info: Option<String>,
/// 初始化状态ID
pub init_state_id: Option<String>,
Expand Down Expand Up @@ -354,3 +354,10 @@ pub struct FlowModelExistRelByTemplateIdsReq {
/// 关联的模板ID
pub rel_template_ids: Vec<String>,
}

/// 获取关联的模型名请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct FlowModelFindRelNameByTemplateIdsReq {
/// 关联的模板ID
pub rel_template_ids: Vec<String>,
}
30 changes: 15 additions & 15 deletions backend/middlewares/flow/src/serv/clients/search_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ impl IamSearchClient {
// flow model 全局搜索埋点方法
pub async fn add_or_modify_model_search(model_resp: &FlowModelDetailResp, is_modify: Box<bool>, 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 {
Expand All @@ -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!({
Expand All @@ -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,
}),
Expand Down Expand Up @@ -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!({
Expand All @@ -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,
}),
Expand Down
1 change: 1 addition & 0 deletions backend/spi/spi-plugin/src/api/ci/plugin_ci_exec_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl PluginExecApi {
body: Some(tardis::serde_json::Value::String(msg.0)),
query: None,
header: None,
percent_encode: None,
})
}
}
1 change: 1 addition & 0 deletions backend/spi/spi-plugin/tests/test_plugin_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub async fn test(client: &mut TestHttpClient) -> TardisResult<()> {
)])),
body: Some(json!({ "msg": "object" })),
query: None,
percent_encode: None,
},
)
.await;
Expand Down
23 changes: 15 additions & 8 deletions backend/spi/spi-search/src/serv/pg/search_pg_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,30 @@ pub async fn search(search_req: &mut SearchItemSearchReq, funs: &TardisFunsInst,
})
.collect::<String>();
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 ${})",
Expand Down Expand Up @@ -794,7 +801,7 @@ pub async fn query_metrics(query_req: &SearchQueryMetricsReq, funs: &TardisFunsI
})
.collect::<String>();
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();
Expand Down
25 changes: 25 additions & 0 deletions backend/supports/iam/src/basic/serv/iam_cert_ldap_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
// 如果有手机号配置那么就更新手机号
Expand Down

0 comments on commit ce7549a

Please sign in to comment.