Skip to content

Commit 8f549c6

Browse files
author
Jeremiah VALERIE
committed
Merge branch 'add_expression_hasAnyPermission'
2 parents 751b2f8 + 947d33d commit 8f549c6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ExpressionLanguage/AuthorizationExpressionProvider.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ public function getFunctions()
7474
}, function (array $variables, $object, $permission) {
7575
return $variables['container']->get('security.authorization_checker')->isGranted($permission, $object);
7676
}),
77+
78+
new ExpressionFunction('hasAnyPermission', function ($object, array $permissions) {
79+
$compiler = 'false';
80+
foreach ($permissions as $permission) {
81+
$compiler .= ' || ';
82+
$compiler .= sprintf('$authChecker->isGranted("%s", $object)', $permission);
83+
}
84+
85+
return $compiler;
86+
}, function (array $variables, $object, array $permissions) {
87+
foreach ($permissions as $permission) {
88+
if ($variables['container']->get('security.authorization_checker')->isGranted($permission, $object)) {
89+
return true;
90+
}
91+
}
92+
93+
return false;
94+
}),
7795
];
7896
}
7997
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ boolean **isRememberMe**() | Checks whether the token is remember me. | @=isReme
697697
boolean **isFullyAuthenticated**() | Checks whether the token is fully authenticated. | @=isFullyAuthenticated()
698698
boolean **isAuthenticated**() | Checks whether the token is not anonymous. | @=isAuthenticated()
699699
boolean **hasPermission**(mixed $var, string $permission) | Checks whether the token has the given permission for the given object (requires the ACL system). |@=hasPermission(object, 'OWNER')
700+
boolean **hasAnyPermission**(mixed $var, array $permissions) | Checks whether the token has any of the given permissions for the given object | @=hasAnyPermission(object, ['OWNER', 'ADMIN'])
700701

701702
**c)** Variables description
702703

0 commit comments

Comments
 (0)