为一组用户查找所有组成员资格的最简单方法是什么?

问题描述 投票:0回答:3

我有一个多米诺骨牌组(仅限访问控制列表),让我们称它们为

Main_Group
。 该组包括所有员工,我想知道他们属于哪些其他多米诺骨牌组。

Main_Group
的成员:

- John Smith/ORGANIZATION
- Peter Smith/ORGANIZATION
- Jeff Smith/ORGANIZATION

当然这个列表比这 3 个条目长得多。

我会寻找这个组中的每个成员,这个用户是其他多米诺骨牌组的成员,并将这些信息放入 CSV 中。 CSV 格式应如下所示:

UserName;DominoGroups
John Smith;Domino_Group1,Domino_Group2,Domino_Group3
Peter Smith;Domino_Group2
Jeff Smith;Domino_Group1,Domino_Group3

获得这些信息的最佳方式是什么? Lotus Script,任何带公式的视图?或者是否已经有一个笔记数据库在做这个?

lotus-notes lotus-domino lotusscript lotus hcl
3个回答
1
投票

不简单。一个人可以通过一个或多个间接级别进入一个组。即,一个人在 GroupA 中,GroupA 在 GroupB 中,GroupB 在 GroupC 中,GroupC 在 GroupD 中,顺便说一句,GroupE、GroupF 和 GroupG...您将不得不编写代码来递归遍历组,检测周期,并提出一个确定的组成员列表。据我所知,从来没有为此公开过 API。


1
投票

没有简单的方法可以得到你想要的。您可以在地址簿中创建一个视图,使用“组”视图作为模板,并为“成员”项添加一个分类列。不幸的是 - 正如理查德所写 - 你不会得到那样的嵌套组成员资格。

你需要:

  • 循环浏览所有组文件
  • 递归获取每个组的所有成员
  • 只要您的用户在成员中,然后将组名添加到列表/数组...
  • 导出结果

但是:如果您只需要知道/查看特定用户属于哪些组,那么请使用 Domino Administrator Client。打开“组”视图,然后打开“组”窗格并选择“管理组”。然后在最左边的面板中选择用户并单击右侧的“成员层次结构”,然后您会看到该用户所属的组,甚至是嵌套组。很遗憾,您无法导出此信息。


0
投票

这段代码构建了一个动态数组列表来充当键/值对(其中每个值都是一个数组)。它是根据

Group
中的
names.nsf
视图构建的。它不是获取每个组名并加载成员,而是以相反的方式构建它,因此对于每个成员,它都有一个组数组。组可以在其他组中,因此它递归地遍历每个组。为了防止循环(例如,A 组在 B 组中,反之亦然),它使用
visited
数组,如果已经访问过该组,该数组将终止搜索的那一部分。访问数组结束,递归完成后,用户所在的组列表。

最初构建键/值列表比多个全文搜索更快,特别是如果您不是查找一个名称,而是在 names.nsf 中循环所有用户名,因为一旦构建了键/值列表就没有必要再次查询数据库。我没有为每个用户构建循环,但它可以很容易地添加到

getGroupsForUser
函数中。

下面的代码

getGroupsForUser
功能。返回用户所在的每个组的格式化字符串。用户名是第一项。

Function getGroupsForUser(userName As String) As String
    If userName="" Then Exit function
    
    Dim ns As New NotesSession, namesDatabase As NotesDatabase
    Dim visited As Variant, groupKeyValueStore List As Variant
    Dim returnString As String, separator As String, i As Integer
    
    Set namesDatabase = ns.getDatabase(ns.Currentdatabase.Server, "names.nsf", False)
    visited = Null
    
    Call getGroupKeyValues(groupKeyValueStore, namesDatabase)
    Call searchGroupsRecursive(userName, visited, groupKeyValueStore)

    i=0
    returnString = ""
    ForAll item In visited
        If i=0 Then separator = ""
        If i=1 Then separator = ";"
        If i>1 Then separator = "," 
        returnString = returnString + separator + item
        i = i + 1
    End forall

    getGroupsForUser = returnString
End Function

getGroupKeyValues
遍历 names.nsf 中的组视图并创建键/值列表。

Public Function getGroupKeyValues(groupKeyValueStore List As Variant , namesDatabase As NotesDatabase)
    Dim groupView As NotesView, doc As NotesDocument, members As Variant, groupName As String
    Dim separator As String, values As Variant, i As Integer, tempString(0) As String
    
    Set groupView = namesDatabase.getView("Groups")
    Set doc=groupView.Getfirstdocument()
    
    Do Until doc Is Nothing
        groupName = doc.ListName(0)
        members = doc.getItemValue("Members")
        ForAll member In members
            If IsElement(groupKeyValueStore(member)) Then
                If IsNull(ArrayGetIndex(groupKeyValueStore(member), groupName)) Then
                    values = groupKeyValueStore(member)
                    i = ubound(values) + 1
                    ReDim Preserve values(i)
                    values(i) = groupName
                    groupKeyValueStore(member) = values
                End If
            Else
                tempString(0) = groupName
                groupKeyValueStore(member) = tempString
            End If
        End ForAll
        Set doc=groupView.getNextDocument(doc)
    Loop
End Function

searchGroupsRecursive
递归搜索每个组,确保没有组被访问两次。

Public Function searchGroupsRecursive(userName As String, visited As Variant, groupKeyValueStore List As Variant) As Variant
    Dim length As Integer, userNotesName As NotesName, fullUserName As String
    Dim tempArray(0) As String
    
    Set userNotesName = New NotesName(userName)
    fullUserName = userNotesName.Canonical
    
    If IsNull(visited) Then
        tempArray(0) = userName
        visited = tempArray
    Else
        length = UBound(visited)
        ReDim Preserve visited(length + 1)
        visited(length + 1) = userName  
    End If
    
    If Not isElement(groupKeyValueStore(fullUserName)) Then Exit function

    ForAll item In groupKeyValueStore(fullUserName)
        Call searchGroupsRecursive(CStr(item), visited, groupKeyValueStore)
    End ForAll
End Function
© www.soinside.com 2019 - 2024. All rights reserved.