My Store, part two: roles and permissions¶
This part decides who can do what. It assumes you built the application in part one.
In this part you will:
- Define permissions
- Group them into roles
- Require permissions on the controller actions of a form
- Decide what a user without the permission sees
How it fits together¶
A permission names one thing a user may do. A role is a set of permissions that you give to a user. Each controller action of a form lists the permissions that open it. A user can run the action if they hold at least one of its permissions.
For My Store, three permissions are enough:
| Permission | What it allows |
|---|---|
| CanViewStore | See products, suppliers and orders |
| CanManageStore | Change products, suppliers and orders |
| CanCreateOrders | Create orders |
and the roles are:
| Role | Permissions |
|---|---|
| Administrator | The system permissions Studio created (users, roles, permissions, operations, settings, application data) |
| Director | CanViewStore, CanManageStore, CanCreateOrders |
| Employee | CanViewStore, CanCreateOrders |
Create the permissions¶
In the Project Explorer open Configuration and then app. In the editor, under Security, choose Permissions. The table already holds the permissions of the built-in forms: ManageUsers, ManageRoles, ManagePermissions, ManageOperations, ManageSettings and ManageApplicationData.
Click Add... under the table, then edit the new row: type the name, and a description in words. Add CanViewStore, CanManageStore and CanCreateOrders. Save.
The page shows how to refer to a permission in code, for example Application.Permissions.ManageUsers.
Create the roles¶
Choose Roles. Administrator already exists. Click +, then the New Role button that appears. Name the role Director, add a description, then click the Permissions box and choose its permissions one after another: type to search, and press Enter to pick.
Click + twice
The first click on + only shows the New Role button. Click New Role to create the role. If you start typing before the new role is on the list, you change the role that was selected.
Add the Employee role the same way, with CanViewStore and CanCreateOrders. Save.
Require permissions on the forms¶
Open a form and its Controller tab. For each action, Available To All Authenticated is checked, which lets every signed-in user run it. To restrict an action:
- Select the action.
- Uncheck Available To All Authenticated. A Permissions box appears.
- Click the box and pick the permissions that may run the action.
For OrderForm:
| Action | Permissions |
|---|---|
| Add | CanCreateOrders, CanManageStore |
| Edit | CanViewStore, CanManageStore |
| Save | CanManageStore |
| Delete | CanManageStore |
Do the same for the other forms and for the lists. For ProductForm and SupplierForm, Add, Save and Delete take CanManageStore, and Edit takes CanViewStore and CanManageStore. For each list, choose CanViewStore and CanManageStore.
Note
A menu item is hidden from users who lack the permissions of the action it opens.
What a user without the permission sees¶
An employee can open an order, but should not see Save or Delete. Select the button on the form and, in Properties under Events, open the ... next to On Click. The window has the option If the user is not in role. It is set to Hide the element by default. You can choose to disable the button instead.
Do this for each button that runs a restricted action.
Try it¶
Save, validate and build, then create a user for each role and sign in as each of them:
- an administrator sees and does everything the administrator permissions allow
- a director views and edits products, suppliers and orders
- an employee views them and creates orders, without the Save and Delete buttons
You can manage roles and permissions from the running application. Open the user menu, then Administration, and choose Manage Roles or Permissions. Changing them needs a role that holds ManageRoles or ManagePermissions.




