Imports System
Imports System.ComponentModel

Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering

Imports DevExpress.ExpressApp
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Persistent.Validation
Imports DevExpress.Persistent.Base.Security
Imports DevExpress.Utils

<DefaultClassOptions()> _
  Public Class SecuritySystemHelper
    Public Shared Function IsUserInRole(ByVal userWithRoles As IUserWithRoles, ByVal roleName As String) As Boolean
        'Guard.ArgumentNotNull(userWithRoles, "userWithRoles")
        If userWithRoles Is Nothing Then Return True
        For Each role As IRole In userWithRoles.Roles
            If role.Name = roleName Then
                Return True
            End If
        Next role
        Return False
    End Function
    Public Shared Function IsUserInRoleCurrentUser(ByVal roleName As String) As Boolean
        Return IsUserInRole(TryCast(SecuritySystem.CurrentUser, IUserWithRoles), roleName)
    End Function
    Public Shared Function IsUserInRole(ByVal roleName As String, ByVal user As User) As Boolean
        Return IsUserInRole(TryCast(user, IUserWithRoles), roleName)
    End Function
    Public Shared Function IsUserAdministrator(ByVal simpleUser As ISimpleUser) As Boolean
        Guard.ArgumentNotNull(simpleUser, "simpleUser")
        Return simpleUser.IsAdministrator
    End Function
End Class
