mirror of
https://github.com/flarum/framework.git
synced 2025-04-25 14:14:03 +08:00
Give GetPermission event priority when determining permissions
This commit is contained in:
parent
aaab2cc86e
commit
dfc0cf53b0
@ -73,13 +73,25 @@ class CoreServiceProvider extends AbstractServiceProvider
|
|||||||
});
|
});
|
||||||
|
|
||||||
$this->app->make('flarum.gate')->before(function (User $actor, $ability, $model = null) {
|
$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))) {
|
if ($actor->isAdmin() || (! $model && $actor->hasPermission($ability))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->app->make('events')->until(
|
return false;
|
||||||
new GetPermission($actor, $ability, $model ? [$model] : [])
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->registerPostTypes();
|
$this->registerPostTypes();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user