Give GetPermission event priority when determining permissions

This commit is contained in:
Toby Zerner 2016-01-16 13:56:37 +10:30
parent aaab2cc86e
commit dfc0cf53b0

View File

@ -73,13 +73,25 @@ class CoreServiceProvider extends AbstractServiceProvider
});
$this->app->make('flarum.gate')->before(function (User $actor, $ability, $model = null) {
// Fire an event so that core and extension policies can hook into
// this permission query and explicitly grant or deny the
// permission.
$allowed = $this->app->make('events')->until(
new GetPermission($actor, $ability, $model ? [$model] : [])
);
if (! is_null($allowed)) {
return $allowed;
}
// If no policy covered this permission query, we will only grant
// the permission if the actor's groups have it. Otherwise, we will
// not allow the user to perform this action.
if ($actor->isAdmin() || (! $model && $actor->hasPermission($ability))) {
return true;
}
return $this->app->make('events')->until(
new GetPermission($actor, $ability, $model ? [$model] : [])
);
return false;
});
$this->registerPostTypes();