Revert "Avoid totally rewriting of AccessRule::matchRole #380"

This reverts commit 78bd5f9de8.
This commit is contained in:
Lorenzo Milesi
2020-04-27 08:12:13 +02:00
parent 78bd5f9de8
commit 8adbffeb3f
2 changed files with 27 additions and 11 deletions

View File

@ -1,7 +1,6 @@
# CHANGELOG # CHANGELOG
## work in progress ## work in progress
- Fix #380: Avoid rewriting AccessRule::matchRole (maxxer)
- Fix #378: Add module attribute 'disableIpLogging' (jkmssoft) - Fix #378: Add module attribute 'disableIpLogging' (jkmssoft)
## 1.5.1 April 5, 2020 ## 1.5.1 April 5, 2020

View File

@ -48,21 +48,38 @@ class AccessRuleFilter extends AccessRule
/** /**
* {@inheritdoc} * {@inheritdoc}
**/ * */
protected function matchRole($user) protected function matchRole($user)
{ {
if (empty($this->roles)) { if (empty($this->roles)) {
return parent::matchRole($user); return true;
} }
// We just check our custom role "admin" otherwise call back the original implementation foreach ($this->roles as $role) {
if (!in_array("admin", $this->roles)) { if ($role === '?') {
return parent::matchRole($user); if ($user->getIsGuest()) {
} return true;
/** @var User $identity */ }
$identity = $user->getIdentity(); } elseif ($role === '@') {
if (!$user->getIsGuest() && $identity->getIsAdmin()) { if (!$user->getIsGuest()) {
return true; 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; return false;