Skip to content

Commit

Permalink
iam:fix res.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Dec 5, 2023
1 parent 6e4f01d commit e5a2659
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 7 additions & 0 deletions support/iam/src/basic/dto/iam_res_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,10 @@ pub struct MenuItem {
pub name: String,
pub kind: String,
}


#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct IamResAppReq {
pub app_ids: Vec<String>,
pub res_codes: Vec<String>,
}
8 changes: 7 additions & 1 deletion support/iam/src/basic/serv/iam_res_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,12 @@ impl IamResServ {
Ok(res_id)
}

pub async fn get_res_by_app(app_ids: Vec<String>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<HashMap<String, Vec<IamResSummaryResp>>> {
pub async fn get_res_by_app_code(
app_ids: Vec<String>,
res_code: Option<Vec<String>>,
funs: &TardisFunsInst,
ctx: &TardisContext,
) -> TardisResult<HashMap<String, Vec<IamResSummaryResp>>> {
let raw_roles = IamAccountServ::find_simple_rel_roles(&ctx.owner, true, Some(true), None, funs, ctx).await?;
let mut roles: Vec<RbumRelBoneResp> = vec![];
let mut result = HashMap::new();
Expand Down Expand Up @@ -528,6 +533,7 @@ impl IamResServ {
basic: RbumBasicFilterReq {
with_sub_own_paths: true,
ids: Some(res_ids.into_iter().collect()),
codes: res_code.clone(),
..Default::default()
},
..Default::default()
Expand Down
15 changes: 13 additions & 2 deletions support/iam/src/console_common/api/iam_cc_res_api.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::collections::HashMap;

use crate::basic::dto::iam_res_dto::IamResSummaryResp;
use crate::basic::dto::iam_res_dto::{IamResAppReq, IamResSummaryResp};
use crate::basic::serv::iam_res_serv::IamResServ;
use crate::basic::serv::iam_set_serv::IamSetServ;
use crate::iam_constants;
use crate::iam_enumeration::IamSetKind;
use bios_basic::helper::request_helper::add_remote_ip;
use bios_basic::rbum::dto::rbum_set_dto::RbumSetTreeResp;
use tardis::web::context_extractor::TardisContextExtractor;
use tardis::web::poem::web::Json;
use tardis::web::poem::Request;
use tardis::web::poem_openapi;
use tardis::web::poem_openapi::param::Query;
Expand Down Expand Up @@ -37,7 +38,17 @@ impl IamCcResApi {
add_remote_ip(request, &ctx.0).await?;
let funs = iam_constants::get_tardis_inst();
let ids = app_ids.0.split(',').map(|s| s.to_string()).collect();
let result = IamResServ::get_res_by_app(ids, &funs, &ctx.0).await?;
let result = IamResServ::get_res_by_app_code(ids, None, &funs, &ctx.0).await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}

/// Find res by apps and code
#[oai(path = "/res", method = "put")]
async fn get_res_by_app_code(&self, res_req: Json<IamResAppReq>, ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<HashMap<String, Vec<IamResSummaryResp>>> {
add_remote_ip(request, &ctx.0).await?;
let funs = iam_constants::get_tardis_inst();
let result = IamResServ::get_res_by_app_code(res_req.0.app_ids, Some(res_req.0.res_codes), &funs, &ctx.0).await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}
Expand Down

0 comments on commit e5a2659

Please sign in to comment.