Subject: Roles, Contain with Lotusscript
On my way out, so no time to break down the code, but here is a script I use to check whether a person can create a comment based on a role and some other criteria.
Sub Click(Source As Button)
Dim wk As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As notesdocument
Dim pdoc As notesdocument
Dim session As New NotesSession
Dim db As NotesDatabase
Dim acl As NotesACL
Dim entry As NotesACLEntry
Dim entry2 As NotesACLEntry 'The matching entry is set to this
Dim dateTime As New NotesDateTime( "" )
Dim body As Variant
Dim cloop As Boolean
Dim editor As notesitem
'Dim rtitem As NotesRichTextItem
'Dim attach As NotesEmbeddedObject
Dim rname(1 To 5) As String
Dim pr As String
Dim rtfpr As String
Dim x As Integer
Dim y As Integer
Dim al As Integer 'length of the current user's role
Dim almod As Integer 'al - 2 which is used to remove the brackets from the role
Dim a As String 'current user's role without brackets
Dim uname As String 'current user's name
Dim roleswhocanedit As Variant 'stores roles of those who can edit any comments
Dim canedit As Boolean 'set if the user's role is one that can edit any comments
Dim tdata As String
Dim groupmembers As Variant 'explode the group members in the ACL and use those when comparing to the current user.
Dim pstrGroupName As String 'Group name in the acl
Dim pvarGroupMembersOut As Variant 'Members of the group in the acl
Dim activerole As String
Static tempvar As String 'this is the variable that will be used, that way it stays the same throughout the loop
Set db = session.CurrentDatabase
Set acl = db.ACL
Set uidoc = wk.CurrentDocument
Set doc = uidoc.Document
Set pdoc = db.GetProfileDocument("settings")
roleswhocanedit = doc.cpEditRoles
uname = session.CommonUserName
Set entry = acl.GetFirstEntry
While Not (entry Is Nothing)
If entry.IsGroup Then
pstrGroupName = entry.Name
groupmembers = expandGroupNames(pstrGroupName)
'Check to see if the groupmembers list contains the current user. if so, exit the wend, else loop
Forall gdata In groupmembers
If gdata = session.UserName Then
Set entry2 = entry
End If
End Forall
Else
If Lcase(entry.Name) = Lcase(session.UserName) Then
Set entry2 = entry
End If
End If
Set entry = acl.GetNextEntry(entry)
Wend
If entry2 Is Nothing Then
Exit Sub
End If
x = 1
cloop = False
Forall r In entry2.Roles
’ Messagebox( r )
rname(x) = r
Forall data In roleswhocanedit
If (Not cloop = True) Then
If (Not data = "") Then
tdata = "[" + data + "]"
’ Msgbox rname(x) + "Show all role values that are in the edit list: " + tdata
If rname(x) = tdata Then
canedit = True
tempvar = data
cloop = True
’ Msgbox TEMPVAR + " " + rname(x) + " " + tdata
Print TEMPVAR + " " + rname(x) + " " + tdata
End If
End If
End If
End Forall
x = x + 1
End Forall
al = Len(rname(1))
activerole = Mid$(rname(1), 2, al - 2)
’ Msgbox TEMPVAR
Print tempvar
If doc.wrpcxAuthor_1(0) = uname Or doc.wrpcxAuthor_1(0) = "" Or canedit Then
'Msgbox "good to go"
Else
Msgbox uname + Chr$(10) + "Only " + doc.wrpcxAuthor_1(0) + " or an administrator may edit this comment."
Exit Sub
End If
'After the correct role is found and the code runs, will drop out so no extra loops are invoked.
If tempvar = doc.wrpcxrole_1(0) Or "" = doc.wrpcxrole_1(0) Or canedit Then
'Throw up a prompt for Comments and fill out wrpcxComments_1
With doc
’ pr$ = Inputbox(“Enter your comment here…”, “Comments”, doc.wrpcxcomments_1(0))
.txtcomment = .wrpcxcomments_1
pr$ = wk.DialogBox("dlgComment", True, True, False, False, False, False, "Comment", , False, False, True)
If pr$ <> False Then
.wrpcxComments_1 = .txtcomment
'May want to only update this the first time.. ie if it is blank.
If .wrpcxrole_1(0) = "" Then
.wrpcxrole_1 = activerole 'use this because tempvar is only those people in roleswhocanedit
End If
'Current Date and Time only for new rows
If .wrpcxAuthor_1(0) = "" Then
dateTime.LSLocalTime = Now
.wrpcxCreateTime_1 = dateTime.DateOnly & Chr(10) & dateTime.TimeOnly
End If
'only update the author name if it is currently blank, else, leave it alone
If .wrpcxAuthor_1(0) = "" Then
.wrpcxAuthor_1 = session.CommonUserName
End If
'Append the editor's name to the field
Set editor = doc.GetFirstItem( "wrpcxEditor_1" )
Call editor.AppendToTextList( session.CommonUserName & " (" & activerole & ") - " & Cstr(Now) )
End If
End With
End If
'empty the comment field on this form.
doc.txtcomment = ""
Call uidoc.Refresh(False)
Set session = Nothing
Set wk = Nothing
errhndl:
End Sub