Prevent doc deletion based on author or role membership

Insert the script below in the DB 'Querydocumentdelete' event. This will prevent any user who isn't the doc author or a member of the Admin role the ability to delete the document. There are three variable types (docauthor field, role name, formname#). You will need to identify every form title. This script will also disallow users from deleting a doc if is has existing children docs.
LotusScript


Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
     
     
     Dim session As New NotesSession
     Dim db As NotesDatabase, UtilitiesDB As NotesDataBase
     Dim collection As NotesDocumentCollection, responses As NotesDocumentCollection
     Dim  doc As NotesDocument, xdoc As NotesDocument
     Dim view As notesview
     
     Dim user As String  
     Dim docauthor As String 
     Dim FoundRole As Variant
     
     Stop
     
     Set db = session.CurrentDatabase
     Set collection = Source.Documents
     
     user = session.CommonUserName 
     
     
     Set Doc = Collection.GetFirstDocument
     Do While Not Doc Is Nothing
          'Allow Replication or Save Conflicts to be deleted in any event.
          IsConflict = Evaluate("@IsAvailable($Conflict)", Doc)
          If IsConflict(0) Then
               Continue = True
               Exit Sub
          End If
          
          docauthor = doc.created_by(0)            ' Author field
          
          userRoles = Evaluate("@UserRoles")
          
          For i = 0 To Ubound(userRoles)     
               If userRoles(i) = "[Admin]" Then            'Role
                    FoundRole = True
               Else
                    FoundRole = False
               End If
          Next  
                  
          
          If FoundRole = False Then
               
               If user = docauthor Then
               Else
                    
                    If Ucase(doc.Form(0)) = "formname#1" Then      
                         Messagebox "Sorry, you may not delete this document, please contact " & docauthor & " or the database administrator.",0 + 48
                         Continue = False
                         Exit Sub
                    End If
                    
                    If Ucase(doc.Form(0)) = "formname#2" Then
                         Messagebox "Sorry, you may not delete this document, please contact " & docauthor & " or the database administrator.",0 + 48
                         Continue = False
                         Exit Sub
                    End If
                    
                    If Ucase(doc.Form(0)) = "formname#3" Then
                         Messagebox "Sorry, you may not delete this document, please contact " & docauthor & " or the database administrator.",0 + 48
                         Continue = False
                         Exit Sub
                    End If
                    
                    If Ucase(doc.Form(0)) = "formname#4" Then
                         Messagebox "Sorry, you may not delete this document, please contact " & docauthor & " or the database administrator.",0 + 48
                         Continue = False
                         Exit Sub
                    End If
                    
                    If Ucase(doc.Form(0)) = "formname#5" Then
                         Messagebox "Sorry, you may not delete this document, please contact " & docauthor & " or the database administrator.",0 + 48
                         Continue = False
                         Exit Sub
                    End If
                    
                    If Ucase(doc.Form(0)) = "formname#6" Then
                         Messagebox "Sorry, you may not delete this document, please contact " & docauthor & " or the database administrator.",0 + 48
                         Continue = False
                         Exit Sub
                    End If
                    
               End If
          End If
          
          Set responses = doc.Responses
          If responses.Count <> 0 Then
               Messagebox "Sorry, you may not delete this Document because it contains child Documents. " & _
               "First delete the child documents, then delete the Parent Document."
               Continue = False
               Exit Sub
          End If
          Set Doc = Collection.GetNextDocument(Doc)
     Loop
     
End Sub

Posted by fbrefere001 on Friday May 11, 2001