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:
Toby Zerner 2018-01-11 14:10:37 +10:30
parent 801d619a36
commit ae2e07e94c
5 changed files with 17 additions and 17 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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]);
}
}

View File

@ -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;