mirror of
https://github.com/flarum/framework.git
synced 2025-02-11 07:19:46 +08:00
Centralize permission caching (#2832)
This commit is contained in:
parent
a7f98f54fa
commit
f8421b47b2
|
@ -379,11 +379,7 @@ class User extends AbstractModel
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->permissions)) {
|
return in_array($permission, $this->getPermissions());
|
||||||
$this->permissions = $this->getPermissions();
|
|
||||||
}
|
|
||||||
|
|
||||||
return in_array($permission, $this->permissions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -399,11 +395,7 @@ class User extends AbstractModel
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->permissions)) {
|
foreach ($this->getPermissions() as $permission) {
|
||||||
$this->permissions = $this->getPermissions();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->permissions as $permission) {
|
|
||||||
if (substr($permission, -strlen($match)) === $match) {
|
if (substr($permission, -strlen($match)) === $match) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -739,7 +731,11 @@ class User extends AbstractModel
|
||||||
*/
|
*/
|
||||||
public function getPermissions()
|
public function getPermissions()
|
||||||
{
|
{
|
||||||
return $this->permissions()->pluck('permission')->all();
|
if (is_null($this->permissions)) {
|
||||||
|
$this->permissions = $this->permissions()->pluck('permission')->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user