Implementing Authorization functionality on Dyn. Elements (Click Events)

Implementing Authorization functionality on Dyn. Elements (Click Events)

At Dynamic Elements (i.e. Text Buttons) authorization groups can be configured (so only a user with the appropriate rights can operate the element).
If only VBA Click-Events (like LeftClickUp, LeftClickDown, RightClickUp, ... aso) are configured the standard authorization mechanism doesn't work (this is intended). At the standard authorization mechanism then a message is displayed like "You are not entitled to execute this function" or the temporary login dialog is displayed (if activated).
Find below a VBA Code which compares the authorization group of the clicked element and the authorization group of the current logged-in user:
VBA Code:

'this macro is executed if the left mouse button is released
'this macro is linked to the element via "LeftClickUp"
Public Sub LeftClickUp_SetLow(obElem As Element)
'perform the validation check (-> does the current user have sufficient rights to operate the clicked element?)
If CheckUserLevel(obElem.PasswordLevel) = True Then
'-> ok.. the user has sufficient rights (perform the action you want)
Debug.Print "Current user is allowed to perform the action"
Else
'-> not sufficient rights
Debug.Print "Current user is NOT allowed to perform the action"
'show the login dialog (name of the login function: fct_LoginUser)
thisProject.RtFunctions.Item("fct_LoginUser").Start
End If

'release the text button
obElem.LeftClickUp

End Sub

'this function checks if the current user has the proper rights to operate the clicked element
Public Function CheckUserLevel(ByVal UserLevel As Integer) As Boolean
Select Case UserLevel
Case 0 To 30
CheckUserLevel = CBool(thisProject.Passwords.ItemUser(thisProject.Passwords.LoggedUser).Level And 2 ^ UserLevel)
Case 31
CheckUserLevel = CBool(thisProject.Passwords.ItemUser(thisProject.Passwords.LoggedUser).Level < 0)
Case 32 To 62
CheckUserLevel = CBool(thisProject.Passwords.ItemUser(thisProject.Passwords.LoggedUser).Level1 And 2 ^ (UserLevel - 32))
Case 63
CheckUserLevel = CBool(thisProject.Passwords.ItemUser(thisProject.Passwords.LoggedUser).Level1 < 0)
Case 64 To 94
CheckUserLevel = CBool(thisProject.Passwords.ItemUser(thisProject.Passwords.LoggedUser).Level2 And 2 ^ (UserLevel - 64))
Case 95
CheckUserLevel = CBool(thisProject.Passwords.ItemUser(thisProject.Passwords.LoggedUser).Level2 < 0)
Case 96 To 126
CheckUserLevel = CBool(thisProject.Passwords.ItemUser(thisProject.Passwords.LoggedUser).Level3 And 2 ^ (UserLevel - 96))
Case 127
CheckUserLevel = CBool(thisProject.Passwords.ItemUser(thisProject.Passwords.LoggedUser).Level3 < 0)
End Select
End Function


This is a migrated post! Originally posted on 10.07.2009 by user herberto. Please be aware that information can be outdated.