mirror of
https://github.com/flarum/core.git
synced 2025-10-14 08:24:28 +02:00
Get rid of Laravel Gate contract (#2181)
* Get rid of unnecessary uses of gate * Move gate off of Laravel's gate contract
This commit is contained in:
committed by
GitHub
parent
bab084a75f
commit
7b1269207e
@@ -10,7 +10,6 @@
|
||||
namespace Flarum\User;
|
||||
|
||||
use Flarum\Event\ConfigureUserPreferences;
|
||||
use Flarum\Event\GetPermission;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\User\DisplayName\DriverInterface;
|
||||
@@ -18,12 +17,10 @@ use Flarum\User\DisplayName\UsernameDriver;
|
||||
use Flarum\User\Event\EmailChangeRequested;
|
||||
use Flarum\User\Event\Registered;
|
||||
use Flarum\User\Event\Saving;
|
||||
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Filesystem\Factory;
|
||||
use Illuminate\Support\Arr;
|
||||
use League\Flysystem\FilesystemInterface;
|
||||
use RuntimeException;
|
||||
|
||||
class UserServiceProvider extends AbstractServiceProvider
|
||||
{
|
||||
@@ -32,7 +29,6 @@ class UserServiceProvider extends AbstractServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerGate();
|
||||
$this->registerAvatarsFilesystem();
|
||||
$this->registerDisplayNameDrivers();
|
||||
}
|
||||
@@ -60,18 +56,6 @@ class UserServiceProvider extends AbstractServiceProvider
|
||||
$this->app->alias('flarum.user.display_name.driver', DriverInterface::class);
|
||||
}
|
||||
|
||||
protected function registerGate()
|
||||
{
|
||||
$this->app->singleton('flarum.gate', function ($app) {
|
||||
return new Gate($app, function () {
|
||||
throw new RuntimeException('You must set the gate user with forUser()');
|
||||
});
|
||||
});
|
||||
|
||||
$this->app->alias('flarum.gate', GateContract::class);
|
||||
$this->app->alias('flarum.gate', Gate::class);
|
||||
}
|
||||
|
||||
protected function registerAvatarsFilesystem()
|
||||
{
|
||||
$avatarsFilesystem = function (Container $app) {
|
||||
@@ -88,30 +72,8 @@ class UserServiceProvider extends AbstractServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$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)
|
||||
);
|
||||
|
||||
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() || $actor->hasPermission($ability)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
User::setHasher($this->app->make('hash'));
|
||||
User::setGate($this->app->make('flarum.gate'));
|
||||
User::setGate($this->app->make(Gate::class));
|
||||
User::setDisplayNameDriver($this->app->make('flarum.user.display_name.driver'));
|
||||
|
||||
$events = $this->app->make('events');
|
||||
|
Reference in New Issue
Block a user