Skip to content

Commit e240333

Browse files
committed
add isAllowedRoute
1 parent b1977a6 commit e240333

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Ubiquity/security/acl/AclManager.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Ubiquity\security\acl\models\Resource;
1414
use Ubiquity\security\acl\models\Role;
1515
use Ubiquity\security\acl\persistence\AclCacheProvider;
16+
use Ubiquity\controllers\Router;
1617

1718
/**
1819
* Ubiquity\security\acl$AclManager
@@ -186,6 +187,30 @@ public static function addAndAllow(string $role, ?string $resource = '*', ?strin
186187
public static function isAllowed(string $role, ?string $resource = '*', ?string $permission = 'ALL'): bool {
187188
return self::$aclList->isAllowed($role, $resource ?? '*', $permission ?? 'ALL');
188189
}
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+
}
189214

190215
/**
191216
* Save all acls,roles, resources and permissions for AclProviders with no autoSave.

0 commit comments

Comments
 (0)