Page 1 of 1

How to determine a users permissions

PostPosted: Wed Nov 19, 2008 1:45 pm
by Mike.Sheen
Here's some code examples on how you would determine permissions for a user.

All these examples assume you have access to the MDIParent object, which has some publicly exposed methods to readily get a permission. If you don't (ie: you're not using breakouts, but your own custom app, then you need to create a staff maintenance business logic object to achieve the same result).

Example 1 - Get form load permission for particular form
Code: Select all
   
Dim lPermission
' FormNumber is a number - it references the FormNo column in the SY_Forms table
lPermission = MDIParentObject.GetFormPermission(FormNumber)
    Select Case lPermission
        Case 0, 3   'not configured, denied
        Case 1      'read only
        Case 2      'read + write
    End Select


Example 2 - Get permission for particular form's tab
Code: Select all
   
Dim lPermission
Dim lTabKey
' FormNumber is a number - it references the FormNo column in the SY_Forms table
' lTabKey is a string it is the tab key for the tab on the form
lTabKey = "Notes"
lPermission = MDIParentObject.GetFormPermission(FormNumber, lTabKey)
    Select Case lPermission
        Case 0, 3   'not configured, denied
        Case 1      'read only
        Case 2      'read + write
    End Select


Example 3 - Get permission for particular form's sub-tab within a tab
Code: Select all
   
Dim lPermission
Dim lTabKey
Dim lSubTabKey
' FormNumber is a number - it references the FormNo column in the SY_Forms table
' lTabKey is a string it is the tab key for the tab on the form
lTabKey = "Other"
lSubTabKey = "Custom"
lPermission = MDIParentObject.GetFormPermission(FormNumber, lTabKey, lSubTabKey )
    Select Case lPermission
        Case 0, 3   'not configured, denied
        Case 1      'read only
        Case 2      'read + write
    End Select


Example 4 - Get a Global Switch permission
Code: Select all
    lPermission = MDIParentObject.GetSwitchPermission("inventory - view cost price")
    Select Case lPermission
        Case 0, 3   'not configured, denied
        Case 2      'read + write
    End Select


And to create these permissions, here's the TSQL :

Example 5 - Create a Global Switch
The following code will cause a switch to appear in the Role Maintenance, under the Global Switches tab - you should see a new node appear in the tree "My Module", with a switch named "My Switch"
Code: Select all
INSERT INTO SY_SwitchSections
SELECT NewID(),
'My Module',
'My Module',
'2008-11-19'
GO

INSERT INTO SY_Switches
SELECT NewID(),
'My Switch,
'My Module',
'2008-11-19'
GO


Example 6 - Add a permission to a form
This example adds a "tab" permission to the sales order entry form, for a new tab named "Test". Note this does NOT cause the tab to be added to the sales order form (you would need a breakout to do that), but it merely provides a permission the user can set via Role Maintenance.
Code: Select all
INSERT INTO HR_RolePermissions
SELECT '0835EBED-A299-4F79-82CC-FE5D53FB19FD',
(SELECT RolePermissionID FROM HR_RolePermissions WHERE ObjectID = '300' AND
RoleID = (SELECT RoleID FROM HR_Roles WHERE RoleName = 'Administrator')),
(SELECT RoleID FROM HR_Roles WHERE RoleName = 'Administrator'),
'Test', 'Tab', 2, '2008-11-04'