如何防止某些用户从 Lotus 视图打开文档?

How to prevent some users to open a document from a Lotus view?

我有:

我如何防止为所有用户打开特定文档,除了那些列在 X 中的用户? 我想这可以通过 QueryOpenDocument 事件来完成,但是需要一些关于如何构建代码的帮助。

谢谢。

QueryOpenDocument、查看选择公式和其他类似内容并不是防止用户打开您的文档作为安全措施的好方法。

用户可以创建个人视图或将您的数据库 and/or 文件复制到另一个地方(闪存 usb 等)。

安全措施应包括:

  1. Encryption(通过 public and/or 秘密加密密钥)
  2. Readers访问,通过Readers字段(一个特殊字段,内容是授权用户的用户名,可以阅读本文档)。

在某些情况下,您可能需要阻止从视图中打开文档,这不是出于安全原因,而是为了解决特定任务。

例如,如果您的视图显示不应以任何形式打开的文档。

在这种情况下,在设计器中打开视图,转到 QueryOpenDocument 并添加如下代码:

Sub Queryopendocument(Source As Notesuiview, Continue As Variant)
    Dim doc2BeOpened As NotesDocument

    Set doc2BeOpened =  Source.Documents.getFirstDocument()

    'checking MyField value to decide, open or not open the document
    If doc2BeOpened.MyField(0) = "some value" Then
        continue = False 'preventing `open document` action
    End If
End Sub

要允许打开文档,请确保 Continue 变量等于 True。默认为True




更新 №1

如果您的文档包含常用用户名列表,那么您可以使用以下代码:

Sub Queryopendocument(Source As Notesuiview, Continue As Variant)

    Dim session As New NotesSession
    Dim userName As String
    Dim whoAllowed2ViewDoc As Variant

    Dim doc2BeOpened As NotesDocument

    userName = session.CommonUserName

    Set doc2BeOpened =  Source.Documents.getFirstDocument()

    'let say your field name is AllowedPeopleNames
    'you can use doc2BeOpened.AllowedPeopleNames or doc2BeOpened.GetItemValue("AllowedPeopleNames")
    'both (without (0) at the end, will return you a variant array with names)
    whoAllowed2ViewDoc = doc2BeOpened.GetItemValue("AllowedPeopleNames")

    If Not Isnumeric(Arraygetindex(whoAllowed2ViewDoc, userName)) Then
        continue = False 'preventing `open document` action if userName is not listed in whoAllowed2ViewDoc array   
    End If  
End Sub

请注意,上面的代码适用于普通用户名。

  • John Smith - 是普通用户名
  • John Smith\IT\Acme - 用户名的缩写
  • CN=John Smith\OU=IT\O=Acme - 是完全限定的名称(规范形式)。

要获得完全限定名称(也称为 canonical 形式),您可以使用 session.username 要获取缩写形式的名称,请获取完全限定的用户名,然后使用 NotesName class,以完全限定名称作为参数构建,然后从中获取名称的缩写形式。

Dim notesName as NotesName
Dim abbreviatedUserName as String

Set notesName = New NotesName( fullyQualifiedName )
abbreviatedUserName = notesName.Abbreviated




更新№2

检查数组中是否存在用户名时要小心。首先,您需要确定存储在该(字段)数组 AllowedPeopleNames.

中的名称使用的是什么形式

如果此数组中的名称如下所示:

"John Smith"
"Luis Brown"
"Antony Stoppard"

那么这个数组包含了常用的用户名,你需要获取用户名来检查:

Dim session as New NotesSession
Dim username as String

username = session.CommonUserName

如果此数组中的名称如下所示:

"John Smith/IT/Acme"
"Luis Brown/IT/Acme"
"Antony Stoppard/IT/Acme"

然后这个数组包含缩写形式的名字。您需要获取用户名以使用此方法进一步检查:

Dim session as New NotesSession
Dim notesName as New NotesName(session.username)
Dim username as String

username = notesName.abbreviated

并且如果此数组中的名称如下所示:

"CN=John Smith/OU=IT/O=Acme"
"CN=Luis Brown/OU=IT/O=Acme"
"CN=Antony Stoppard/OU=IT/O=Acme" 

然后它包含规范形式的名称。您应该使用以下方法获取用于检查此数组的用户名:

Dim session as New NotesSession
Dim username as String

username = session.username

希望对您有所帮助。