OpenNTF.org - CopyACL
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
CopyACL 
Rating:
Rating: 3 , Number of votes: 2 
Contributor:
John Smart 
Category:
Lotusscript 
Type:
String functions 
Document Release:
1.1 
Notes Version:
R5.x, R6.x 
Last Modified:
20 Feb 2003 
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
Sub CopyAcl(SourceDb As notesdatabase, DestDb As notesdatabase, bReplaceAdminServer As Variant)
%REM
Thanks to Simon Andrews for posting much of this to the Lotus Developer Domain
http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/cd5ecae78219aa5c85256b6e0039c96b?OpenDocument
Code changed from original to account for setting the IsAdminServer, fixing a few bugs, and changing the variable
naming conventions to fit my standard. - John Smart, 20-Feb-2003
This will lock you out of the 'DestDb' if you are not in the 'SourceDb' acl.
Parameters:
 SourceDb - NotesDatabase - Source Database containing the desired ACL
 DestDb - NotesDatabase - Destination Database to receive the desired ACL
 bReplaceAdminServer - boolean - True if the admin server of the destination ACL should be DestDb.Server
%END REM
 Dim DestACL As NotesACL
 Dim DestEntry As NotesACLEntry
 Dim DestEntry2 As NotesACLEntry
 Dim iLevel As Integer
 Dim SourceEntry As NotesACLEntry
 Dim SourceACL As NotesACL
 
 Set SourceACL = SourceDb.ACL
 Set DestACL = DestDb.ACL
 Set SourceEntry = SourceACL.GetFirstEntry
 
 Forall sRole In DestACL.Roles
  If Len(sRole) <> 0 Then Call DestACL.DeleteRole(sRole)
 End Forall
 
 Set DestEntry = DestACL.getfirstEntry
 
 While Not(DestEntry Is Nothing)
  Set DestEntry2 = DestACL.getnextEntry(DestEntry)
  If DestEntry.name<>"-Default-" Then
   Call DestEntry.remove
  End If
  Set DestEntry = DestEntry2
 Wend
 
 Forall sRole In SourceACL.Roles
  If Len(sRole) <> 0 Then Call DestACL.AddRole( sRole )
 End Forall
 
 Do Until SourceEntry Is Nothing
  iLevel = SourceEntry.LEVEL
  If SourceEntry.name="-Default-" Then
   Set DestEntry = DestACL.getEntry("-Default-")
   DestEntry.Level = iLevel
  Else
   Set DestEntry = DestACL.CreateACLEntry( SourceEntry.Name, iLevel )
  End If
  
  Forall sRole In SourceEntry.Roles
   If Len(sRole) <> 0 Then Call DestEntry.EnableRole( sRole )
  End Forall
  
  DestEntry.UserType = SourceEntry.UserType
  
  DestEntry.CanCreateDocuments = SourceEntry.CanCreateDocuments
  
  DestEntry.CanCreateLSOrJavaAgent = SourceEntry.CanCreateLSOrJavaAgent
  
  DestEntry.CanCreatePersonalAgent = SourceEntry.CanCreatePersonalAgent
  
  DestEntry.CanCreatePersonalFolder = SourceEntry.CanCreatePersonalFolder
  
  DestEntry.CanCreateSharedFolder = SourceEntry.CanCreateSharedFolder
  
  DestEntry.CanCreateDocuments = SourceEntry.CanCreateDocuments
  
  If SourceEntry.IsAdminServer Then
   DestEntry.IsAdminServer = True
   If bReplaceAdminServer Then If DestDb.Server <> DestEntry.Name Then DestEntry.Name = DestDb.Server
   DestEntry.IsAdminReaderAuthor = SourceEntry.IsAdminReaderAuthor
  End If
  
  DestEntry.IsGroup = SourceEntry.IsGroup
  
  DestEntry.IsPerson = SourceEntry.IsPerson
  
  DestEntry.IsPublicReader = SourceEntry.IsPublicReader
  
  DestEntry.IsPublicWriter = SourceEntry.IsPublicWriter
  
  DestEntry.IsServer = SourceEntry.IsServer
  
  Set SourceEntry = SourceACL.GetNextEntry(SourceEntry)
  
 Loop
 
 DestACL.InternetLevel = SourceACL.InternetLevel
 DestACL.UniformAccess = SourceACL.UniformAccess
 
 Call DestACL.Save
End Sub
Usage / Example
Note: If the code tries to replace the admin server but an ACLEntry already exists for the admin-server-to-be, an error may occur.
 Comments
Posted by John Smart on 10/20/2004 10:59:21 AMWhy two stars?
Ok, I realize that whoever rated this piece of code with two stars probably isn't going to come back and see this message. Also, I don't really feel personal pride in this code since, as I've noted before, it's mainly just a repackaging of code already written by Simon Andrews.
However, since I do like to learn...
I felt that it does what it does very well, the code is clean, and the documentation sufficient. What about this code makes it worth only two stars?
John Smart
http://www.greyduck.com
Posted by Angelika Hendrick on 10/20/2005 07:33:50 AMCopy ACL
Dear John, I like your code. It helped me out, didn't have to write it myself and it worked well. Thanks.;-)
Posted by Kevin Pettitt on 01/12/2010 03:17:07 PMSimilar code on IBM support site
http://www-01.ibm.com/support/docview.wss?uid=swg21098933
 Add your comment!