Prevent doc editing based on field value or [Admin] role membership

Insert the script for the two events listed below. This will only allow users who name appears in the "created_by" field or are a member of the Admin role to edit the document.
LotusScript


Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
     
     Dim FoundRole As Variant
     
     Dim session As New NotesSession
     Dim doc As NotesDocument
     Set doc = Source.Document  
     Dim user As String
     Dim docauthor As String
     
     user = session.CommonUserName
     
     If Source.IsNewDoc = False Then
          
          docauthor = doc.created_by(0)    ' Field to check
          
          If user = docauthor Then
               continue = True
          Else
               userRoles = Evaluate("@UserRoles")
               
               If Source.IsNewDoc = False Then
                    If Source.EditMode = True Then
                         FoundRole = False
                         For i = 0 To Ubound(userRoles)     
                              If userRoles(i) = "[Admin]" Then   ' Role to check
                                   FoundRole = True
                              End If
                         Next
                         
                         If FoundRole = False Then
                              Messagebox "You do not have the authority to edit this document, please contact " & docauthor & " or the database administrator.", 16, "Access Control Error"
                              Continue = False
                         Else
                              Continue = True
                         End If
                    End If
               End If       
          End If     
     End If
     
End Sub


Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
     
     Dim FoundRole As Variant
     
     Dim session As New NotesSession
     Dim user As String
     Dim docauthor As String
     docauthor = Source.FieldGetText("created_by")   ' Field to check
     user = session.CommonUserName     
     
     If user = docauthor Then
          continue = True
     Else
          
          userRoles = Evaluate("@UserRoles")
          
          If True = Source.EditMode Then
               Continue = True
          Else
               For i = 0 To Ubound(userRoles)
                    If userRoles(i) = "[Admin]" Then     ' Role to check
                         FoundRole = True
                    Else
                         FoundRole = False
                    End If
               Next
               If FoundRole = False Then
                    Messagebox "You do not have the authority to edit this document, please contact " & docauthor & " or the database administrator.", 16, "Access Control Error"
                    Continue = False
               Else
                    Continue = True
               End If          
          End If
     End If
     
End Sub

Posted by fbrefere001 on Friday May 11, 2001