I have a database that keeps contracts and each contract have an attached document file.
My task is to make users without access to the database able to access specific contracts and its attachments.
Thus, the special access button.
I added a special access button to the form that gives access to default users.
I was able to give them access up to the contract but I am not able to give them access to the attached document.
Upon further investigation, I found out that the form associated with the attached document is restricted to be viewed with users with role/s read, author, and siteadmin only.
The solution I should do is to create a new role (addreader) and create a group that have the addreader role.
when users are addedd via the special access button, the user/s should be added to the notes group with addreader role.
My problem here is how to add the user in the group.
I am a beginner in lotus notes and i am hoping for some help.
Thanks in advance.
CODE STARTS HERE:
Sub Initialize
AGENT_NAME = "wqs-DocAccess"
ERROR_ON = True
If (ERROR_ON) Then On Error Goto Error_Handler
Call initObjects() ' Set global variables
Call ProcessAccess()
Exit Sub
Error_Handler: ' Error handling
Call ErrorHandler(Err(), Error$(), "Initialize sub", Erl())
End Sub
Sub ProcessAccess()
' This sub will inspect the given effective date range and enforce it for this web submit.
If (ERROR_ON) Then On Error Goto Error_Handler
Dim scanDoc As NotesDocument
Dim nItem As NotesItem
Dim vStart As Variant
Dim vEnd As Variant
Dim vEntries As Variant ' Array of strings
Dim strUser As String
Dim strCanonUser As String
Dim strDESUnid As String
Dim strDuration As String
Dim doRemove As Integer ' Boolean: Default = False
strUser = webDoc.GetItemValue("UserName")(0)
strCanonUser = Session.CreateName(strUser).Canonical
strDESUnid = webDoc.GetItemValue("DesDocID")(0)
If (webDoc.GetItemValue("RemoveAccess")(0) = "Yes") Then doRemove = True
' Determine date range
vStart = webDoc.GetItemValue("AccessBeginDate")(0)
strDuration = webDoc.GetItemValue("Duration")(0)
' Required fields on Access Doc have been filled out - continue inspection
vEnd = Evaluate(|@Adjust([| & Format$(vStart, "mm/dd/yyyy") & |]; 0; 0; | & Val(strDuration) - 1 & |; 0; 0; 0)|)
vEnd = vEnd(0)
' Store info in the event an error occurs trying to retrieve DES
strErrorInfo = "DES UNID = " & strDESUnid & "; User = " & strUser & "; AccessDoc UNID = " & webDoc.UniversalID
' Retrieve DES doc
Set desDoc = getDESDoc(strDESUnid)
If (desDoc Is Nothing) Then
Error 6020, "ERROR: Could not find related DES doc upon saving the Access doc" ' Should never happen.
End If
' Continue inspection of effective date range and be sure is enforced on DES
vEntries = desDoc.GetItemValue("AllowAccess")
If ((Today >= vStart And Today <= vEnd) And (Not doRemove)) Then
' In scope, be sure name and Access UNID are in DES
If Not (isStringInArray(strUser, vEntries)) Then
' User should have access, but is not listed -- stamp name on DES
Call desDoc.ReplaceItemValue("AllowAccess", AddStringToArray(strUser, vEntries))
Call desDoc.ReplaceItemValue("AllowAccessDocID", _
AddStringToArray(webDoc.UniversalID, desDoc.GetItemValue("AllowAccessDocID")))
' Add name to Readers field on DES
Call desDoc.ReplaceItemValue("WhoCanRead", _
AddStringToArray(strCanonUser, desDoc.GetItemValue("WhoCanRead")))
' BSM 09/08/2004: Also add name to Readers field on Scan doc (if one exists)
Set scanDoc = getScanDoc(desDoc)
If Not (scanDoc Is Nothing) Then
Call scanDoc.ReplaceItemValue("WhoCanRead", _
AddStringToArray(strCanonUser, scanDoc.GetItemValue("WhoCanRead")))
Call scanDoc.Save(True, True)
End If
Call StampAccessHistory(desDoc, Format$(Now, "mm/dd/yyyy") & " -- Name added: " & strUser)
Call desDoc.Save(True, True)
End If
Else
' Out of scope, be sure name and Access UNID are *not* in DES
If (isStringInArray(strUser, vEntries)) Then
' ERROR -- User has access, but should not! -- Remove user name stamp from DES.
Call RemoveAccessNameFromDES(strUser, strDESUnid, False)
End If
If (vEnd < Today) Then
Call webDoc.ReplaceItemValue("Expired", "Yes")
End If
' Note: If user clicked "Remove", then the daily agent will delete it the next day (cannot delete webDoc if the DocumentContext)
End If
' Copy editors field over from DES doc
Set nItem = desDoc.GetFirstItem("WhoCanEdit")
Call webDoc.CopyItem(nItem, "")
Exit Sub
Error_Handler: ' Error handling
Call ErrorHandler(Err(), Error$(), "ProcessAccess sub", Erl())
End Sub
Sub initObjects()
' This sub will set certain global variables
If (ERROR_ON) Then On Error Goto Error_Handler
Call InitSession() ' Invoke shared function
Set webDoc = Session.DocumentContext
Exit Sub
Error_Handler: ' Error handling
Call ErrorHandler(Err(), Error$(), "initObjects sub", Erl())
End Sub