我已经构建了一个检查用户是否是安全组成员的函数。目前它循环所有组,但我希望它只循环用户的组。我试图更改功能,但它一直给我一个类型不匹配错误。
对象 ScUser 有 SecurityGroups 属性。当我在For Each循环中使用它时,它会给我一个类型不匹配错误。 对于ScUser.SecurityGroups中的每个SecGroup
以下代码运行正常。你如何修改它,使它只循环用户的组?
Public Function UserHasAccess(SGroup As String) As Boolean
Dim ScUser As CUser
Dim SecGroup As CSecurityGroup
Dim SecGroups As CSecurityGroups
Set ScUser = New CUser
ScUser.Init SessionContext
ScUser.Load SessionContext.CurrentUserID
Set SecGroups = New CSecurityGroups
SecGroups.Init SessionContext
For Each SecGroup In SecGroups
Debug.Print SecGroup.Fields(SecurityGroup_fld_NAME)
If SecGroup.Fields(SecurityGroup_fld_NAME) = SGroup Then
UserHasAccessNEW = True
Exit Function
End If
Next
End Function
答案 0 :(得分:0)
我找到了答案。见下文。谢谢你的帮助。
Public Function UserHasAccess(ByVal GroupName)As Boolean
Dim oGroups As CSecurityGroups
Dim oGroup As CSecurityGroup
Dim oSecUser As CSecurityUser
Set oGroups = New CSecurityGroups
oGroups.Init REApplication.SessionContext
For Each oGroup In oGroups
If oGroup.Fields(SecurityGroup_fld_NAME) = GroupName Then
For Each oSecUser In oGroup.SecurityUsers
If Trim(oSecUser.Fields(SecurityUser_fld_USERS_ID)) = Trim(REApplication.SessionContext.CurrentUserID) Then
UserHasAccess = True
End If
Next oSecUser
End If
oGroup.Closedown
Next oGroup
oGroups.Closedown
Set oGroups = Nothing
Set oGroup = Nothing
Set oSecUser = Nothing
结束功能