以编程方式将用户添加到lotus notes组中

时间:2016-10-04 07:00:46

标签: lotus-notes lotus-domino lotusscript lotus

我有一个保存合同的数据库,每个合同都附有一份文件。
我的任务是让无法访问数据库的用户能够访问特定合同及其附件。
因此,特殊访问按钮。
我在表单中添加了一个特殊的访问按钮,可以访问默认用户。
我能够让他们访问合同,但是我无法让他们访问附加的文档。
进一步调查,我发现与附加文档相关联的表单仅限于与具有role / s read,author和siteadmin的用户一起查看。
我应该做的解决方案是创建一个新角色(addreader) )并创建一个具有addreader角色的组 当通过特殊访问按钮添加用户时,应该将用户添加到具有addreader角色的notes组中。
我的问题是如何在组中添加用户。
我是初学者在莲花笔记,我希望得到一些帮助。

提前致谢。

代码在这里开始:

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 个答案:

答案 0 :(得分:0)

查看小组经理http://www.ibm.com/developerworks/lotus/library/ls-groups/https://www.openntf.org/main.nsf/project.xsp?r=project/LotusScript%20Gold%20Collection

基本上,您可以从names.nsf数据库($ Groups)视图中查找groupdocument,并将用户fullname添加到成员项。