Forum Discussion

Marco's avatar
Marco
Contributor II
10 months ago

how can I add a group to a user and remove it in a BR?

I would like you to help me with this question, because I want to know how I can add a security group to a person (the section that appears in the image) and how I can remove that group in a BR.

ā€ƒ

 

  • JIC, here's the VB:

    Dim updateParentGroupsTrue As Boolean = True
    
    Dim userInfo As UserInfo = BRApi.Security.Admin.GetUser(si, username)
    Dim parentGroups As List(Of Guid) = userInfo.ParentGroups.Keys.ToList()
    Dim user As User = userInfo.User
    
    Dim groupInfo As GroupInfo = BRApi.Security.Admin.GetGroup(si, groupName)
    Dim addedParentGroupGuid As Guid = groupInfo.Group.UniqueID
    parentGroups.Add(addedParentGroupGuid)
    
    BRApi.Security.Admin.SaveUser(si, user, updateParentGroupsTrue, parentGroups, False)
    
    'Remove a group
    Dim updateParentGroupsTrue As Boolean = True
    Dim userInfo As UserInfo = BRApi.Security.Admin.GetUser(si, username)
    Dim user As User = userInfo.User
    
    Dim parentGroups As List(Of Guid) = userInfo.ParentGroups.Keys.ToList()
    Dim groupInfo As GroupInfo = BRApi.Security.Admin.GetGroup(si, "Development")
    Dim parentGroupToDeleteGuid As Guid = groupInfo.Group.UniqueID
    
    If parentGroups.Contains(parentGroupToDeleteGuid) Then
        parentGroups.Remove(parentGroupToDeleteGuid)
        BRApi.Security.Admin.SaveUser(si, user, updateParentGroupsTrue, parentGroups, False)
    End If
    

     

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    Add a user to a group:

    bool updateParentGroupsTrue = true;
    UserInfo userInfo = BRApi.Security.Admin.GetUser(si, username);
    User user = userInfo.User;
    List<Guid> parentGroups = userInfo.ParentGroups.Keys.ToList();
    
    GroupInfo groupInfo = BRApi.Security.Admin.GetGroup(si, groupName);				
    Guid addedParentGroupGuid = groupInfo.Group.UniqueID;
    
    parentGroups.Add(addedParentGroupGuid);
    BRApi.Security.Admin.SaveUser(si, user, updateParentGroupsTrue, parentGroups, false);

    Remove the person from the group is similar

    //remove a group
    bool updateParentGroupsTrue = true;
    UserInfo userInfo = BRApi.Security.Admin.GetUser(si, username);
    User user = userInfo.User;
    
    List<Guid> parentGroups = userInfo.ParentGroups.Keys.ToList();
    GroupInfo groupInfo = BRApi.Security.Admin.GetGroup(si, "Development");				
    Guid parentGroupToDeleteGuid = groupInfo.Group.UniqueID;
    
    if(parentGroups.Contains(parentGroups)
    {
    	parentGroups.Remove(parentGroupToDeleteGuid);
    	BRApi.Security.Admin.SaveUser(si, user, updateParentGroupsTrue, parentGroups, false);
    }

     

     

    • RobbSalzmann's avatar
      RobbSalzmann
      Valued Contributor II

      JIC, here's the VB:

      Dim updateParentGroupsTrue As Boolean = True
      
      Dim userInfo As UserInfo = BRApi.Security.Admin.GetUser(si, username)
      Dim parentGroups As List(Of Guid) = userInfo.ParentGroups.Keys.ToList()
      Dim user As User = userInfo.User
      
      Dim groupInfo As GroupInfo = BRApi.Security.Admin.GetGroup(si, groupName)
      Dim addedParentGroupGuid As Guid = groupInfo.Group.UniqueID
      parentGroups.Add(addedParentGroupGuid)
      
      BRApi.Security.Admin.SaveUser(si, user, updateParentGroupsTrue, parentGroups, False)
      
      'Remove a group
      Dim updateParentGroupsTrue As Boolean = True
      Dim userInfo As UserInfo = BRApi.Security.Admin.GetUser(si, username)
      Dim user As User = userInfo.User
      
      Dim parentGroups As List(Of Guid) = userInfo.ParentGroups.Keys.ToList()
      Dim groupInfo As GroupInfo = BRApi.Security.Admin.GetGroup(si, "Development")
      Dim parentGroupToDeleteGuid As Guid = groupInfo.Group.UniqueID
      
      If parentGroups.Contains(parentGroupToDeleteGuid) Then
          parentGroups.Remove(parentGroupToDeleteGuid)
          BRApi.Security.Admin.SaveUser(si, user, updateParentGroupsTrue, parentGroups, False)
      End If
      

       

    • Marco's avatar
      Marco
      Contributor II

      I checked the post but I do not see exactly how to add, and even more how to delete, I have not found something like that in the forum.