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.

    Disclaimer

    This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.

    The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.

    Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.

    Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.

    COPA-DATA reserves the right to change this document from time to time at own discretion.


    Ing. Punzenberger COPA-DATA GmbH
    Karolingerstraße 7b · 5020 Salzburg · Austria
    www.copadata.com