1
1
use std:: ops:: Add ;
2
2
3
3
use async_trait:: async_trait;
4
- use bios_basic:: helper:: request_helper:: get_remote_ip;
5
- use bios_basic:: process:: task_processor:: TaskProcessor ;
4
+ use tardis:: { TardisFuns , TardisFunsInst } ;
6
5
use tardis:: basic:: dto:: TardisContext ;
7
6
use tardis:: basic:: field:: TrimString ;
8
7
use tardis:: basic:: result:: TardisResult ;
9
- use tardis:: db:: sea_orm:: sea_query:: { Expr , SelectStatement } ;
10
- use tardis:: db:: sea_orm:: EntityName ;
11
8
use tardis:: db:: sea_orm:: * ;
9
+ use tardis:: db:: sea_orm:: prelude:: Expr ;
10
+ use tardis:: db:: sea_orm:: sea_query:: SelectStatement ;
12
11
use tardis:: log:: info;
13
12
use tardis:: web:: web_resp:: TardisPage ;
14
- use tardis:: { TardisFuns , TardisFunsInst } ;
15
13
14
+ use bios_basic:: helper:: request_helper:: get_remote_ip;
15
+ use bios_basic:: process:: task_processor:: TaskProcessor ;
16
16
use bios_basic:: rbum:: dto:: rbum_filer_dto:: { RbumBasicFilterReq , RbumRelFilterReq } ;
17
17
use bios_basic:: rbum:: dto:: rbum_item_dto:: { RbumItemKernelAddReq , RbumItemKernelModifyReq } ;
18
18
use bios_basic:: rbum:: dto:: rbum_rel_dto:: { RbumRelBoneResp , RbumRelCheckReq } ;
@@ -23,9 +23,10 @@ use bios_basic::rbum::serv::rbum_item_serv::RbumItemCrudOperation;
23
23
use bios_basic:: rbum:: serv:: rbum_rel_serv:: RbumRelServ ;
24
24
25
25
use crate :: basic:: domain:: iam_role;
26
- use crate :: basic:: dto:: iam_filer_dto:: IamRoleFilterReq ;
26
+ use crate :: basic:: dto:: iam_filer_dto:: { IamAppFilterReq , IamRoleFilterReq } ;
27
27
use crate :: basic:: dto:: iam_role_dto:: { IamRoleAddReq , IamRoleAggAddReq , IamRoleAggModifyReq , IamRoleDetailResp , IamRoleModifyReq , IamRoleSummaryResp } ;
28
28
use crate :: basic:: serv:: iam_account_serv:: IamAccountServ ;
29
+ use crate :: basic:: serv:: iam_app_serv:: IamAppServ ;
29
30
use crate :: basic:: serv:: iam_key_cache_serv:: IamIdentCacheServ ;
30
31
use crate :: basic:: serv:: iam_rel_serv:: IamRelServ ;
31
32
use crate :: iam_config:: { IamBasicConfigApi , IamBasicInfoManager , IamConfig } ;
@@ -240,6 +241,13 @@ impl RbumItemCrudOperation<iam_role::ActiveModel, IamRoleAddReq, IamRoleModifyRe
240
241
{
241
242
return Err ( funs. err ( ) . conflict ( & Self :: get_obj_name ( ) , "delete" , "role is not private" , "409-iam-delete-role-conflict" ) ) ;
242
243
}
244
+ let sub_role = Self :: find_id_items ( & IamRoleFilterReq {
245
+ extend_role_id : Some ( id. to_string ( ) ) ,
246
+ ..Default :: default ( )
247
+ } , None , None , funs, ctx) . await ?;
248
+ for role_id in sub_role {
249
+ Self :: delete_item_with_all_rels ( & role_id, funs, ctx) . await ?;
250
+ }
243
251
Ok ( None )
244
252
}
245
253
@@ -341,6 +349,7 @@ impl IamRoleServ {
341
349
} ,
342
350
kind : Some ( kind. clone ( ) ) ,
343
351
in_embed : Some ( true ) ,
352
+ in_base : Some ( true ) ,
344
353
..Default :: default ( )
345
354
} ,
346
355
None ,
@@ -374,6 +383,50 @@ impl IamRoleServ {
374
383
Ok ( ( ) )
375
384
}
376
385
386
+ pub async fn add_app_copy_role_agg ( app_id : & str , funs : & TardisFunsInst , ctx : & TardisContext ) -> TardisResult < ( ) > {
387
+ Self :: copy_role_agg ( app_id, & IamRoleKind :: App , funs, ctx) . await ?;
388
+ let tenant_app_roles = Self :: find_detail_items (
389
+ & IamRoleFilterReq {
390
+ basic : RbumBasicFilterReq {
391
+ with_sub_own_paths : true ,
392
+ ..Default :: default ( )
393
+ } ,
394
+ kind : Some ( IamRoleKind :: App ) ,
395
+ in_embed : Some ( false ) ,
396
+ in_base : Some ( false ) ,
397
+ ..Default :: default ( )
398
+ } ,
399
+ None ,
400
+ None ,
401
+ funs,
402
+ ctx,
403
+ )
404
+ . await ?;
405
+ for app_role in tenant_app_roles {
406
+ Self :: add_role_agg (
407
+ & mut IamRoleAggAddReq {
408
+ role : IamRoleAddReq {
409
+ code : Some ( TrimString :: from ( format ! ( "{}:{}" , app_id, app_role. code) ) ) ,
410
+ name : TrimString :: from ( app_role. name ) ,
411
+ icon : Some ( app_role. icon ) ,
412
+ sort : Some ( app_role. sort ) ,
413
+ kind : Some ( app_role. kind ) ,
414
+ scope_level : Some ( RbumScopeLevelKind :: Private ) ,
415
+ in_embed : Some ( app_role. in_embed ) ,
416
+ extend_role_id : Some ( app_role. id ) ,
417
+ disabled : Some ( app_role. disabled ) ,
418
+ in_base : Some ( false ) ,
419
+ } ,
420
+ res_ids : None ,
421
+ } ,
422
+ funs,
423
+ ctx,
424
+ )
425
+ . await ?;
426
+ }
427
+ Ok ( ( ) )
428
+ }
429
+
377
430
pub async fn get_embed_subrole_id ( extend_role_id : & str , funs : & TardisFunsInst , ctx : & TardisContext ) -> TardisResult < String > {
378
431
let scope_level = get_scope_level_by_context ( ctx) ?;
379
432
info ! (
@@ -398,6 +451,49 @@ impl IamRoleServ {
398
451
Err ( funs. err ( ) . not_found ( & Self :: get_obj_name ( ) , "get_embed_subrole_id" , "role not found" , "404-iam-role-not-found" ) )
399
452
}
400
453
454
+ /// 租户添加应用角色
455
+ pub async fn tenant_add_app_role_agg ( add_req : & mut IamRoleAggAddReq , funs : & TardisFunsInst , ctx : & TardisContext ) -> TardisResult < String > {
456
+ add_req. role . scope_level = Some ( RbumScopeLevelKind :: Private ) ;
457
+ let app_role_id = Self :: add_role_agg ( add_req, funs, ctx) . await ?;
458
+ let app_ids = IamAppServ :: find_id_items ( & IamAppFilterReq {
459
+ basic : RbumBasicFilterReq {
460
+ with_sub_own_paths : true ,
461
+ ..Default :: default ( )
462
+ } ,
463
+ ..Default :: default ( )
464
+ } , None , None , funs, ctx) . await ?;
465
+ let app_role = Self :: get_item ( & app_role_id, & IamRoleFilterReq {
466
+ basic : RbumBasicFilterReq {
467
+ with_sub_own_paths : true ,
468
+ ..Default :: default ( )
469
+ } ,
470
+ ..Default :: default ( )
471
+ } , funs, ctx) . await ?;
472
+ for app_id in app_ids {
473
+ Self :: add_role_agg (
474
+ & mut IamRoleAggAddReq {
475
+ role : IamRoleAddReq {
476
+ code : Some ( TrimString :: from ( format ! ( "{}:{}" , app_id, app_role. code) ) ) ,
477
+ name : TrimString :: from ( app_role. name . clone ( ) ) ,
478
+ icon : Some ( app_role. icon . clone ( ) ) ,
479
+ sort : Some ( app_role. sort ) ,
480
+ kind : Some ( app_role. kind . clone ( ) ) ,
481
+ scope_level : Some ( RbumScopeLevelKind :: Private ) ,
482
+ in_embed : Some ( app_role. in_embed ) ,
483
+ extend_role_id : Some ( app_role_id. clone ( ) ) ,
484
+ disabled : Some ( app_role. disabled ) ,
485
+ in_base : Some ( false ) ,
486
+ } ,
487
+ res_ids : None ,
488
+ } ,
489
+ funs,
490
+ ctx,
491
+ )
492
+ . await ?;
493
+ }
494
+ Ok ( app_role_id)
495
+ }
496
+
401
497
pub async fn add_role_agg ( add_req : & mut IamRoleAggAddReq , funs : & TardisFunsInst , ctx : & TardisContext ) -> TardisResult < String > {
402
498
let role_id = Self :: add_item ( & mut add_req. role , funs, ctx) . await ?;
403
499
if let Some ( res_ids) = & add_req. res_ids {
0 commit comments