|
13 | 13 | use Ubiquity\security\acl\models\Resource;
|
14 | 14 | use Ubiquity\security\acl\models\Role;
|
15 | 15 | use Ubiquity\security\acl\persistence\AclCacheProvider;
|
| 16 | +use Ubiquity\controllers\Router; |
16 | 17 |
|
17 | 18 | /**
|
18 | 19 | * Ubiquity\security\acl$AclManager
|
@@ -186,6 +187,30 @@ public static function addAndAllow(string $role, ?string $resource = '*', ?strin
|
186 | 187 | public static function isAllowed(string $role, ?string $resource = '*', ?string $permission = 'ALL'): bool {
|
187 | 188 | return self::$aclList->isAllowed($role, $resource ?? '*', $permission ?? 'ALL');
|
188 | 189 | }
|
| 190 | + |
| 191 | + public static function isAllowedRoute(string $role,string $routeName){ |
| 192 | + $routeInfo=Router::getRouteInfoByName($name); |
| 193 | + if (!isset ( $routeDetails ['controller'] )) { |
| 194 | + $routeInfo=current($routeInfo); |
| 195 | + } |
| 196 | + $controller=$routeInfo['controller']??null; |
| 197 | + $action=$routeInfo['action']??null; |
| 198 | + if(isset($controller) && isset($action)){ |
| 199 | + $resourceController = self::getPermissionMap ()->getRessourcePermission ( $controller, $action ); |
| 200 | + if (isset ( $resourceController )) { |
| 201 | + try{ |
| 202 | + if (self::isAllowed ( $role, $resourceController ['resource'], $resourceController ['permission'] )) { |
| 203 | + return true; |
| 204 | + } |
| 205 | + } |
| 206 | + catch(AclException $e){ |
| 207 | + //Nothing to do |
| 208 | + } |
| 209 | + } |
| 210 | + return false; |
| 211 | + } |
| 212 | + return false; |
| 213 | + } |
189 | 214 |
|
190 | 215 | /**
|
191 | 216 | * Save all acls,roles, resources and permissions for AclProviders with no autoSave.
|
|
0 commit comments