Skip to content

Commit

Permalink
Merge pull request #148 from szymach/3.2
Browse files Browse the repository at this point in the history
Better comparison for users on admin list batch action
  • Loading branch information
rn0 authored Feb 8, 2023
2 parents b066bf0 + 967cf4a commit c2c2496
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@
<argument type="collection"/>
<tag name="admin.element"/>
</service>

<!-- Twig -->
<service id="FSi\Bundle\AdminSecurityBundle\Twig\SecurityExtension">
<tag name="twig.extension" />
</service>

</services>

</container>
2 changes: 1 addition & 1 deletion Resources/views/Admin/datagrid.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{# pattern: datagrid_{grid_name}_column_name_{column_name}_cell #}
{% block datagrid_admin_security_user_column_name_batch_cell %}
<td>
{% if attribute(app.user, 'getId') is not defined or cell.value == app.user.id %}
{% if are_same_users(cell.source, app.user) %}
<input type="checkbox" disabled />
{% else %}
<input type="checkbox"
Expand Down
38 changes: 38 additions & 0 deletions Twig/SecurityExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* (c) FSi sp. z o.o. <[email protected]>
*
* 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<TwigFunction>
*/
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();
}
)
];
}
}

0 comments on commit c2c2496

Please sign in to comment.