I've written an add-in for EPDM but I need a way to only allow members of the "Administrators" group access it. Does anyone know a way to do this?
I've written an add-in for EPDM but I need a way to only allow members of the "Administrators" group access it. Does anyone know a way to do this?
following function will return true if the login user is the member of Admin group
Private Function IsAdmin(loginuser as String) As Boolean
Dim userMgr As IEdmUserMgr5
Set userMgr = vault
Dim group As IEdmUserGroup5
Set group = userMgr.GetUserGroup("Administrator")
If group Is Nothing Then
MsgBox "There is no group named Administrator"
Exit Sub
End If
Dim pos As IEdmPos5
Set pos = group.GetFirstUserPosition
While Not pos.IsNull
Dim user As IEdmUser5
Set user = group.GetNextUser(pos)
if user.Name = loginuser Then
return True
End If
Wend
return False
End Function
Brandon Barnes wrote:
Is there a way to disable the add-in if the function returns false?
In the EdmLib.IEdmAddIn5.GetAddInInfo method of your add-in, use some sort of branching code (if-else, switch statement etc) that only adds the various hooks and such if the appropriate conditions are met.
Jim S.
Hi Brandon
If you wouldn't mind, could show the code method you used to switch off the addin unless it's a member of the "xxx" group?
I have been using your code but it throws "random" errors for users in EPDM and I have been unable to identify the root cause.
Here is my error code:
"An Error has occurred. Error:IsGroupMember. The supplied object ID is not valid."
My function is a boolean that returns whether or not the user is a member of the supplied group.
Sure Tim,
Here's my code -
Public Sub GetAddInInfo(ByRef poInfo As EdmLib.EdmAddInInfo, ByVal poVault As EdmLib.IEdmVault5, ByVal poCmdMgr As EdmLib.IEdmCmdMgr5) Implements EdmLib.IEdmAddIn5.GetAddInInfo
' Set the add-in properties
poInfo.mbsAddInName = "Test"
poInfo.mbsCompany = "My Company"
poInfo.mbsDescription = "Test Add-in"
poInfo.mlAddInVersion = 1
poInfo.mlRequiredVersionMajor = 7
poInfo.mlRequiredVersionMinor = 0
' See if the user is allowed to access the addin
If UserCheck(strUserName, poVault) = True Then
' Add hooks
poCmdMgr.AddCmd(1000, "Test", 1)
End If
End Sub
Private Function UserCheck(ByVal strUser As String, ByVal vault As EdmLib.IEdmVault5) As Boolean
' Create a list of user groups that the add-in will be available to
Dim lstGroups As New List(Of String)
lstGroups.Add("Administrators")
lstGroups.Add("Managers")
' Loop through the groups and check if the user is a member
For Each strGroup As String In lstGroups
Dim userMgr As IEdmUserMgr5
userMgr = vault
Dim group As IEdmUserGroup5
group = userMgr.GetUserGroup(strGroup)
' Loop through the users in this group
Dim pos As IEdmPos5
pos = group.GetFirstUserPosition
While Not pos.IsNull
Dim user As IEdmUser5
user = group.GetNextUser(pos)
If user.Name = strUser Then
' User is in this group
Return True
End If
End While
Next
' User wasn't found in any of the groups
Return False
End Function
Thank you Brandon.
I have used this exact code you are using but some users in the system are now not able to right click without crashing their edmserver instance. The best I can figure is the server is not able to load the code to build their right click menu.
However, if I remove the user check, from the addin and let the OnCmd run and shift the user check when they actually execute the menu command, nobody has trouble.
EPDM 2011 SP2
Hi i have noticed this too,
Including any method calls outside of what's expected in GetAddInInfo(). EPDM throes anerror you're seeing if you're doing anything with the EPDM API besides accessing the IEdmCmdMgr interface in the GetAddInInfo() method.. So testing for group or user memberships or the like can cause issues. However, I believe this has been fixed in a recent service pack but it should be kept in mind.
Unless is absolutely necessary I try to avoid that approach
following function will return true if the login user is the member of Admin group
Private Function IsAdmin(loginuser as String) As Boolean
Dim userMgr As IEdmUserMgr5
Set userMgr = vault
Dim group As IEdmUserGroup5
Set group = userMgr.GetUserGroup("Administrator")
If group Is Nothing Then
MsgBox "There is no group named Administrator"
Exit Sub
End If
Dim pos As IEdmPos5
Set pos = group.GetFirstUserPosition
While Not pos.IsNull
Dim user As IEdmUser5
Set user = group.GetNextUser(pos)
if user.Name = loginuser Then
return True
End If
Wend
return False
End Function