diff --git a/Resources/config/services.xml b/Resources/config/services.xml index bf17459d..479f87d8 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -243,6 +243,12 @@ + + + + + + diff --git a/Resources/views/Admin/datagrid.html.twig b/Resources/views/Admin/datagrid.html.twig index a5c14a2f..2227a29e 100644 --- a/Resources/views/Admin/datagrid.html.twig +++ b/Resources/views/Admin/datagrid.html.twig @@ -4,7 +4,7 @@ {# pattern: datagrid_{grid_name}_column_name_{column_name}_cell #} {% block datagrid_admin_security_user_column_name_batch_cell %} - {% if attribute(app.user, 'getId') is not defined or cell.value == app.user.id %} + {% if are_same_users(cell.source, app.user) %} {% else %} + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace FSi\Bundle\AdminSecurityBundle\Twig; + +use Symfony\Component\Security\Core\User\UserInterface; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; + +final class SecurityExtension extends AbstractExtension +{ + /** + * @return array + */ + public function getFunctions(): array + { + return [ + new TwigFunction( + 'are_same_users', + static function (UserInterface $a, UserInterface $b): bool { + if (false === $a instanceof $b && false === $b instanceof $a) { + return false; + } + + return $a->getUsername() === $b->getUsername(); + } + ) + ]; + } +}