Skip to content

[Security] Add docs for is_granted_for_user() function #20505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2025
Merged
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
21 changes: 21 additions & 0 deletions reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@
Optionally, an object can be passed to be used by the voter. More information
can be found in :ref:`security-template`.

is_granted_for_user
~~~~~~~~~~~~~~~~~~~

.. code-block:: twig

{{ is_granted_for_user(user, attribute, subject = null, field = null) }}

Check failure on line 182 in reference/twig_reference.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Twig] Unknown "is_granted_for_user" function.

``user``
**type**: ``object``
``attribute``
**type**: ``string``
``subject`` *(optional)*
**type**: ``object``
``field`` *(optional)*
**type**: ``string``

Returns ``true`` if the user is authorized for the specified attribute.

Optionally, an object can be passed to be used by the voter. More information
can be found in :ref:`security-template`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a versionadded directive ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done while merging: ddf1ad3

Thanks!

logout_path
~~~~~~~~~~~

Expand Down
11 changes: 11 additions & 0 deletions security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2549,6 +2549,17 @@

.. _security-isgranted:

Similarly, if you want to check if a specific user has a certain role, you can use
the built-in ``is_granted_for_user()`` helper function:

.. code-block:: html+twig

{% if is_granted_for_user(user, 'ROLE_ADMIN') %}

Check failure on line 2557 in security.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Twig] Unknown "is_granted_for_user" function.
<a href="...">Delete</a>
{% endif %}

.. _security-isgrantedforuser:

Securing other Services
.......................

Expand Down
Loading