@@ -2511,6 +2511,10 @@ def apply_patch(self, item):
2511
2511
self .opencti .notification .update_field (
2512
2512
id = item_id , input = field_patch_without_files
2513
2513
)
2514
+ elif item ["type" ] == "user" :
2515
+ self .opencti .user .update_field (
2516
+ id = item_id , input = field_patch_without_files
2517
+ )
2514
2518
else :
2515
2519
self .opencti .stix_domain_object .update_field (
2516
2520
id = item_id , input = field_patch_without_files
@@ -2583,6 +2587,62 @@ def organization_unshare(self, item):
2583
2587
item ["id" ], organization_ids , sharing_direct_container
2584
2588
)
2585
2589
2590
+ def element_add_organizations (self , item ):
2591
+ organization_ids = self .opencti .get_attribute_in_extension (
2592
+ "organization_ids" , item
2593
+ )
2594
+ if organization_ids is None :
2595
+ organization_ids = item ["organization_ids" ]
2596
+ if item ["type" ] == "user" :
2597
+ for organization_id in organization_ids :
2598
+ self .opencti .user .add_organization (id = item ["id" ], organization_id = organization_id )
2599
+ else :
2600
+ raise ValueError (
2601
+ "Add organizations operation not compatible with type" , {"type" : item ["type" ]}
2602
+ )
2603
+
2604
+ def element_remove_organizations (self , item ):
2605
+ organization_ids = self .opencti .get_attribute_in_extension (
2606
+ "organization_ids" , item
2607
+ )
2608
+ if organization_ids is None :
2609
+ organization_ids = item ["organization_ids" ]
2610
+ if item ["type" ] == "user" :
2611
+ for organization_id in organization_ids :
2612
+ self .opencti .user .delete_organization (id = item ["id" ], organization_id = organization_id )
2613
+ else :
2614
+ raise ValueError (
2615
+ "Remove organizations operation not compatible with type" , {"type" : item ["type" ]}
2616
+ )
2617
+
2618
+ def element_add_groups (self , item ):
2619
+ group_ids = self .opencti .get_attribute_in_extension (
2620
+ "group_ids" , item
2621
+ )
2622
+ if group_ids is None :
2623
+ group_ids = item ["group_ids" ]
2624
+ if item ["type" ] == "user" :
2625
+ for group_id in group_ids :
2626
+ self .opencti .user .add_membership (id = item ["id" ], group_id = group_id )
2627
+ else :
2628
+ raise ValueError (
2629
+ "Add groups operation not compatible with type" , {"type" : item ["type" ]}
2630
+ )
2631
+
2632
+ def element_remove_groups (self , item ):
2633
+ group_ids = self .opencti .get_attribute_in_extension (
2634
+ "group_ids" , item
2635
+ )
2636
+ if group_ids is None :
2637
+ group_ids = item ["group_ids" ]
2638
+ if item ["type" ] == "user" :
2639
+ for group_id in group_ids :
2640
+ self .opencti .user .delete_membership (id = item ["id" ], group_id = group_id )
2641
+ else :
2642
+ raise ValueError (
2643
+ "Remove groups operation not compatible with type" , {"type" : item ["type" ]}
2644
+ )
2645
+
2586
2646
def element_operation_delete (self , item , operation ):
2587
2647
# If data is stix, just use the generic stix function for deletion
2588
2648
force_delete = operation == "delete_force"
@@ -2666,25 +2726,13 @@ def apply_opencti_operation(self, item, operation):
2666
2726
element_id = item ["id" ], connector_ids = connector_ids
2667
2727
)
2668
2728
elif operation == "add_organizations" :
2669
- raise ValueError (
2670
- "Not implemented opencti_operation" ,
2671
- {"operation" : operation },
2672
- )
2729
+ self .element_add_organizations (item )
2673
2730
elif operation == "remove_organizations" :
2674
- raise ValueError (
2675
- "Not implemented opencti_operation" ,
2676
- {"operation" : operation },
2677
- )
2731
+ self .element_remove_organizations (item )
2678
2732
elif operation == "add_groups" :
2679
- raise ValueError (
2680
- "Not implemented opencti_operation" ,
2681
- {"operation" : operation },
2682
- )
2733
+ self .element_add_groups (item )
2683
2734
elif operation == "remove_groups" :
2684
- raise ValueError (
2685
- "Not implemented opencti_operation" ,
2686
- {"operation" : operation },
2687
- )
2735
+ self .element_remove_groups (item )
2688
2736
else :
2689
2737
raise ValueError (
2690
2738
"Not supported opencti_operation" ,
0 commit comments