Showing posts with label Handling user roles in Lotus script. Show all posts
Showing posts with label Handling user roles in Lotus script. Show all posts

Wednesday, February 21, 2007

Handling user roles in Lotus script

Problem description: In lotus notes development it is quite often, we developers face situations, where based on the user's role we have to grant/restrict some of the functions for him/her.

Solution: Solution is quite simple. we can use 'Evaluate' function as follows.

Step1:

Create a function in the script library as below.
%REM
=============================================================
Input: Role name should be passed to this function, without square brackets
Return value: True if the passed role is enabled for current user. Else false.
=============================================================
%END REM

Function CheckUserRole(RoleName As String) As Variant
Dim CheckRole As String
Dim Userroles As Variant
CheckUserRole=False
CheckRole="["+RoleName+"]"
UserRoles= Evaluate("@UserRoles")

If Not Isempty(UserRoles ) Then
If Not Isnull(Arraygetindex(UserRoles,CheckRole,0)) Then
CheckUserRole=True
End If
End If
End Function

Step2:

Now use the above function, wherever it is required as follows.

Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
'If the user do not have [Admin] role then do not allow him to delete a document

Dim Response As Integer

If Not CheckUserRole("Admin") Then
Msgbox "You are not authorized to delete document from the database", 16, "Warning"
Continue = False
Exit Sub
End If

End Sub