@@ -39,6 +39,7 @@ pub fn routes() -> Vec<Route> {
39
39
put_organization_collection_update,
40
40
delete_organization_collection,
41
41
post_organization_collection_delete,
42
+ bulk_delete_organization_collections,
42
43
get_org_details,
43
44
get_org_users,
44
45
send_invite,
@@ -81,6 +82,7 @@ pub fn routes() -> Vec<Route> {
81
82
get_group_details,
82
83
delete_group,
83
84
post_delete_group,
85
+ bulk_delete_groups,
84
86
get_group_users,
85
87
put_group_users,
86
88
get_user_groups,
@@ -537,35 +539,44 @@ async fn post_organization_collection_delete_user(
537
539
delete_organization_collection_user ( org_id, col_id, org_user_id, headers, conn) . await
538
540
}
539
541
540
- #[ delete( "/organizations/<org_id>/collections/<col_id>" ) ]
541
- async fn delete_organization_collection (
542
- org_id : String ,
543
- col_id : String ,
544
- headers : ManagerHeaders ,
545
- mut conn : DbConn ,
542
+ async fn _delete_organization_collection (
543
+ org_id : & str ,
544
+ col_id : & str ,
545
+ headers : & ManagerHeaders ,
546
+ conn : & mut DbConn ,
546
547
) -> EmptyResult {
547
- match Collection :: find_by_uuid ( & col_id, & mut conn) . await {
548
+ match Collection :: find_by_uuid ( col_id, conn) . await {
548
549
None => err ! ( "Collection not found" ) ,
549
550
Some ( collection) => {
550
551
if collection. org_uuid == org_id {
551
552
log_event (
552
553
EventType :: CollectionDeleted as i32 ,
553
554
& collection. uuid ,
554
- org_id,
555
+ org_id. to_string ( ) ,
555
556
headers. user . uuid . clone ( ) ,
556
557
headers. device . atype ,
557
558
& headers. ip . ip ,
558
- & mut conn,
559
+ conn,
559
560
)
560
561
. await ;
561
- collection. delete ( & mut conn) . await
562
+ collection. delete ( conn) . await
562
563
} else {
563
564
err ! ( "Collection and Organization id do not match" )
564
565
}
565
566
}
566
567
}
567
568
}
568
569
570
+ #[ delete( "/organizations/<org_id>/collections/<col_id>" ) ]
571
+ async fn delete_organization_collection (
572
+ org_id : String ,
573
+ col_id : String ,
574
+ headers : ManagerHeaders ,
575
+ mut conn : DbConn ,
576
+ ) -> EmptyResult {
577
+ _delete_organization_collection ( & org_id, & col_id, & headers, & mut conn) . await
578
+ }
579
+
569
580
#[ derive( Deserialize , Debug ) ]
570
581
#[ allow( non_snake_case, dead_code) ]
571
582
struct DeleteCollectionData {
@@ -579,9 +590,38 @@ async fn post_organization_collection_delete(
579
590
col_id : String ,
580
591
headers : ManagerHeaders ,
581
592
_data : JsonUpcase < DeleteCollectionData > ,
582
- conn : DbConn ,
593
+ mut conn : DbConn ,
583
594
) -> EmptyResult {
584
- delete_organization_collection ( org_id, col_id, headers, conn) . await
595
+ _delete_organization_collection ( & org_id, & col_id, & headers, & mut conn) . await
596
+ }
597
+
598
+ #[ derive( Deserialize , Debug ) ]
599
+ #[ allow( non_snake_case) ]
600
+ struct BulkCollectionIds {
601
+ Ids : Vec < String > ,
602
+ OrganizationId : String ,
603
+ }
604
+
605
+ #[ delete( "/organizations/<org_id>/collections" , data = "<data>" ) ]
606
+ async fn bulk_delete_organization_collections (
607
+ org_id : & str ,
608
+ headers : ManagerHeadersLoose ,
609
+ data : JsonUpcase < BulkCollectionIds > ,
610
+ mut conn : DbConn ,
611
+ ) -> EmptyResult {
612
+ let data: BulkCollectionIds = data. into_inner ( ) . data ;
613
+ if org_id != data. OrganizationId {
614
+ err ! ( "OrganizationId mismatch" ) ;
615
+ }
616
+
617
+ let collections = data. Ids ;
618
+
619
+ let headers = ManagerHeaders :: from_loose ( headers, & collections, & mut conn) . await ?;
620
+
621
+ for col_id in collections {
622
+ _delete_organization_collection ( org_id, & col_id, & headers, & mut conn) . await ?
623
+ }
624
+ Ok ( ( ) )
585
625
}
586
626
587
627
#[ get( "/organizations/<org_id>/collections/<coll_id>/details" ) ]
@@ -2363,17 +2403,21 @@ async fn get_group_details(_org_id: String, group_id: String, _headers: AdminHea
2363
2403
}
2364
2404
2365
2405
#[ post( "/organizations/<org_id>/groups/<group_id>/delete" ) ]
2366
- async fn post_delete_group ( org_id : String , group_id : String , headers : AdminHeaders , conn : DbConn ) -> EmptyResult {
2367
- delete_group ( org_id, group_id, headers, conn) . await
2406
+ async fn post_delete_group ( org_id : String , group_id : String , headers : AdminHeaders , mut conn : DbConn ) -> EmptyResult {
2407
+ _delete_group ( org_id, group_id, & headers, & mut conn) . await
2368
2408
}
2369
2409
2370
2410
#[ delete( "/organizations/<org_id>/groups/<group_id>" ) ]
2371
2411
async fn delete_group ( org_id : String , group_id : String , headers : AdminHeaders , mut conn : DbConn ) -> EmptyResult {
2412
+ _delete_group ( org_id, group_id, & headers, & mut conn) . await
2413
+ }
2414
+
2415
+ async fn _delete_group ( org_id : String , group_id : String , headers : & AdminHeaders , conn : & mut DbConn ) -> EmptyResult {
2372
2416
if !CONFIG . org_groups_enabled ( ) {
2373
2417
err ! ( "Group support is disabled" ) ;
2374
2418
}
2375
2419
2376
- let group = match Group :: find_by_uuid ( & group_id, & mut conn) . await {
2420
+ let group = match Group :: find_by_uuid ( & group_id, conn) . await {
2377
2421
Some ( group) => group,
2378
2422
_ => err ! ( "Group not found" ) ,
2379
2423
} ;
@@ -2385,11 +2429,30 @@ async fn delete_group(org_id: String, group_id: String, headers: AdminHeaders, m
2385
2429
headers. user . uuid . clone ( ) ,
2386
2430
headers. device . atype ,
2387
2431
& headers. ip . ip ,
2388
- & mut conn,
2432
+ conn,
2389
2433
)
2390
2434
. await ;
2391
2435
2392
- group. delete ( & mut conn) . await
2436
+ group. delete ( conn) . await
2437
+ }
2438
+
2439
+ #[ delete( "/organizations/<org_id>/groups" , data = "<data>" ) ]
2440
+ async fn bulk_delete_groups (
2441
+ org_id : String ,
2442
+ data : JsonUpcase < OrgBulkIds > ,
2443
+ headers : AdminHeaders ,
2444
+ mut conn : DbConn ,
2445
+ ) -> EmptyResult {
2446
+ if !CONFIG . org_groups_enabled ( ) {
2447
+ err ! ( "Group support is disabled" ) ;
2448
+ }
2449
+
2450
+ let data: OrgBulkIds = data. into_inner ( ) . data ;
2451
+
2452
+ for group_id in data. Ids {
2453
+ _delete_group ( org_id. clone ( ) , group_id, & headers, & mut conn) . await ?
2454
+ }
2455
+ Ok ( ( ) )
2393
2456
}
2394
2457
2395
2458
#[ get( "/organizations/<_org_id>/groups/<group_id>" ) ]
0 commit comments