mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some simplification.
This commit is contained in:
parent
f7d06b9759
commit
6f08482aaf
21
app/User.php
21
app/User.php
@ -129,35 +129,18 @@ class User extends Authenticatable
|
|||||||
*
|
*
|
||||||
* Full credit goes to: https://github.com/Zizaco/entrust
|
* Full credit goes to: https://github.com/Zizaco/entrust
|
||||||
*
|
*
|
||||||
* @param string|array $name Role name or array of role names.
|
* @param string $name
|
||||||
* @param bool $requireAll All roles in the array are required.
|
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasRole($name, $requireAll = false)
|
public function hasRole(string $name): bool
|
||||||
{
|
{
|
||||||
if (is_array($name)) {
|
|
||||||
foreach ($name as $roleName) {
|
|
||||||
$hasRole = $this->hasRole($roleName);
|
|
||||||
|
|
||||||
if ($hasRole && !$requireAll) {
|
|
||||||
return true;
|
|
||||||
} elseif (!$hasRole && $requireAll) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we've made it this far and $requireAll is FALSE, then NONE of the roles were found
|
|
||||||
// If we've made it this far and $requireAll is TRUE, then ALL of the roles were found.
|
|
||||||
// Return the value of $requireAll;
|
|
||||||
return $requireAll;
|
|
||||||
} else {
|
|
||||||
foreach ($this->roles as $role) {
|
foreach ($this->roles as $role) {
|
||||||
if ($role->name == $name) {
|
if ($role->name == $name) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user