Skip to content

Commit

Permalink
iam:add ci org api.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Jul 3, 2024
1 parent 1d8df44 commit 0dbc9be
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/supports/iam/src/console_interface/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
64 changes: 64 additions & 0 deletions backend/supports/iam/src/console_interface/api/iam_ci_org_api.rs
Original file line number Diff line number Diff line change
@@ -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<Option<String>>,
tenant_id: Query<Option<String>>,
mut ctx: TardisContextExtractor,
request: &Request,
) -> TardisApiResult<RbumSetTreeResp> {
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)
}
}
5 changes: 4 additions & 1 deletion backend/supports/iam/src/iam_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
)
Expand Down

0 comments on commit 0dbc9be

Please sign in to comment.