0
votes

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
1
I'm not sure if adding users to a group is the right solution to your problem. You need to clarify some of your language here in order for us to get a clear idea of what you are really doing. When you say "attachment", that could simply mean a file that is directly attached to the Notes document that contains the contract. I don't think you mean that, but it's important to be sure. Does this application have two forms - one for the contract document, and one for a document containing the attached file? - Richard Schwartz
second Richards comment - Andrew Magerman
I am sorry, I was not able discuss my problem clearly. Yes you are right. There is a document and a file attached to the document. I have two forms. One form to view the contract and another form where users can view or download the attachment. The form where users can download the attachment is restricted to be viewed by users with roles read, author, and siteadmin only. The database was already designed that way by the developer. - Faith Camille
I was asked to make the default users(Users with no access to the database) be able to view the contract and its associated attachment. I made a Special access button in the contract which will add the username to the whocan read field of the document or the contract. This shouldmake default users view specific contracts and its attachment but I am unable to make the attachment viewed by the user with special access. The form where users can view and download the attachment is restricted to be viewed by users with roles read, author, and siteadmin only. - Faith Camille
I was planning to add an Addreader role to be given to special access users. I will create an ADDREADER group too where users with special access will be members. This ADDREADER group will have the addreader role in the ACL of the database. I will add the Addreader role in the form (where users can download and view attachment) so that special access users will be able to view and open attachments. May I ask if this is the right thing to do? If not, please advice on waht is the best thing to do. Thank you. - Faith Camille

1 Answers

0
votes

have a look at the group manager http://www.ibm.com/developerworks/lotus/library/ls-groups/ or https://www.openntf.org/main.nsf/project.xsp?r=project/LotusScript%20Gold%20Collection

Basically you could lookup the groupdocument from the names.nsf database ($Groups) view and add the users fullname to the members item.