Centralize permission caching (#2832)

This commit is contained in:
Alexander Skvortsov 2021-05-04 13:56:14 -04:00 committed by GitHub
parent 3a6b8847f1
commit 7d4bd8a845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -379,11 +379,7 @@ class User extends AbstractModel
return true;
}
if (is_null($this->permissions)) {
$this->permissions = $this->getPermissions();
}
return in_array($permission, $this->permissions);
return in_array($permission, $this->getPermissions());
}
/**
@ -399,11 +395,7 @@ class User extends AbstractModel
return true;
}
if (is_null($this->permissions)) {
$this->permissions = $this->getPermissions();
}
foreach ($this->permissions as $permission) {
foreach ($this->getPermissions() as $permission) {
if (substr($permission, -strlen($match)) === $match) {
return true;
}
@ -739,7 +731,11 @@ class User extends AbstractModel
*/
public function getPermissions()
{
return $this->permissions()->pluck('permission')->all();
if (is_null($this->permissions)) {
$this->permissions = $this->permissions()->pluck('permission')->all();
}
return $this->permissions;
}
/**