Skip to content

Abilities (Brezel 3.x)

Abilities are permissions that are not tied to a module, for example whether users may use API keys. Like module permissions, they are granted per role and are off by default.

AbilityGrants
api_keysCreating, reactivating and authenticating with API keys

Set them in the abilities field of a role:

integration.bake.json
[{
"resource_entity": "integration_role",
"resource": {
"module": "roles",
"fields": {
"name": "Integration",
"slug": "integration",
"abilities": {
"api_keys": true
},
"modules": false
}
}
}]

A role has an ability if it sets it to true, if it has full access ("modules": true), or if one of its parent roles has it. Root users have all abilities.

The permissions widget shows the abilities of a role above the module matrix. To make them editable, add an abilities field to your roles module, just like the modules field:

roles.bake.json
[{
"resource_module": "roles",
"resource": {
"identifier": "roles",
"type": "roles",
"title": "name",
"fields": [
{ "identifier": "name" },
{ "identifier": "slug" },
{ "identifier": "modules", "type": "code" },
{
"identifier": "abilities",
"type": "code"
}
]
}
}]

Without this field, the abilities are shown read-only.

You can declare your own abilities with the abilities option of that field. They behave exactly like built-in ones and appear in the permissions widget:

roles.bake.json
{
"identifier": "abilities",
"type": "code",
"options": {
"abilities": ["export_pdf", "see_purchase_prices"]
}
}

Labels are taken from the translation modules.<roles module>.abilities.<name>, e.g. modules.roles.abilities.export_pdf.

Check abilities with the hasAbility recipe function, e.g. to hide a button:

{
"type": "buttons",
"options": {"buttons": [{"title":"Export PDF","identifier":"export_pdf","options":{"recipes":{"display":"hasAbility('export_pdf')"}}}]}
}