Skip to content

Commit

Permalink
Revert "Avoid totally rewriting of AccessRule::matchRole #380"
Browse files Browse the repository at this point in the history
This reverts commit 78bd5f9.
  • Loading branch information
maxxer committed Apr 27, 2020
1 parent 78bd5f9 commit 8adbffe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# CHANGELOG

## work in progress
- Fix #380: Avoid rewriting AccessRule::matchRole (maxxer)
- Fix #378: Add module attribute 'disableIpLogging' (jkmssoft)

## 1.5.1 April 5, 2020
Expand Down
37 changes: 27 additions & 10 deletions src/User/Filter/AccessRuleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,38 @@ public function allows($action, $user, $request)

/**
* {@inheritdoc}
**/
* */
protected function matchRole($user)
{
if (empty($this->roles)) {
return parent::matchRole($user);
return true;
}

// We just check our custom role "admin" otherwise call back the original implementation
if (!in_array("admin", $this->roles)) {
return parent::matchRole($user);
}
/** @var User $identity */
$identity = $user->getIdentity();
if (!$user->getIsGuest() && $identity->getIsAdmin()) {
return true;
foreach ($this->roles as $role) {
if ($role === '?') {
if ($user->getIsGuest()) {
return true;
}
} elseif ($role === '@') {
if (!$user->getIsGuest()) {
return true;
}
} elseif ($role === 'admin') {
/** @var User $identity */
$identity = $user->getIdentity();

if (!$user->getIsGuest() && $identity->getIsAdmin()) {
return true;
}
} else {
$roleParams = $this->roleParams instanceof Closure
? call_user_func($this->roleParams, $this)
: $this->roleParams;

if ($user->can($role, $roleParams)) {
return true;
}
}
}

return false;
Expand Down

0 comments on commit 8adbffe

Please sign in to comment.