| 785 | } |
| 786 | |
| 787 | pub async fn set_initial_user_groups( |
| 788 | user_groups: &[InitUserGroupInput], |
| 789 | ) -> Result<(), ApiError> { |
| 790 | let add_user_groups = user_groups |
| 791 | .iter() |
| 792 | .map(|user_group| { |
| 793 | let input = AddUserGroupOperationInput { |
| 794 | name: user_group.name.clone(), |
| 795 | }; |
| 796 | |
| 797 | let user_group_id = user_group |
| 798 | .id |
| 799 | .as_ref() |
| 800 | .map(|id| HelperMapper::to_uuid(id.clone()).map(|uuid| *uuid.as_bytes())) |
| 801 | .transpose(); |
| 802 | |
| 803 | user_group_id.map(|user_group_id| (input, user_group_id)) |
| 804 | }) |
| 805 | .collect::<Result<Vec<_>, _>>()?; |
| 806 | |
| 807 | for (new_user_group, with_user_group_id) in add_user_groups { |
| 808 | USER_GROUP_SERVICE |
| 809 | .create_with_id(new_user_group, with_user_group_id) |
| 810 | .await?; |
| 811 | } |
| 812 | |
| 813 | Ok(()) |
| 814 | } |
| 815 | |
| 816 | pub fn set_initial_named_rules(named_rules: &[InitNamedRuleInput]) -> Result<(), ApiError> { |
| 817 | let mut add_named_rules = named_rules |