From 0dbc9be215966c08383007002e1978279460ccc3 Mon Sep 17 00:00:00 2001 From: ljl <17743125563@163.com> Date: Wed, 3 Jul 2024 15:01:56 +0800 Subject: [PATCH] iam:add ci org api. --- .../supports/iam/src/console_interface/api.rs | 1 + .../console_interface/api/iam_ci_org_api.rs | 64 +++++++++++++++++++ backend/supports/iam/src/iam_initializer.rs | 5 +- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 backend/supports/iam/src/console_interface/api/iam_ci_org_api.rs diff --git a/backend/supports/iam/src/console_interface/api.rs b/backend/supports/iam/src/console_interface/api.rs index bb31f4356..2429398f7 100644 --- a/backend/supports/iam/src/console_interface/api.rs +++ b/backend/supports/iam/src/console_interface/api.rs @@ -3,6 +3,7 @@ pub mod iam_ci_app_api; pub mod iam_ci_app_set_api; pub mod iam_ci_cert_api; pub mod iam_ci_open_api; +pub mod iam_ci_org_api; pub mod iam_ci_res_api; pub mod iam_ci_role_api; pub mod iam_ci_system_api; diff --git a/backend/supports/iam/src/console_interface/api/iam_ci_org_api.rs b/backend/supports/iam/src/console_interface/api/iam_ci_org_api.rs new file mode 100644 index 000000000..e91152f41 --- /dev/null +++ b/backend/supports/iam/src/console_interface/api/iam_ci_org_api.rs @@ -0,0 +1,64 @@ +use crate::basic::serv::iam_cert_serv::IamCertServ; +use crate::basic::serv::iam_set_serv::IamSetServ; +use crate::iam_constants; +use bios_basic::helper::request_helper::try_set_real_ip_from_req_to_ctx; +use bios_basic::rbum::dto::rbum_filer_dto::RbumSetTreeFilterReq; +use bios_basic::rbum::dto::rbum_set_dto::RbumSetTreeResp; +use bios_basic::rbum::helper::rbum_scope_helper::check_without_owner_and_unsafe_fill_ctx; +use bios_basic::rbum::rbum_enumeration::RbumSetCateLevelQueryKind; +use tardis::web::context_extractor::TardisContextExtractor; +use tardis::web::poem::Request; +use tardis::web::poem_openapi; +use tardis::web::poem_openapi::param::Query; +use tardis::web::web_resp::{TardisApiResult, TardisResp}; + +#[derive(Clone, Default)] +pub struct IamCiOrgApi; + +/// Interface Console Org API +/// 接口控制台组织API +#[poem_openapi::OpenApi(prefix_path = "/ci/org", tag = "bios_basic::ApiTag::Interface")] +impl IamCiOrgApi { + /// Find Org Tree By Current Tenant + /// 查找组织树 + /// + /// * Without parameters: Query the whole tree + /// * ``parent_sys_code=true`` : query only the next level. This can be used to query level by level when the tree is too large + /// * 无参数:查询整个树 + /// * ``parent_sys_code=true``:仅查询下一级,当树太大时可以用来逐级查询 + #[oai(path = "/tree", method = "get")] + async fn get_tree( + &self, + parent_sys_code: Query>, + tenant_id: Query>, + mut ctx: TardisContextExtractor, + request: &Request, + ) -> TardisApiResult { + let funs = iam_constants::get_tardis_inst(); + check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?; + try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?; + let ctx = IamCertServ::try_use_tenant_ctx(ctx.0, tenant_id.0)?; + let code = if ctx.own_paths.is_empty() { + IamSetServ::get_default_org_code_by_system() + } else { + IamSetServ::get_default_org_code_by_tenant(&funs, &ctx)? + }; + let set_id = IamSetServ::get_set_id_by_code(&code, true, &funs, &ctx).await?; + let result = IamSetServ::get_tree( + &set_id, + &mut RbumSetTreeFilterReq { + fetch_cate_item: true, + hide_item_with_disabled: true, + sys_codes: parent_sys_code.0.map(|parent_sys_code| vec![parent_sys_code]), + sys_code_query_kind: Some(RbumSetCateLevelQueryKind::CurrentAndSub), + sys_code_query_depth: Some(1), + ..Default::default() + }, + &funs, + &ctx, + ) + .await?; + ctx.execute_task().await?; + TardisResp::ok(result) + } +} diff --git a/backend/supports/iam/src/iam_initializer.rs b/backend/supports/iam/src/iam_initializer.rs index 6e2da364e..d69448857 100644 --- a/backend/supports/iam/src/iam_initializer.rs +++ b/backend/supports/iam/src/iam_initializer.rs @@ -40,7 +40,9 @@ use crate::console_common::api::{ iam_cc_account_api, iam_cc_account_task_api, iam_cc_app_api, iam_cc_app_set_api, iam_cc_config_api, iam_cc_org_api, iam_cc_org_task_api, iam_cc_res_api, iam_cc_role_api, iam_cc_system_api, iam_cc_tenant_api, }; -use crate::console_interface::api::{iam_ci_account_api, iam_ci_app_api, iam_ci_app_set_api, iam_ci_cert_api, iam_ci_open_api, iam_ci_res_api, iam_ci_role_api, iam_ci_system_api}; +use crate::console_interface::api::{ + iam_ci_account_api, iam_ci_app_api, iam_ci_app_set_api, iam_ci_cert_api, iam_ci_open_api, iam_ci_org_api, iam_ci_res_api, iam_ci_role_api, iam_ci_system_api, +}; use crate::console_passport::api::{iam_cp_account_api, iam_cp_app_api, iam_cp_cert_api, iam_cp_tenant_api}; use crate::console_system::api::{ iam_cs_account_api, iam_cs_account_attr_api, iam_cs_cert_api, iam_cs_org_api, iam_cs_platform_api, iam_cs_res_api, iam_cs_role_api, iam_cs_spi_data_api, iam_cs_tenant_api, @@ -132,6 +134,7 @@ async fn init_api(web_server: &TardisWebServer) -> TardisResult<()> { iam_ci_account_api::IamCiAccountApi, iam_ci_system_api::IamCiSystemApi, iam_ci_open_api::IamCiOpenApi, + iam_ci_org_api::IamCiOrgApi, ), )), // .middlewares(EncryptMW), )