- Added method hasAtLeastOne to the library PermissionLib

- Adapted the method isAllowed of the library FiltersLib to use hasAtLeastOne
- Corrected/added comments
This commit is contained in:
Paolo
2018-06-29 11:51:16 +02:00
parent 2b15c88410
commit 2cba129076
4 changed files with 40 additions and 30 deletions
+34
View File
@@ -204,4 +204,38 @@ class PermissionLib
return $checkPermissions;
}
/**
* Checks if at least one of the permissions given as parameter (requiredPermissions) belongs to the authenticated user
* It checks the given permissions against a given method (controller method name) and a given permission type (R and/or W)
*/
public function hasAtLeastOne($requiredPermissions, $method, $permissionType)
{
$isAllowed = false; // by default is NOT allowed
// If the parameter requiredPermissions is NOT given, then no one is allow to use this FilterWidget
if ($requiredPermissions != null)
{
// If requiredPermissions is NOT an array then converts it to an array
if (!is_array($requiredPermissions))
{
$requiredPermissions = array($requiredPermissions);
}
// Checks if at least one of the permissions given as parameter belongs to the authenticated user...
for ($p = 0; $p < count($requiredPermissions); $p++)
{
$isAllowed = $this->_ci->permissionlib->isEntitled(
array(
$method => $requiredPermissions[$p].':'.$permissionType
),
$method
);
if ($isAllowed === true) break; // ...if confirmed then is allowed to use this FilterWidget
}
}
return $isAllowed;
}
}