mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 15:03:44 +08: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
1b15f6cded
commit
050d6bdc9e
|
@ -60,7 +60,7 @@ class DiscussionPolicy extends AbstractPolicy
|
|||
* @param string $ability
|
||||
* @return bool|null
|
||||
*/
|
||||
public function after(User $actor, $ability)
|
||||
public function can(User $actor, $ability)
|
||||
{
|
||||
if ($actor->hasPermission('discussion.'.$ability)) {
|
||||
return true;
|
||||
|
|
|
@ -26,7 +26,7 @@ class GroupPolicy extends AbstractPolicy
|
|||
* @param string $ability
|
||||
* @return bool|null
|
||||
*/
|
||||
public function after(User $actor, $ability)
|
||||
public function can(User $actor, $ability)
|
||||
{
|
||||
if ($actor->hasPermission('group.'.$ability)) {
|
||||
return true;
|
||||
|
|
|
@ -60,7 +60,7 @@ class PostPolicy extends AbstractPolicy
|
|||
* @param \Flarum\Post\Post $post
|
||||
* @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)) {
|
||||
return true;
|
||||
|
|
|
@ -28,29 +28,29 @@ abstract class AbstractPolicy
|
|||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(GetPermission::class, [$this, 'getPermission']);
|
||||
$events->listen(GetPermission::class, [$this, 'getPermissionAfter'], -100);
|
||||
$events->listen(ScopeModelVisibility::class, [$this, 'scopeModelVisibility']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GetPermission $event
|
||||
* @return bool|null
|
||||
* @return bool|void
|
||||
*/
|
||||
public function getPermission(GetPermission $event)
|
||||
{
|
||||
if ($event->model instanceof $this->model && method_exists($this, $event->ability)) {
|
||||
return call_user_func_array([$this, $event->ability], [$event->actor, $event->model]);
|
||||
if (! $event->model instanceof $this->model) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GetPermission $event
|
||||
* @return bool|null
|
||||
*/
|
||||
public function getPermissionAfter(GetPermission $event)
|
||||
{
|
||||
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, $event->ability)) {
|
||||
$result = call_user_func_array([$this, $event->ability], [$event->actor, $event->model]);
|
||||
|
||||
if (! is_null($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
* @return bool|null
|
||||
*/
|
||||
public function after(User $actor, $ability)
|
||||
public function can(User $actor, $ability)
|
||||
{
|
||||
if ($actor->hasPermission('user.'.$ability)) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue
Block a user