Capability voters

Many frontend features are gated through the capability system. Backends contribute implementations of ICapabilityVoter to enable or disable actions per resource type. This page documents the inputs seen by a voter and the capabilities currently queried by the UI.

1. How voting works

In order to use the capability voters, you have to depend on the module sirius-components-capabilities. It provides the ICapabilityEvaluator which will check every capability voter available to figure out if a capability is available or not. For that, it will ask every capability voter to vote and consider the result. A capability voter can abstain, grant the capability or deny it. All those who abstain will be ignored. A capability will be available only if every non-abstaining capability voter has granted the capability.

If all capability voters have abstained from the vote, then we will leverage the IDefaultCapabilityEvaluator to have a default value. By default, Sirius Web will return true for all possible capability checks. To change this behavior and deny everything by default, just provide an implementation of IDefaultCapabilityEvaluator returning false.

ICapabilityVoter#vote(type, identifier, capability): CapabilityVote receives:

  • type — identifies the resource category (for example Project or ProjectSettings#images).

  • identifier — optional resource identifier; when the capability applies to a specific instance it contains the project/library id, otherwise it is null.

  • capability — the action being tested (for example canCreate).

Return CapabilityVote.GRANTED to enable the feature, or CapabilityVote.DENIED to disable it. It is critical to return CapabilityVote.ABSTAIN if your capability voter does not need to take part to the vote.

2. Supported capabilities

2.1. Projects collection

  • type: Project

  • identifier: null

  • capability:

    • canList — display the projects browser.

    • canCreate — show the “New project” command.

    • canUpload — allow ZIP uploads.

2.2. Individual project

  • type: Project

  • identifier: project id

  • capability:

    • canDownload

    • canRename

    • canDelete

    • canEdit — toggles read-only mode.

    • canView

2.3. Project style customizations

  • type: Project

  • identifier: project id

  • capability: canUpdateStyleCustomizationsState — whether project style customization can be enabled or disabled.

2.4. Libraries collection

  • type: Library

  • identifier: null

  • capability: canList

2.5. Individual library

  • type: Library

  • identifier: {namespace}:{name}:{version}

  • capability: canView

2.6. Project settings view

  • type: ProjectSettings

  • identifier: project id

  • capability: canView — whether the settings entry is visible.

Add your own type strings for custom tabs so voters can distinguish them. Each tab contributed through projectSettingsTabExtensionPoint has its own type. For example, the image settings tab uses ProjectSettings#images.

2.7. Project settings tabs

  • type: ProjectSettings#images

  • identifier: project id

  • capability: canView

2.8. Project General Settings

  • type: ProjectSettings#general

  • identifier: project id

  • capability: canView