bios_iam/console_interface/api/
iam_ci_org_api.rs

1use crate::basic::serv::iam_cert_serv::IamCertServ;
2use crate::basic::serv::iam_set_serv::IamSetServ;
3use crate::iam_constants;
4use bios_basic::helper::request_helper::try_set_real_ip_from_req_to_ctx;
5use bios_basic::rbum::dto::rbum_filer_dto::RbumSetTreeFilterReq;
6use bios_basic::rbum::dto::rbum_set_dto::RbumSetTreeResp;
7use bios_basic::rbum::helper::rbum_scope_helper::check_without_owner_and_unsafe_fill_ctx;
8use bios_basic::rbum::rbum_enumeration::RbumSetCateLevelQueryKind;
9use tardis::web::context_extractor::TardisContextExtractor;
10use tardis::web::poem::Request;
11use tardis::web::poem_openapi;
12use tardis::web::poem_openapi::param::Query;
13use tardis::web::web_resp::{TardisApiResult, TardisResp};
14
15#[derive(Clone, Default)]
16pub struct IamCiOrgApi;
17
18/// Interface Console Org API
19/// 接口控制台组织API
20#[poem_openapi::OpenApi(prefix_path = "/ci/org", tag = "bios_basic::ApiTag::Interface")]
21impl IamCiOrgApi {
22    /// Find Org Tree By Current Tenant
23    /// 查找组织树
24    ///
25    /// * Without parameters: Query the whole tree
26    /// * ``parent_sys_code=true`` : query only the next level. This can be used to query level by level when the tree is too large
27    /// * 无参数:查询整个树
28    /// * ``parent_sys_code=true``:仅查询下一级,当树太大时可以用来逐级查询
29    #[oai(path = "/tree", method = "get")]
30    async fn get_tree(
31        &self,
32        parent_sys_code: Query<Option<String>>,
33        tenant_id: Query<Option<String>>,
34        mut ctx: TardisContextExtractor,
35        request: &Request,
36    ) -> TardisApiResult<RbumSetTreeResp> {
37        let funs = iam_constants::get_tardis_inst();
38        check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
39        try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
40        let ctx = IamCertServ::try_use_tenant_ctx(ctx.0, tenant_id.0)?;
41        let code = if ctx.own_paths.is_empty() {
42            IamSetServ::get_default_org_code_by_system()
43        } else {
44            IamSetServ::get_default_org_code_by_tenant(&funs, &ctx)?
45        };
46        let set_id = IamSetServ::get_set_id_by_code(&code, true, &funs, &ctx).await?;
47        let result = IamSetServ::get_tree(
48            &set_id,
49            &mut RbumSetTreeFilterReq {
50                fetch_cate_item: true,
51                hide_item_with_disabled: true,
52                sys_codes: parent_sys_code.0.map(|parent_sys_code| vec![parent_sys_code]),
53                sys_code_query_kind: Some(RbumSetCateLevelQueryKind::CurrentAndSub),
54                sys_code_query_depth: Some(1),
55                ..Default::default()
56            },
57            &funs,
58            &ctx,
59        )
60        .await?;
61        ctx.execute_task().await?;
62        TardisResp::ok(result)
63    }
64}