This lesson will guide you through using the static SecuritySystem class to check whether or not a user has particular permission. The SetTask Action will be accessible to users who have permission to modify DemoTask objects.
Before proceeding, we recommend that you review the following lessons.
Open the TaskActionsController.cs (TaskActionsController.vb) file you created in the Add an Action with Option Selection lesson. Add the "using" directive and modify the Activated event handler as shown below.
Partial Public Class TaskActionsController
Private Sub TaskActionsController_Activated(ByVal sender As Object, ByVal e As EventArgs)
AddHandler View.SelectionChanged, AddressOf View_SelectionChanged
Private Sub View_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
Private Sub UpdateSetTaskActionState()
Dim isGranted As Boolean = True
For Each selectedObject As Object In View.SelectedObjects
Dim isPriorityGranted As Boolean = SecuritySystem.IsGranted(_
New PermissionRequest(ObjectSpace, GetType(DemoTask), SecurityOperations.Write, selectedObject, "Priority"))
Dim isStatusGranted As Boolean = SecuritySystem.IsGranted(_
New PermissionRequest(ObjectSpace, GetType(DemoTask), SecurityOperations.Write, selectedObject, "Status"))
If (Not isPriorityGranted) OrElse (Not isStatusGranted) Then
isGranted = False
With the added code, the Set Task Action will be activated for users who have write permissions for the Priority and Status properties of the selected DemoTask objects.
Add a user who does not have permission to modify the DemoTask objects (see Using the Security System). Run the application as this new user. The Set Task Action will not be visible when you display the Demo Task List View.
This is the last lesson of the Comprehensive Tutorial. To learn more about the main concepts for building business applications and extending XAF tools, refer to the Concepts section. If you need task-based help, take a look at the Task-Based Help section. To learn how to deploy XAF applications, review the Deployment Tutorial.