Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ There are several ways to support Mautic other than contributing with code.
plugins/event_listeners
plugins/installation
plugins/data
plugins/roles_and_permissions
plugins/translations
plugins/continuous-integration
plugins/from-4-to-5
Expand Down
164 changes: 164 additions & 0 deletions docs/plugins/roles_and_permissions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
Roles and Permissions

Check warning on line 1 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Headings] 'Roles and Permissions' should use sentence-style capitalization. Raw Output: {"message": "[Google.Headings] 'Roles and Permissions' should use sentence-style capitalization.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 1, "column": 1}}}, "severity": "WARNING"}
###################

Mautic lets you define custom permissions for each Role. These permissions determine what Users can view or do within different parts of the system.

How Permissions Work

Check warning on line 6 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Headings] 'How Permissions Work' should use sentence-style capitalization. Raw Output: {"message": "[Google.Headings] 'How Permissions Work' should use sentence-style capitalization.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 6, "column": 1}}}, "severity": "WARNING"}
--------------------

Mautic assigns permissions using bit values. These bits double as they increase:

``1, 2, 4, 8, 16, 32, 64, 128...``

Bits should always follow this sequence. Avoid values like ``3`` or ``5`` because permission checks will fail.

Check warning on line 13 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Will] Avoid using 'will'. Raw Output: {"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 13, "column": 101}}}, "severity": "WARNING"}

Example permission set:

+--------------+-----+
| Permission | Bit |
+--------------+-----+
| view | 1 |
| edit | 2 |
| create | 4 |
| delete | 8 |
| full | 16 |
+--------------+-----+

A permission notation looks like this:

``plugin:helloWorld:worlds:view``

This checks the ``view`` permission for the ``worlds`` level of the plugin.

Check warning on line 31 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Plugin' instead of 'plugin'. Raw Output: {"message": "[Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Plugin' instead of 'plugin'.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 31, "column": 69}}}, "severity": "INFO"}

Check failure on line 31 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Vale.Terms] Use 'Plugin' instead of 'plugin'. Raw Output: {"message": "[Vale.Terms] Use 'Plugin' instead of 'plugin'.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 31, "column": 69}}}, "severity": "ERROR"}

How Bit Storage Works

Check warning on line 33 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Headings] 'How Bit Storage Works' should use sentence-style capitalization. Raw Output: {"message": "[Google.Headings] 'How Bit Storage Works' should use sentence-style capitalization.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 33, "column": 1}}}, "severity": "WARNING"}
~~~~~~~~~~~~~~~~~~~~~

Mautic stores permissions by adding the bits of all permissions assigned to a Role.

Examples:

* ``view`` + ``edit`` = ``1 + 2 = 3``
* ``view`` + ``create`` = ``1 + 4 = 5``

When checking a permission, Mautic verifies whether the bit exists within the stored sum.

The ``full`` permission should always use the highest bit. It automatically grants all lower permissions.

Using Permissions

Check warning on line 47 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Headings] 'Using Permissions' should use sentence-style capitalization. Raw Output: {"message": "[Google.Headings] 'Using Permissions' should use sentence-style capitalization.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 47, "column": 1}}}, "severity": "WARNING"}
-----------------

Use the Security service to check permissions.

Check warning on line 50 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.WordList] Use 'select' instead of 'check'. Raw Output: {"message": "[Google.WordList] Use 'select' instead of 'check'.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 50, "column": 29}}}, "severity": "WARNING"}

Example in Twig:

.. code-block:: twig

{% if security.isGranted('user:roles:edit') %}
{# User can edit roles #}
{% endif %}

Permission notation:

* Core bundles: ``bundle:level:permission``
* Plugins: ``plugin:bundle:level:permission``

Example:

``user:roles:view``

Creating Custom Permissions

Check warning on line 69 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Headings] 'Creating Custom Permissions' should use sentence-style capitalization. Raw Output: {"message": "[Google.Headings] 'Creating Custom Permissions' should use sentence-style capitalization.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 69, "column": 1}}}, "severity": "WARNING"}
---------------------------

Plugins can define their own Permission classes.

Each Permission class must:

* Extend ``Mautic\CoreBundle\Security\Permissions\AbstractPermissions``
* Implement ``__construct()``
* Implement ``buildForm()``
* Implement ``getName()``

Constructor
~~~~~~~~~~~

Inside ``__construct()``:

1. Call ``parent::__construct($params)`` or assign ``$this->params = $params``.
2. Define ``$this->permissions`` as an array of permission levels and bits.

Example level definition:

* Level: ``worlds``
* Permissions: ``use_telescope``, ``send_probe``, ``visit``, ``full``

Access check example:

Check warning on line 94 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.WordList] Use 'select' instead of 'check'. Raw Output: {"message": "[Google.WordList] Use 'select' instead of 'check'.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 94, "column": 8}}}, "severity": "WARNING"}

``plugin:helloWorld:worlds:send_probe``

Helper Methods for Permission Sets

Check warning on line 98 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Headings] 'Helper Methods for Permission Sets' should use sentence-style capitalization. Raw Output: {"message": "[Google.Headings] 'Helper Methods for Permission Sets' should use sentence-style capitalization.", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 98, "column": 1}}}, "severity": "WARNING"}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Mautic includes helper methods:

* ``addStandardPermissions()`` adds view, edit, create, delete, publish, full
* ``addExtendedPermissions()`` adds creator-based permissions
* ``addManagePermission()`` adds a single manage permission

buildForm()
~~~~~~~~~~~

``buildForm()`` adds permission fields to the Role form.

Available helpers:

* ``addStandardFormFields()``
* ``addExtendedFormFields()``
* ``addManageFormFields()``

getName()
~~~~~~~~~

This must return the bundle name in camelCase.

Check failure on line 121 in docs/plugins/roles_and_permissions.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'camelCase'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'camelCase'?", "location": {"path": "docs/plugins/roles_and_permissions.rst", "range": {"start": {"line": 121, "column": 37}}}, "severity": "ERROR"}

Example:

* Bundle: ``HelloWorldBundle``
* Method return value: ``helloWorld``
* File name: ``HelloWorldPermissions.php``

Permission Aliases
------------------

Use ``getSynonym()`` to map a permission name to another one.

Example:

``editown`` maps to ``edit`` if ``editown`` is not defined.

Analyzing Permissions Before Saving
-----------------------------------

Plugins can adjust permissions before saving.

Use:

``analyzePermissions()``

If a second pass is needed, return ``true``.
The next call will include ``$isSecondRound = true``.

Advanced Permission Checks
--------------------------

To override bit-based checking, extend:

``isGranted($userPermissions, $name, $level)``

Advanced Support Logic
----------------------

You can customize support checks by overriding:

``isSupported()``

Use this for backward compatibility or custom permission rules.
Loading