
OpenNTF Code Bin
About This Code
Brief Description:
Agent to set document readers acl for selected documents
Last Modified:
24 Sep 2007
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
Name: Set Document Readers
Last Modification: 09/24/2007 07:50:15 AM
Comment: [Not Assigned]
Shared Agent: Yes
Type: LotusScript
State: Enabled
Trigger: Manually From Actions Menu
Acts On: Selected documents
LotusScript Code:
Option Public
Option Declare
%INCLUDE "lsconst.lss"
Sub Initialize
' Set the $Readers field just like it's set when edited using the security tab of the Document Properties box
' for each items selected in the view
' check to see it item value already exists before adding to list
' use names must be in full cannonical format
' group names are just the name
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim docChanged As Boolean
Dim fieldValues As Variant
Dim statusMessage As String
Dim count As Long
Dim nameCount As Integer
Dim picklist As Variant
' get names to set $Readers field to
' display names selection dialog here
picklist = workspace.PickListStrings( PICKLIST_NAMES, True )
If Elements(picklist) <= 0 Then
statusMessage = "Do you want to allow all readers and above to read the selected documents?"
Else
statusMessage = "Do you want to allow only these names to have read access to the selected documents??"
End If
If Messagebox(statusMessage, MB_YESNO + MB_DEFBUTTON2, "Set Document Reader ACL") = IDNO Then
Exit Sub
End If
' set document acl for each document selected
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set doc = collection.GetFirstDocument()
count = 0
While Not(doc Is Nothing) ' for each document selected
count = count + 1
If SetReaders(doc, picklist) Then
statusMessage = "Set document access for " & doc.Form(0) & " document " & Cstr(count) & " of " & Cstr(collection.Count)
Else
statusMessage = "Unable to set document access for " & doc.Form(0) & " document " & Cstr(count) & " of " & Cstr(collection.Count)
End If
Print statusMessage
Set doc = collection.GetNextDocument(doc)
Wend
End Sub
Function SetReaders(doc As notesdocument, values As Variant) As Boolean
' forces the specified values into the documents $Readers field, setting access to the document
' if values contains only "" in one element, remove the $Readers field which sets access to all readers and above
On Error Goto errHand
SetReaders = False ' assume field change fails
' parameter validation
If doc Is Nothing Then
Exit Function
End If
Dim item As NotesItem
Set item = doc.GetFirstItem( "$Readers" )
If Not item Is Nothing Then ' if $Readers exists, we're replacing it so get rid of it
item.Remove
End If
If Elements(values) <= 0 Then ' removing $Readers sets access to all readers and above
Call doc.Save( True, False)
Exit Function
End If
' build name list
Dim fieldValues As Variant
Redim fieldValues(1) ' minimum of 2 values in the list
fieldValues(0) = "LocalDomainAdmins" ' always have these two in the access list
fieldValues(1) = "LocalDomainServers" ' so we can't lock ourselves out of the document
fieldValues = Arrayappend( fieldValues, values )
values = Fulltrim(Arrayunique(fieldValues, 5)) ' remove duplicate names and empty elements
Set item = New NotesItem(doc, "$Readers", values, READERS) ' Field Flags = SUMMARY READ-ACCESS NAMES
item.IsNames = False ' remove NAMES attribute from Field Flags = SUMMARY READ-ACCESS
item.IsSigned = True ' add SIGN to Field Flags = SIGN SUMMARY READ-ACCESS
Call doc.Save( True, False)
SetReaders = True ' $Readers field update worked
errExit:
On Error Goto 0
Exit Function
errHand:
Msgbox "error at line " & Erl & ": " & Error
Resume errExit
End Function
Function Elements (aList As Variant) As Long
'count the number of elements in a list and return it
'LS equivalent to @Elements
If Isempty(aList) Then
Elements = 0
Else
Dim x As Long
x = 0
If Not aList(0) = "" Then
Forall vals In aList
x = x + 1
End Forall
End If
Elements = x
End If
End Function
Usage / Example
A recent admin task required setting the document readers for a bunch of groups in our Domino directory. This is done manually as follows: right click a document, pick document properties, switch to the Security tab), set the ACL under the "All readers and above" check box. But, setting read access for a lot documents is very cumbersome. I looked around for a quick way to do this and found none. Though there is probably a 3rd party tool that does it. I don't have the budget for that. So, I created an agent.
The agent modifies the document readers ACL of the selected documents. When run, a name picker is displayed. If no names are selected, the document ACL will be reset to "All readers and above". If one or more names are selected, the names and the groups Local Domain Admins and Local Domain Servers will be granted access to the document.
WARNING: You can do some serious damage by denying access to documents in the Domino directory. Especially if you lock out servers or admins. So, examine the code and make changes to reflect your system. Test thoroughly. I make no guaranty or warranty of any kind. USE AT
YOUR OWN RISK.
I hope you find this useful.
Comments
No documents found