mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02:00
Centralize permission caching (#2832)
This commit is contained in:
committed by
GitHub
parent
3a6b8847f1
commit
7d4bd8a845
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user