Developer forum

Forum » Development » Add group to the list of my impersonate users

Add group to the list of my impersonate users

Rui Silva
Reply

Is there anyway in DW API to add a group to the impressonate list of an user ?

Best,

Rui Silva


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Rui,

It is possible, but you can't do it on the basis of the Group by itself, you need the users in the group.

Something like this:

// Get your user that can impersonate
var userThatCanImpersonate = User.GetUserByID(100);
// Get your group that can be impersonated
var groupThatCanBeImpersonated = Group.GetGroupByID(100);

// Get the ids of the users that can be impersonated
var idsOfUsersThatCanBeImpersonated = groupThatCanBeImpersonated.Users.Select(user => user.ID).ToList();
// Set the list of user ids on the current user and mark the relation so that the userThatCanImpersonate object is the one that can impersonate
userThatCanImpersonate.UpdateSecondaryUsers(idsOfUsersThatCanBeImpersonated, updateUsersICanSetAsSecondary: true)

Be aware that this will replace any existing impersonation relations. If you want to keep those, then they need to be added to the list of ids.

- Jeppe

Votes for this answer: 1
 
Rui Silva
Reply

Thanks for the help.

 

You must be logged in to post in the forum