mirror of
https://github.com/flarum/core.git
synced 2025-10-27 05:31:29 +01:00
Remove deprecated policy and visibility scoping events
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\User;
|
||||
|
||||
use Flarum\Event\GetPermission;
|
||||
use Flarum\Event\ScopeModelVisibility;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
abstract class AbstractPolicy
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(GetPermission::class, [$this, 'getPermission']);
|
||||
$events->listen(ScopeModelVisibility::class, [$this, 'scopeModelVisibility']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GetPermission $event
|
||||
* @return bool|void
|
||||
*/
|
||||
public function getPermission(GetPermission $event)
|
||||
{
|
||||
if (! $event->model instanceof $this->model && $event->model !== $this->model) {
|
||||
return;
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ScopeModelVisibility $event
|
||||
* @deprecated beta 15, remove beta 16
|
||||
*/
|
||||
public function scopeModelVisibility(ScopeModelVisibility $event)
|
||||
{
|
||||
if ($event->query->getModel() instanceof $this->model) {
|
||||
if (substr($event->ability, 0, 4) === 'view') {
|
||||
$method = 'find'.substr($event->ability, 4);
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
call_user_func_array([$this, $method], [$event->actor, $event->query]);
|
||||
}
|
||||
} elseif (method_exists($this, 'findWithPermission')) {
|
||||
call_user_func_array([$this, 'findWithPermission'], [$event->actor, $event->query, $event->ability]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,8 @@
|
||||
namespace Flarum\User\Access;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Event\GetPermission;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class Gate
|
||||
@@ -30,11 +28,6 @@ class Gate
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@@ -46,12 +39,12 @@ class Gate
|
||||
protected $policies;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
* @param Container $container
|
||||
* @param array $policyClasses
|
||||
*/
|
||||
public function __construct(Container $container, Dispatcher $events, array $policyClasses)
|
||||
public function __construct(Container $container, array $policyClasses)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->events = $events;
|
||||
$this->policyClasses = $policyClasses;
|
||||
}
|
||||
|
||||
@@ -88,20 +81,6 @@ class Gate
|
||||
}
|
||||
}
|
||||
|
||||
// START OLD DEPRECATED SYSTEM
|
||||
|
||||
// Fire an event so that core and extension modelPolicies can hook into
|
||||
// this permission query and explicitly grant or deny the
|
||||
// permission.
|
||||
$allowed = $this->events->until(
|
||||
new GetPermission($actor, $ability, $model)
|
||||
);
|
||||
|
||||
if (! is_null($allowed)) {
|
||||
return $allowed;
|
||||
}
|
||||
// END OLD DEPRECATED SYSTEM
|
||||
|
||||
// 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.
|
||||
|
||||
Reference in New Issue
Block a user