First create solution
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
Partial Class NavigationItemPermission
|
||||
<System.Diagnostics.DebuggerNonUserCode()> _
|
||||
Public Sub New(ByVal Container As System.ComponentModel.IContainer)
|
||||
MyClass.New()
|
||||
|
||||
'Required for Windows.Forms Class Composition Designer support
|
||||
Container.Add(Me)
|
||||
|
||||
End Sub
|
||||
|
||||
'Component overrides dispose to clean up the component list.
|
||||
<System.Diagnostics.DebuggerNonUserCode()> _
|
||||
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
|
||||
If disposing AndAlso components IsNot Nothing Then
|
||||
components.Dispose()
|
||||
End If
|
||||
MyBase.Dispose(disposing)
|
||||
End Sub
|
||||
|
||||
'Required by the Component Designer
|
||||
Private components As System.ComponentModel.IContainer
|
||||
|
||||
'NOTE: The following procedure is required by the Component Designer
|
||||
'It can be modified using the Component Designer.
|
||||
'Do not modify it using the code editor.
|
||||
<System.Diagnostics.DebuggerStepThrough()> _
|
||||
Private Sub InitializeComponent()
|
||||
components = New System.ComponentModel.Container()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
@@ -0,0 +1,126 @@
|
||||
Imports System
|
||||
Imports System.ComponentModel
|
||||
Imports System.Collections.Generic
|
||||
Imports System.Diagnostics
|
||||
Imports System.Text
|
||||
|
||||
Imports DevExpress.ExpressApp
|
||||
Imports DevExpress.ExpressApp.Actions
|
||||
Imports DevExpress.Persistent.Base
|
||||
|
||||
Imports DevExpress.ExpressApp.SystemModule
|
||||
Imports DevExpress.Xpo
|
||||
Imports DevExpress.Data.Filtering
|
||||
|
||||
|
||||
Public Class NavigationItemPermission
|
||||
Inherits DevExpress.ExpressApp.WindowController
|
||||
Private _navigationController As ShowNavigationItemController
|
||||
Private _ID As Long = 1
|
||||
Public Sub New()
|
||||
MyBase.New()
|
||||
|
||||
'This call is required by the Component Designer.
|
||||
InitializeComponent()
|
||||
RegisterActions(components)
|
||||
|
||||
End Sub
|
||||
Protected Overrides Sub OnFrameAssigned()
|
||||
|
||||
MyBase.OnFrameAssigned()
|
||||
'_navigationController = Frame.GetController(Of ShowNavigationItemController)()
|
||||
'If _navigationController IsNot Nothing Then
|
||||
' AddHandler _navigationController.ItemsInitialized, AddressOf ItemsInitialized
|
||||
'End If
|
||||
End Sub
|
||||
Protected Overrides Sub OnActivated()
|
||||
MyBase.OnActivated()
|
||||
End Sub
|
||||
|
||||
Private Sub ItemsInitialized(sender As Object, e As EventArgs)
|
||||
Dim _ChoiceActionItem As ChoiceActionItem
|
||||
Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
|
||||
Dim _uow As New UnitOfWork(_onew.Session.DataLayer)
|
||||
Dim _NavigationItemRole_Collection As XPCollection(Of NavigationItemRole) = New XPCollection(Of NavigationItemRole)(_onew.Session, CriteriaOperator.Parse("1=1"))
|
||||
|
||||
|
||||
_uow.Delete(New XPCollection(Of ModelNavigation)(_uow))
|
||||
_uow.CommitChanges()
|
||||
|
||||
For Each _ChoiceActionItem In _navigationController.ShowNavigationItemAction.Items
|
||||
|
||||
RecursiveSetPermission(_ChoiceActionItem, _NavigationItemRole_Collection)
|
||||
If SecuritySystem.CurrentUserName = "SysAdmin" Then
|
||||
RecursiveAddModelNavigation(_uow, Nothing, _ChoiceActionItem)
|
||||
End If
|
||||
Next
|
||||
_uow.CommitChanges()
|
||||
|
||||
End Sub
|
||||
|
||||
Sub RecursiveSetPermission(_ChoiceActionItem As ChoiceActionItem, _NavigationItemRole_Collection As XPCollection(Of NavigationItemRole))
|
||||
Dim _NavigationItemRole As NavigationItemRole
|
||||
Dim _ChoiceActionItem_Child As ChoiceActionItem
|
||||
|
||||
If _ChoiceActionItem.Items.Count > 0 Then
|
||||
For Each _ChoiceActionItem_Child In _ChoiceActionItem.Items
|
||||
RecursiveSetPermission(_ChoiceActionItem_Child, _NavigationItemRole_Collection)
|
||||
Next
|
||||
End If
|
||||
If _ChoiceActionItem.Id = "@NavigationItemPermission" Then
|
||||
If SecuritySystem.CurrentUserName <> "SysAdmin" Then
|
||||
_ChoiceActionItem.Active.SetItemValue("", False)
|
||||
End If
|
||||
End If
|
||||
For Each _NavigationItemRole In _NavigationItemRole_Collection
|
||||
If _NavigationItemRole.ChoiceActionItemId = _ChoiceActionItem.Id Then
|
||||
If _NavigationItemRole.Role IsNot Nothing Then
|
||||
If SecuritySystemHelper.IsUserInRoleCurrentUser(_NavigationItemRole.Role.Name) Then
|
||||
_ChoiceActionItem.Active.SetItemValue("", False)
|
||||
End If
|
||||
End If
|
||||
If _NavigationItemRole.SubcontractorRoles IsNot Nothing Then
|
||||
Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
|
||||
Dim _SubcontractorUserRoles_Collection As New XPCollection(Of SubcontractorUserRoles)(_onew.Session, CriteriaOperator.Parse("User.Oid=?", TryCast(SecuritySystem.CurrentUser, DevExpress.Persistent.BaseImpl.User).Oid))
|
||||
|
||||
For Each _SubcontractorUserRoles As SubcontractorUserRoles In _SubcontractorUserRoles_Collection
|
||||
If _NavigationItemRole.SubcontractorRoles.Oid = _SubcontractorUserRoles.SubcontractorRoles.Oid Then
|
||||
_ChoiceActionItem.Active.SetItemValue("", False)
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
If _NavigationItemRole.SupportRoles IsNot Nothing Then
|
||||
Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
|
||||
Dim _SupportUserRoles_Collection As New XPCollection(Of SupportUserRoles)(_onew.Session, CriteriaOperator.Parse("User.Oid=?", TryCast(SecuritySystem.CurrentUser, DevExpress.Persistent.BaseImpl.User).Oid))
|
||||
|
||||
For Each _SupportUserRoles As SupportUserRoles In _SupportUserRoles_Collection
|
||||
If _NavigationItemRole.SupportRoles.Oid = _SupportUserRoles.SupportRoles.Oid Then
|
||||
_ChoiceActionItem.Active.SetItemValue("", False)
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
End Sub
|
||||
Sub RecursiveAddModelNavigation(_uow As UnitOfWork, _ModelNavigationParent As ModelNavigation, _ChoiceActionItem As ChoiceActionItem)
|
||||
Dim _ModelNavigation As ModelNavigation
|
||||
Dim _ChoiceActionItem_Child As ChoiceActionItem
|
||||
|
||||
_ID += 1
|
||||
_ModelNavigation = New ModelNavigation(_uow)
|
||||
|
||||
_ModelNavigation.Parent = _ModelNavigationParent
|
||||
_ModelNavigation.Name = _ChoiceActionItem.Id
|
||||
_ModelNavigation.Navigation_Caption = _ChoiceActionItem.Caption
|
||||
_ModelNavigation.Navigation_ImageName = _ChoiceActionItem.ImageName
|
||||
|
||||
If _ChoiceActionItem.Items.Count > 0 Then
|
||||
For Each _ChoiceActionItem_Child In _ChoiceActionItem.Items
|
||||
RecursiveAddModelNavigation(_uow, _ModelNavigation, _ChoiceActionItem_Child)
|
||||
Next
|
||||
End If
|
||||
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
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
|
||||
|
||||
<DefaultClassOptions(), NavigationItem(False), CreatableItem(False)> _
|
||||
Public Class NavigationItemRole
|
||||
Inherits BaseObject
|
||||
|
||||
Private _ChoiceActionItemId As String
|
||||
Private _Role As Role
|
||||
Private _SubcontractorRoles As SubcontractorRoles
|
||||
Private _SupportRoles As SupportRoles
|
||||
|
||||
Public Sub New(ByVal session As Session)
|
||||
MyBase.New(session)
|
||||
End Sub
|
||||
Public Overrides Sub AfterConstruction()
|
||||
MyBase.AfterConstruction()
|
||||
End Sub
|
||||
|
||||
<ImmediatePostData(True), DataSourceProperty("ChoiceActionItemId_DataSourceProperty")>
|
||||
Property ChoiceActionItemId As String
|
||||
Get
|
||||
Return _ChoiceActionItemId
|
||||
End Get
|
||||
Set(value As String)
|
||||
SetPropertyValue("ChoiceActionItemId", _ChoiceActionItemId, value)
|
||||
End Set
|
||||
End Property
|
||||
Property Role As Role
|
||||
Get
|
||||
Return _Role
|
||||
End Get
|
||||
Set(value As Role)
|
||||
SetPropertyValue("Role", _Role, value)
|
||||
End Set
|
||||
End Property
|
||||
Property SubcontractorRoles As SubcontractorRoles
|
||||
Get
|
||||
Return _SubcontractorRoles
|
||||
End Get
|
||||
Set(value As SubcontractorRoles)
|
||||
SetPropertyValue("SubcontractorRoles", _SubcontractorRoles, value)
|
||||
End Set
|
||||
End Property
|
||||
Property SupportRoles As SupportRoles
|
||||
Get
|
||||
Return _SupportRoles
|
||||
End Get
|
||||
Set(value As SupportRoles)
|
||||
SetPropertyValue("SupportRoles", _SupportRoles, value)
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
Reference in New Issue
Block a user