Plugin Sample - Restrict actions based on permissions

Samples and Examples of using the Jiwa 7 framework - including plugins, stand-alone applications and scripts.

Plugin Sample - Restrict actions based on permissions

Postby Mike.Sheen » Mon Oct 20, 2014 10:29 am

Quite often it will be desirable to allow or disallow actions based on a permission.

Permissions In Jiwa 7 are quite easy to extend and offer powerful yet simple control. Permissions are always applied to a user group, and the users resultant permission is calculated based on the permission for all groups the user belongs to, as well as the default permission for each group.

By default the "Default Permission" for each group is simply "Undefined". That means that group does not contribute to the resultant permission for a user. When calculating a users permission, the user must belong to at least one group where the permission is allow, and no groups where the permission is disallow.

Attached is a sample plugin which adds an Abstract permission to sales orders controlling if the user is able to remove lines from the sales order. In order for this plugin to work, an entry into the table SY_FormsAbstractPermissions must be made:

Code: Select all
INSERT INTO SY_FormsAbstractPermissions(RecID, SY_Forms_ClassName, Name, Description, ItemNo)
SELECT NewID(), 'JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm', 'Remove Sales Order Line', 'Allow removal of sales order lines',
(SELECT MAX(ItemNo) + 1 FROM SY_FormsAbstractPermissions WHERE SY_Forms_ClassName = 'JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm')


The plugin itself is quite simple - the only logic is as follows:
Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
   Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)            
   AddHandler salesOrderForm.SalesOrder.SalesOrderLines.Removing, AddressOf SalesOrderLines_Removing
End Sub

Public Sub SalesOrderLines_Removing(SalesOrderLine As JiwaSales.SalesOrder.SalesOrderLine)
   Dim permission As JiwaApplication.Security.UserGroup.AccessLevels = JiwaApplication.Manager.Instance.Staff.GetAbstractPermission("JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm", "Remove Sales Order Line")
   
   If permission <> JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
      Throw New JiwaApplication.Exceptions.ClientCancelledException
   End If
End Sub


The new "Remove Sales Order Line" abstract permission for each group is set by loading the sales order entry form, and on the utilities tab of the ribbon selection the set permission tool. This will load the permissions dialog, and you can select which group you are editing and on the abstract permissions tab of the form set the appropriate values.

Permissions.JPG
Permission Screen


Plugin Cancel Sales Order Line Remove.xml
Sample Plugin
(32.8 KiB) Downloaded 210 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Return to Samples and Examples

Who is online

Users browsing this forum: No registered users and 2 guests