Skip to content

Policies and roles

Two ideas answer the question who may do what? A role is something a person holds, such as Shopper or SalesManager. A policy is a named rule that admits some callers and turns the rest away, such as CanWorkOrders, which admits a SalesRep or a SalesManager.

Both belong to the whole application, not to one domain. Commands and queries ask for a policy by name, so a rule is written once and every command that needs it points at it.

Roles are managed in the application’s settings.

  1. In the project drawer, select the gear on the application row to open Application Settings.
  2. Open the Roles tab.
  3. Select Add Role, enter a Name and a Description, and select Add.
The Roles tab of Application Settings for Acme Sales with its list of roles and an Add Role button
The Roles tab of Application Settings. Personas, policies and specifications all choose from this list.

To remove a role, select Remove beside it and confirm. Roles are used by personas, by policies and by specifications that name a caller’s roles.

Policies live on their own canvas under the application.

  1. In the project drawer, select Policies under your application.
  2. Select Add Policy. A card named NewPolicy appears. If that name is taken, the new one is numbered, such as NewPolicy2.
  3. Double-click the name and type what the application calls it, for example IsSalesManager. Press Enter.
  4. Select Edit policy. In the Requirement pane, select Add condition and choose its type: Authenticated, Role or Claim.
  5. Select Save requirement.

The card shows the requirement the way Screenplay writes it, such as role "SalesManager", so what you read on the canvas is what the model says. A policy with no conditions yet says so, instead of showing an empty box.

The Policies canvas of Acme Sales with purple cards IsAuthenticated, IsShopper, IsMerchandiser, IsSalesRep, IsSalesManager and CanWorkOrders, each showing its requirement
The Policies canvas of Acme Sales. CanWorkOrders admits a SalesRep or a SalesManager.

Select Add group to combine conditions. Groups are joined by and or or. A group with more than one condition is shown in parentheses. For example, a policy can admit an accountant, or anyone whose department claim matches the department of the invoice.

When a rule is more than conditions can say, a policy can be decided by custom logic instead. The card then shows C# decides, and Edit description and logic opens an editor with the description beside the code. This is a developer’s task, and most policies need only conditions.

You do not apply a policy on this canvas. Commands and queries (or their feature or module) ask for a policy by name where you model them on the event model board. A persona can also state the policies that describe it.

  • Add Sticky Note puts a note anywhere on the canvas, in any of six colors.
  • Arrange, the last tool in the toolbar, tidies the cards into columns.
  • To remove a policy, select the cross in its header. You are asked first, because commands and queries may be asking for it by name.