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

Marco
Contributor

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.

Marco_1-1710435959836.png

 

1 ACCEPTED SOLUTION

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

 

View solution in original post

5 REPLIES 5

MarcusH
Contributor III

You will want to look at BRApi.Security.Admin. This post might help:

https://community.onestreamsoftware.com/t5/Rules/Save-Security-Group-into-another-Security-group-usi...

And the MarketPlace solution Process Control Manager has some code which saves security groups in the Dashboard Extender PCM_SolutionHelper

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.

RobbSalzmann
Valued Contributor

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);
}

 

 

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

 

Thank you very much Robb.