mirror of
https://github.com/flarum/core.git
synced 2025-06-05 14:15:32 +02:00
Remove use of event priorities
Event priorities are no longer in Laravel - see dbbfc62bef
Updated the AbstractPolicy terminology to reflect the new behaviour,
which is that there is no guarantee that the catch-all methods will run
after all specific methods have run globally. This behaviour is only
guaranteed within the policy.
This commit is contained in:
parent
801d619a36
commit
ae2e07e94c
src
Discussion
Group
Post
User
@ -60,7 +60,7 @@ class DiscussionPolicy extends AbstractPolicy
|
|||||||
* @param string $ability
|
* @param string $ability
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function after(User $actor, $ability)
|
public function can(User $actor, $ability)
|
||||||
{
|
{
|
||||||
if ($actor->hasPermission('discussion.'.$ability)) {
|
if ($actor->hasPermission('discussion.'.$ability)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -26,7 +26,7 @@ class GroupPolicy extends AbstractPolicy
|
|||||||
* @param string $ability
|
* @param string $ability
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function after(User $actor, $ability)
|
public function can(User $actor, $ability)
|
||||||
{
|
{
|
||||||
if ($actor->hasPermission('group.'.$ability)) {
|
if ($actor->hasPermission('group.'.$ability)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -60,7 +60,7 @@ class PostPolicy extends AbstractPolicy
|
|||||||
* @param \Flarum\Post\Post $post
|
* @param \Flarum\Post\Post $post
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function after(User $actor, $ability, Post $post)
|
public function can(User $actor, $ability, Post $post)
|
||||||
{
|
{
|
||||||
if ($actor->can($ability.'Posts', $post->discussion)) {
|
if ($actor->can($ability.'Posts', $post->discussion)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -28,29 +28,29 @@ abstract class AbstractPolicy
|
|||||||
public function subscribe(Dispatcher $events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen(GetPermission::class, [$this, 'getPermission']);
|
$events->listen(GetPermission::class, [$this, 'getPermission']);
|
||||||
$events->listen(GetPermission::class, [$this, 'getPermissionAfter'], -100);
|
|
||||||
$events->listen(ScopeModelVisibility::class, [$this, 'scopeModelVisibility']);
|
$events->listen(ScopeModelVisibility::class, [$this, 'scopeModelVisibility']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param GetPermission $event
|
* @param GetPermission $event
|
||||||
* @return bool|null
|
* @return bool|void
|
||||||
*/
|
*/
|
||||||
public function getPermission(GetPermission $event)
|
public function getPermission(GetPermission $event)
|
||||||
{
|
{
|
||||||
if ($event->model instanceof $this->model && method_exists($this, $event->ability)) {
|
if (! $event->model instanceof $this->model) {
|
||||||
return call_user_func_array([$this, $event->ability], [$event->actor, $event->model]);
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (method_exists($this, $event->ability)) {
|
||||||
* @param GetPermission $event
|
$result = call_user_func_array([$this, $event->ability], [$event->actor, $event->model]);
|
||||||
* @return bool|null
|
|
||||||
*/
|
if (! is_null($result)) {
|
||||||
public function getPermissionAfter(GetPermission $event)
|
return $result;
|
||||||
{
|
}
|
||||||
if ($event->model instanceof $this->model && method_exists($this, 'after')) {
|
}
|
||||||
return call_user_func_array([$this, 'after'], [$event->actor, $event->ability, $event->model]);
|
|
||||||
|
if (method_exists($this, 'can')) {
|
||||||
|
return call_user_func_array([$this, 'can'], [$event->actor, $event->ability, $event->model]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class UserPolicy extends AbstractPolicy
|
|||||||
* @param string $ability
|
* @param string $ability
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function after(User $actor, $ability)
|
public function can(User $actor, $ability)
|
||||||
{
|
{
|
||||||
if ($actor->hasPermission('user.'.$ability)) {
|
if ($actor->hasPermission('user.'.$ability)) {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user