Avoid totally rewriting of AccessRule::matchRole - try nr2 #380

This commit is contained in:
Lorenzo Milesi
2020-07-26 09:32:08 +02:00
parent 8adbffeb3f
commit a991801f3e
2 changed files with 13 additions and 29 deletions

View File

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