In a QAction (driver) we want to detect if the person clicking on a button (triggering the qaction) is part of a specific group or groups.
I found the level feature on param level, but this is not what I need.
I would like to make it dynamic e.g.
- click on button is allowed for user from group A when <condition A>
- click on button is NOT allowed for user from group A when <condition B>
- click on button is allowed for user from group B when <condition B>
Can the usercookie be used somehow?
The following code can be used in a QAction to get the security info to determine what user groups a user is part of:
var securityInfo = (GetUserInfoResponseMessage)protocol.SLNet.SendSingleResponseMessage(new GetInfoMessage(InfoType.SecurityInfo));
var user = securityInfo.FindUserByFullName(protocol.UserInfo);
The Groups property will contain an array of the group ids the user is part of. If the group name is needed instead of the id, then the following can be used:
var firstUserGroupId = user.Groups.First();
var firstUserGroup = securityInfo.FindGroupNameByID(firstUserGroupId);
This is just some example code so make sure the necessary checks and exception handling is implemented.
Note that this is using SLNet calls which need to be used with caution and there is no guarantee that these will not be changed in the future.