### Complete Workflow Example for Auditing ACLs with NotesLib in Python Source: https://context7.com/richieadler/noteslib/llms.txt This comprehensive example demonstrates a full workflow for auditing Notes database access using NotesLib. It shows how to connect to a database, retrieve ACL entries, identify managers, track users with elevated access, and handle potential database errors. ```python import noteslib from noteslib import DatabaseError def audit_database_acl(server, database, password=None): """Audit ACL entries for a Notes database.""" try: acl = noteslib.ACL(server, database, password) print(f"ACL Audit for: {server}/{database}") print(f"Available Roles: {acl.Roles}") print("-" * 50) managers = [] high_access = [] for entry in acl.getAllEntries(): name = entry.getName() level = entry.getLevel() roles = entry.getRoles() flags = entry.getFlags() # Track managers if level == "Manager": managers.append(name) # Track users with elevated access if level in ["Manager", "Designer", "Editor"]: high_access.append({ "name": name, "level": level, "roles": roles, "can_delete": "Delete Documents" in flags }) print(f"\nManagers ({len(managers)}): {managers}") print(f"\nUsers with elevated access:") for user in high_access: print(f" {user['name']}: {user['level']}, " f"Delete: {user['can_delete']}, Roles: {user['roles']}") return high_access except DatabaseError as e: print(f"Cannot access database: {e}") return None # Run audit on local names.nsf audit_database_acl("", "names.nsf", "password") # Run audit on server database audit_database_acl("NYNotes1", "ACLTest.nsf", "password") ``` -------------------------------- ### Initialize Notes Session Source: https://context7.com/richieadler/noteslib/llms.txt Demonstrates how to establish a singleton COM connection to a Lotus Notes session. It supports optional password authentication and provides access to standard NotesSession properties. ```python import noteslib session = noteslib.Session("your_password") session = noteslib.Session() print(f"Notes Build Version: {session.NotesBuildVersion}") print(f"Common User Name: {session.CommonUserName}") print(f"User Name: {session.UserName}") data_directory = session.GetEnvironmentString("Directory", -1) print(f"Notes Data Directory: {data_directory}") session_a = noteslib.Session("password") session_b = noteslib.Session() assert id(session_a) == id(session_b) ``` -------------------------------- ### Initialize ACL and Iterate Entries Source: https://github.com/richieadler/noteslib/blob/master/README.md Demonstrates how to instantiate an ACL object by providing server and database details, and how to iterate through all entries within the ACL using the getAllEntries method. ```python import noteslib acl = noteslib.ACL("NYNotes1", "ACLTest.nsf", "password") for entry in acl.getAllEntries(): print(entry.getName()) ``` -------------------------------- ### Connect to Notes Database Source: https://context7.com/richieadler/noteslib/llms.txt Shows how to connect to a local or server-based Notes database (.nsf file). The Database class manages its own session and shares handles for performance efficiency. ```python import noteslib db = noteslib.Database("", "names.nsf", "password") db = noteslib.Database("NYNotes1", "mail/jsmith.nsf", "password") db = noteslib.Database("ServerName", "database.nsf") print(f"Database Created: {db.Created}") print(f"Database Title: {db.Title}") print(f"Database Size: {db.Size}") print(f"File Path: {db.FilePath}") print(f"Is Open: {db.IsOpen}") db_a = noteslib.Database("NYNotes1", "ACLTest.nsf", "password") db_b = noteslib.Database("NYNotes1", "ACLTest.nsf") assert id(db_a) != id(db_b) assert id(db_a._Database__handle) == id(db_b._Database__handle) ``` -------------------------------- ### Connect to Notes Database Source: https://github.com/richieadler/noteslib/blob/master/README.md Instantiates a Database object to interact with a specific Notes database file. It automatically handles the underlying Session creation and allows access to standard NotesDatabase properties. ```python import noteslib db = noteslib.Database("NYNotes1", "ACLTest.nsf", "password") print(db.Created) ``` -------------------------------- ### Initialize Notes Session Source: https://github.com/richieadler/noteslib/blob/master/README.md Creates a singleton Session object to connect to the Notes environment. It supports an optional password parameter and provides access to standard LotusScript NotesSession properties and methods. ```python import noteslib s = noteslib.Session("password") print(s.NotesBuildVersion) print(s.GetEnvironmentString("Directory", -1)) ``` -------------------------------- ### Manage Access Control List (ACL) Source: https://context7.com/richieadler/noteslib/llms.txt Illustrates how to interact with a database ACL, including retrieving entries and printing formatted access information. ```python import noteslib acl = noteslib.ACL("NYNotes1", "ACLTest.nsf", "password") acl = noteslib.ACL("", "names.nsf", "password") entries = acl.getAllEntries() for entry in entries: print(entry.getName()) print(f"ACL Roles: {acl.Roles}") print(acl) ``` -------------------------------- ### NotesLib Error Handling in Python Source: https://context7.com/richieadler/noteslib/llms.txt This section illustrates how to handle specific exceptions provided by the NotesLib library, such as SessionError for connection issues and DatabaseError for database access problems. It also shows how to catch generic NotesLib errors. ```python import noteslib from noteslib import SessionError, DatabaseError, NotesLibError # Handle session connection errors try: session = noteslib.Session("wrong_password") except SessionError as e: print(f"Failed to connect to Notes: {e}") # Handle database connection errors try: db = noteslib.Database("InvalidServer", "nonexistent.nsf", "password") except DatabaseError as e: print(f"Failed to open database: {e}") # Catch all NotesLib errors try: acl = noteslib.ACL("Server", "database.nsf", "password") entries = acl.getAllEntries() except NotesLibError as e: print(f"NotesLib error occurred: {e}") ``` -------------------------------- ### Access ACL Entries Source: https://context7.com/richieadler/noteslib/llms.txt Demonstrates retrieving individual ACLEntry objects from an ACL instance to inspect user permissions and roles. ```python import noteslib acl = noteslib.ACL("NYNotes1", "ACLTest.nsf", "password") entries = acl.getAllEntries() ``` -------------------------------- ### Inspect ACLEntry Details Source: https://github.com/richieadler/noteslib/blob/master/README.md Shows how to retrieve a specific ACLEntry from an ACL object and display its formatted details, including name, level, roles, and flags. ```python import noteslib acl = noteslib.ACL("NYNotes1", "ACLTest.nsf", "password") print(acl.getAllEntries()[3]) ``` -------------------------------- ### Iterating and Accessing ACLEntry Details in Python Source: https://context7.com/richieadler/noteslib/llms.txt This snippet demonstrates how to iterate through ACL entries and access their details such as name, level, roles, and flags using convenience methods provided by the NotesLib library. It also shows direct access to standard NotesACLEntry properties. ```python for entry in entries: # Get entry details using convenience methods name = entry.getName() # Returns entry name as string level = entry.getLevel() # Returns level as string: "No Access", "Depositor", # "Reader", "Author", "Editor", "Designer", "Manager" roles = entry.getRoles() # Returns sorted list of roles flags = entry.getFlags() # Returns list of permission flag strings print(f"User: {name}") print(f"Access Level: {level}") print(f"Roles: {roles}") print(f"Flags: {flags}") print("---") # Print a single entry (uses built-in formatting) manager_entry = entries[3] print(manager_entry) # Access standard NotesACLEntry properties directly print(entry.Name) print(entry.Level) # Returns numeric level (0-6) print(entry.CanCreateDocuments) print(entry.CanDeleteDocuments) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.