mirror of
https://github.com/flarum/framework.git
synced 2024-12-12 14:13:37 +08:00
PERF: further simplify User::hasPermission()
This commit is contained in:
parent
5ae7bfefaa
commit
19ef6ed637
|
@ -61,11 +61,11 @@ class User extends Model
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An cache of permissions, and whether or not this user has them.
|
* An array of permissions that this user has.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array|null
|
||||||
*/
|
*/
|
||||||
protected $hasPermission = [];
|
protected $permissions = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hasher with which to hash passwords.
|
* The hasher with which to hash passwords.
|
||||||
|
@ -322,15 +322,11 @@ class User extends Model
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! array_key_exists('permissions', $this->relations)) {
|
if (is_null($this->permissions)) {
|
||||||
$this->setRelation('permissions', $this->permissions()->get());
|
$this->permissions = $this->permissions()->lists('permission');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($this->hasPermissions[$permission])) {
|
return in_array($permission, $this->permissions);
|
||||||
$this->hasPermission[$permission] = (bool) $this->permissions->contains('permission', $permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->hasPermission[$permission];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user