Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change filters to use $params as array #57

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Filters/PermissionFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PermissionFilter implements FilterInterface
* redirects, etc.
*
* @param \CodeIgniter\HTTP\RequestInterface $request
* @param array|null $params
*
* @return mixed
*/
Expand All @@ -38,8 +39,15 @@ public function before(RequestInterface $request, $params = null)
}

$authorize = Services::authorization();

if (! $authorize->hasPermission($params, $authenticate->id()))
$result = true;

// Check each requested permission
foreach ($params as $permission)
{
$result = $result && $authorize->hasPermission($permission, $authenticate->id());
}

if (! $result)
{
if ($authenticate->silent())
{
Expand Down
12 changes: 10 additions & 2 deletions src/Filters/RoleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class RoleFilter implements FilterInterface
* redirects, etc.
*
* @param \CodeIgniter\HTTP\RequestInterface $request
* @param array|null $params
*
* @return mixed
*/
Expand All @@ -38,8 +39,15 @@ public function before(RequestInterface $request, $params = null)
}

$authorize = Services::authorization();

if (! $authorize->inGroup($params, $authenticate->id()))
$result = true;

// Check each requested permission
foreach ($params as $group)
{
$result = $result && $authorize->inGroup($group, $authenticate->id());
}

if (! $result)
{
if ($authenticate->silent())
{
Expand Down