diff --git a/src/Api/ApiServiceProvider.php b/src/Api/ApiServiceProvider.php index 4f3cfe37b..a3d5b7fb0 100644 --- a/src/Api/ApiServiceProvider.php +++ b/src/Api/ApiServiceProvider.php @@ -13,7 +13,6 @@ use Flarum\Api\Controller\AbstractSerializeController; use Flarum\Api\Serializer\AbstractSerializer; use Flarum\Api\Serializer\BasicDiscussionSerializer; use Flarum\Api\Serializer\NotificationSerializer; -use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\ErrorHandling\JsonApiFormatter; use Flarum\Foundation\ErrorHandling\Registry; @@ -111,10 +110,8 @@ class ApiServiceProvider extends AbstractServiceProvider $this->setNotificationSerializers(); AbstractSerializeController::setContainer($this->app); - AbstractSerializeController::setEventDispatcher($events = $this->app->make('events')); AbstractSerializer::setContainer($this->app); - AbstractSerializer::setEventDispatcher($events); } /** @@ -122,14 +119,8 @@ class ApiServiceProvider extends AbstractServiceProvider */ protected function setNotificationSerializers() { - $blueprints = []; $serializers = $this->app->make('flarum.api.notification_serializers'); - // Deprecated in beta 15, remove in beta 16 - $this->app->make('events')->dispatch( - new ConfigureNotificationTypes($blueprints, $serializers) - ); - foreach ($serializers as $type => $serializer) { NotificationSerializer::setSubjectSerializer($type, $serializer); } diff --git a/src/Api/Controller/AbstractSerializeController.php b/src/Api/Controller/AbstractSerializeController.php index 4be366e2d..e9e05ba29 100644 --- a/src/Api/Controller/AbstractSerializeController.php +++ b/src/Api/Controller/AbstractSerializeController.php @@ -9,11 +9,8 @@ namespace Flarum\Api\Controller; -use Flarum\Api\Event\WillGetData; -use Flarum\Api\Event\WillSerializeData; use Flarum\Api\JsonApiResponse; use Illuminate\Contracts\Container\Container; -use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -77,11 +74,6 @@ abstract class AbstractSerializeController implements RequestHandlerInterface */ protected static $container; - /** - * @var Dispatcher - */ - protected static $events; - /** * @var array */ @@ -107,11 +99,6 @@ abstract class AbstractSerializeController implements RequestHandlerInterface } } - // Deprected in beta 15, removed in beta 16 - static::$events->dispatch( - new WillGetData($this) - ); - $data = $this->data($request, $document); foreach (array_reverse(array_merge([static::class], class_parents($this))) as $class) { @@ -122,11 +109,6 @@ abstract class AbstractSerializeController implements RequestHandlerInterface } } - // Deprecated in beta 15, removed in beta 16 - static::$events->dispatch( - new WillSerializeData($this, $data, $request, $document) - ); - $serializer = static::$container->make($this->serializer); $serializer->setRequest($request); @@ -325,22 +307,6 @@ abstract class AbstractSerializeController implements RequestHandlerInterface $this->sort = $sort; } - /** - * @return Dispatcher - */ - public static function getEventDispatcher() - { - return static::$events; - } - - /** - * @param Dispatcher $events - */ - public static function setEventDispatcher(Dispatcher $events) - { - static::$events = $events; - } - /** * @return Container */ diff --git a/src/Api/Controller/CreateDiscussionController.php b/src/Api/Controller/CreateDiscussionController.php index e4c8b7717..16d9443c2 100644 --- a/src/Api/Controller/CreateDiscussionController.php +++ b/src/Api/Controller/CreateDiscussionController.php @@ -12,7 +12,6 @@ namespace Flarum\Api\Controller; use Flarum\Api\Serializer\DiscussionSerializer; use Flarum\Discussion\Command\ReadDiscussion; use Flarum\Discussion\Command\StartDiscussion; -use Flarum\Post\Floodgate; use Illuminate\Contracts\Bus\Dispatcher; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -41,19 +40,12 @@ class CreateDiscussionController extends AbstractCreateController */ protected $bus; - /** - * @var Floodgate - */ - protected $floodgate; - /** * @param Dispatcher $bus - * @param Floodgate $floodgate */ - public function __construct(Dispatcher $bus, Floodgate $floodgate) + public function __construct(Dispatcher $bus) { $this->bus = $bus; - $this->floodgate = $floodgate; } /** @@ -64,13 +56,6 @@ class CreateDiscussionController extends AbstractCreateController $actor = $request->getAttribute('actor'); $ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1'); - /** - * @deprecated, remove in beta 15. - */ - if (! $request->getAttribute('bypassFloodgate')) { - $this->floodgate->assertNotFlooding($actor); - } - $discussion = $this->bus->dispatch( new StartDiscussion($actor, Arr::get($request->getParsedBody(), 'data', []), $ipAddress) ); diff --git a/src/Api/Controller/CreatePostController.php b/src/Api/Controller/CreatePostController.php index 8209daede..171130955 100644 --- a/src/Api/Controller/CreatePostController.php +++ b/src/Api/Controller/CreatePostController.php @@ -12,7 +12,6 @@ namespace Flarum\Api\Controller; use Flarum\Api\Serializer\PostSerializer; use Flarum\Discussion\Command\ReadDiscussion; use Flarum\Post\Command\PostReply; -use Flarum\Post\Floodgate; use Illuminate\Contracts\Bus\Dispatcher; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -40,19 +39,12 @@ class CreatePostController extends AbstractCreateController */ protected $bus; - /** - * @var \Flarum\Post\Floodgate - */ - protected $floodgate; - /** * @param Dispatcher $bus - * @param \Flarum\Post\Floodgate $floodgate */ - public function __construct(Dispatcher $bus, Floodgate $floodgate) + public function __construct(Dispatcher $bus) { $this->bus = $bus; - $this->floodgate = $floodgate; } /** @@ -65,13 +57,6 @@ class CreatePostController extends AbstractCreateController $discussionId = Arr::get($data, 'relationships.discussion.data.id'); $ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1'); - /** - * @deprecated, remove in beta 15. - */ - if (! $request->getAttribute('bypassFloodgate')) { - $this->floodgate->assertNotFlooding($actor); - } - $post = $this->bus->dispatch( new PostReply($discussionId, $actor, $data, $ipAddress) ); diff --git a/src/Api/Event/Serializing.php b/src/Api/Event/Serializing.php deleted file mode 100644 index d0e1dae48..000000000 --- a/src/Api/Event/Serializing.php +++ /dev/null @@ -1,83 +0,0 @@ -serializer = $serializer; - $this->model = $model; - $this->attributes = &$attributes; - $this->actor = $serializer->getActor(); - } - - /** - * @param string $serializer - * @return bool - */ - public function isSerializer($serializer) - { - return $this->serializer instanceof $serializer; - } - - /** - * @param DateTime|null $date - * @return string|null - */ - public function formatDate(DateTime $date = null) - { - if ($date) { - return $date->format(DateTime::RFC3339); - } - } -} diff --git a/src/Api/Event/WillGetData.php b/src/Api/Event/WillGetData.php deleted file mode 100644 index 973d77336..000000000 --- a/src/Api/Event/WillGetData.php +++ /dev/null @@ -1,141 +0,0 @@ -controller = $controller; - } - - /** - * @param string $controller - * @return bool - */ - public function isController($controller) - { - return $this->controller instanceof $controller; - } - - /** - * Set the serializer that will serialize data for the endpoint. - * - * @param string $serializer - */ - public function setSerializer($serializer) - { - $this->controller->serializer = $serializer; - } - - /** - * Include the given relationship by default. - * - * @param string|array $name - */ - public function addInclude($name) - { - $this->controller->include = array_merge($this->controller->include, (array) $name); - } - - /** - * Don't include the given relationship by default. - * - * @param string $name - */ - public function removeInclude($name) - { - Arr::forget($this->controller->include, $name); - } - - /** - * Make the given relationship available for inclusion. - * - * @param string $name - */ - public function addOptionalInclude($name) - { - $this->controller->optionalInclude[] = $name; - } - - /** - * Don't allow the given relationship to be included. - * - * @param string $name - */ - public function removeOptionalInclude($name) - { - Arr::forget($this->controller->optionalInclude, $name); - } - - /** - * Set the default number of results. - * - * @param int $limit - */ - public function setLimit($limit) - { - $this->controller->limit = $limit; - } - - /** - * Set the maximum number of results. - * - * @param int $max - */ - public function setMaxLimit($max) - { - $this->controller->maxLimit = $max; - } - - /** - * Allow sorting results by the given field. - * - * @param string $field - */ - public function addSortField($field) - { - $this->controller->sortFields[] = $field; - } - - /** - * Disallow sorting results by the given field. - * - * @param string $field - */ - public function removeSortField($field) - { - Arr::forget($this->controller->sortFields, $field); - } - - /** - * Set the default sort order for the results. - * - * @param array $sort - */ - public function setSort(array $sort) - { - $this->controller->sort = $sort; - } -} diff --git a/src/Api/Event/WillSerializeData.php b/src/Api/Event/WillSerializeData.php deleted file mode 100644 index 0cae29589..000000000 --- a/src/Api/Event/WillSerializeData.php +++ /dev/null @@ -1,73 +0,0 @@ -controller = $controller; - $this->data = &$data; - $this->request = $request; - $this->document = $document; - $this->actor = $request->getAttribute('actor'); - } - - /** - * @param string $controller - * @return bool - */ - public function isController($controller) - { - return $this->controller instanceof $controller; - } -} diff --git a/src/Api/Serializer/AbstractSerializer.php b/src/Api/Serializer/AbstractSerializer.php index b20874405..a5165452f 100644 --- a/src/Api/Serializer/AbstractSerializer.php +++ b/src/Api/Serializer/AbstractSerializer.php @@ -11,11 +11,8 @@ namespace Flarum\Api\Serializer; use Closure; use DateTime; -use Flarum\Api\Event\Serializing; -use Flarum\Event\GetApiRelationship; use Flarum\User\User; use Illuminate\Contracts\Container\Container; -use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Arr; use InvalidArgumentException; use LogicException; @@ -38,11 +35,6 @@ abstract class AbstractSerializer extends BaseAbstractSerializer */ protected $actor; - /** - * @var Dispatcher - */ - protected static $dispatcher; - /** * @var Container */ @@ -105,11 +97,6 @@ abstract class AbstractSerializer extends BaseAbstractSerializer } } - // Deprecated in beta 15, removed in beta 16 - static::$dispatcher->dispatch( - new Serializing($this, $model, $attributes) - ); - return $attributes; } @@ -153,27 +140,21 @@ abstract class AbstractSerializer extends BaseAbstractSerializer */ protected function getCustomRelationship($model, $name) { - // Deprecated in beta 15, removed in beta 16 - $relationship = static::$dispatcher->until( - new GetApiRelationship($this, $name, $model) - ); - foreach (array_merge([static::class], class_parents($this)) as $class) { $callback = Arr::get(static::$customRelations, "$class.$name"); if (is_callable($callback)) { $relationship = $callback($this, $model); - break; + + if (isset($relationship) && ! ($relationship instanceof Relationship)) { + throw new LogicException( + 'GetApiRelationship handler must return an instance of '.Relationship::class + ); + } + + return $relationship; } } - - if ($relationship && ! ($relationship instanceof Relationship)) { - throw new LogicException( - 'GetApiRelationship handler must return an instance of '.Relationship::class - ); - } - - return $relationship; } /** @@ -282,22 +263,6 @@ abstract class AbstractSerializer extends BaseAbstractSerializer return $serializer; } - /** - * @return Dispatcher - */ - public static function getEventDispatcher() - { - return static::$dispatcher; - } - - /** - * @param Dispatcher $dispatcher - */ - public static function setEventDispatcher(Dispatcher $dispatcher) - { - static::$dispatcher = $dispatcher; - } - /** * @return Container */ diff --git a/src/Database/ScopeVisibilityTrait.php b/src/Database/ScopeVisibilityTrait.php index 2931c7fb6..ddcdb3cab 100644 --- a/src/Database/ScopeVisibilityTrait.php +++ b/src/Database/ScopeVisibilityTrait.php @@ -9,7 +9,6 @@ namespace Flarum\Database; -use Flarum\Event\ScopeModelVisibility; use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Arr; @@ -41,11 +40,6 @@ trait ScopeVisibilityTrait */ public function scopeWhereVisibleTo(Builder $query, User $actor, string $ability = 'view') { - /** - * @deprecated beta 15, remove beta 15 - */ - static::$dispatcher->dispatch(new ScopeModelVisibility($query, $actor, $ability)); - foreach (array_reverse(array_merge([static::class], class_parents($this))) as $class) { foreach (Arr::get(static::$visibilityScopers, "$class.*", []) as $listener) { $listener($actor, $query, $ability); diff --git a/src/Event/ConfigureNotificationTypes.php b/src/Event/ConfigureNotificationTypes.php deleted file mode 100644 index 89185b916..000000000 --- a/src/Event/ConfigureNotificationTypes.php +++ /dev/null @@ -1,58 +0,0 @@ -blueprints = &$blueprints; - $this->serializers = &$serializers; - } - - /** - * @param string $blueprint - * @param string $serializer - * @param array $enabledByDefault - */ - public function add($blueprint, $serializer, $enabledByDefault = []) - { - if (! (new ReflectionClass($blueprint))->implementsInterface(BlueprintInterface::class)) { - throw new InvalidArgumentException( - 'Notification blueprint '.$blueprint.' must implement '.BlueprintInterface::class - ); - } - - $this->blueprints[$blueprint] = $enabledByDefault; - - $this->serializers[$blueprint::getType()] = $serializer; - } -} diff --git a/src/Event/ConfigurePostTypes.php b/src/Event/ConfigurePostTypes.php deleted file mode 100644 index 768db2b48..000000000 --- a/src/Event/ConfigurePostTypes.php +++ /dev/null @@ -1,28 +0,0 @@ -models = &$models; - } - - public function add($class) - { - $this->models[] = $class; - } -} diff --git a/src/Event/ConfigureUserPreferences.php b/src/Event/ConfigureUserPreferences.php deleted file mode 100644 index 27e986fe5..000000000 --- a/src/Event/ConfigureUserPreferences.php +++ /dev/null @@ -1,23 +0,0 @@ -serializer = $serializer; - $this->relationship = $relationship; - $this->model = $model; - } - - /** - * @param string $serializer - * @param string $relationship - * @return bool - */ - public function isRelationship($serializer, $relationship) - { - return $this->serializer instanceof $serializer && $this->relationship === $relationship; - } -} diff --git a/src/Event/GetPermission.php b/src/Event/GetPermission.php deleted file mode 100644 index 876795c38..000000000 --- a/src/Event/GetPermission.php +++ /dev/null @@ -1,45 +0,0 @@ -actor = $actor; - $this->ability = $ability; - $this->model = $model; - } -} diff --git a/src/Event/ScopeModelVisibility.php b/src/Event/ScopeModelVisibility.php deleted file mode 100644 index f0153c550..000000000 --- a/src/Event/ScopeModelVisibility.php +++ /dev/null @@ -1,49 +0,0 @@ -query = $query; - $this->actor = $actor; - $this->ability = $ability; - } -} diff --git a/src/Extend/Csrf.php b/src/Extend/Csrf.php index bc8cffdcf..5df93ac97 100644 --- a/src/Extend/Csrf.php +++ b/src/Extend/Csrf.php @@ -28,18 +28,6 @@ class Csrf implements ExtenderInterface return $this; } - /** - * Exempt a path from csrf checks. Wildcards are supported. - * - * @deprecated beta 15, remove beta 16. Exempt routes should be used instead. - */ - public function exemptPath(string $path) - { - $this->csrfExemptRoutes[] = $path; - - return $this; - } - public function extend(Container $container, Extension $extension = null) { $container->extend('flarum.http.csrfExemptPaths', function ($existingExemptPaths) { diff --git a/src/Extension/Extension.php b/src/Extension/Extension.php index da0fa0763..84e3fc702 100644 --- a/src/Extension/Extension.php +++ b/src/Extension/Extension.php @@ -334,15 +334,6 @@ class Extension implements Arrayable return $filename; } - // To give extension authors some time to migrate to the new extension - // format, we will also fallback to the old bootstrap.php name. Consider - // this feature deprecated. - $deprecatedFilename = "{$this->path}/bootstrap.php"; - - if (file_exists($deprecatedFilename)) { - return $deprecatedFilename; - } - return null; } diff --git a/src/Formatter/Event/Configuring.php b/src/Formatter/Event/Configuring.php deleted file mode 100644 index 9f5993ce4..000000000 --- a/src/Formatter/Event/Configuring.php +++ /dev/null @@ -1,31 +0,0 @@ -configurator = $configurator; - } -} diff --git a/src/Formatter/Event/Parsing.php b/src/Formatter/Event/Parsing.php deleted file mode 100644 index b0fcb3fd1..000000000 --- a/src/Formatter/Event/Parsing.php +++ /dev/null @@ -1,45 +0,0 @@ -parser = $parser; - $this->context = $context; - $this->text = &$text; - } -} diff --git a/src/Formatter/Event/Rendering.php b/src/Formatter/Event/Rendering.php deleted file mode 100644 index 16c17d80c..000000000 --- a/src/Formatter/Event/Rendering.php +++ /dev/null @@ -1,53 +0,0 @@ -renderer = $renderer; - $this->context = $context; - $this->xml = &$xml; - $this->request = $request; - } -} diff --git a/src/Formatter/Formatter.php b/src/Formatter/Formatter.php index f2d6b7c5b..80683ff2d 100644 --- a/src/Formatter/Formatter.php +++ b/src/Formatter/Formatter.php @@ -9,11 +9,7 @@ namespace Flarum\Formatter; -use Flarum\Formatter\Event\Configuring; -use Flarum\Formatter\Event\Parsing; -use Flarum\Formatter\Event\Rendering; use Illuminate\Contracts\Cache\Repository; -use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use s9e\TextFormatter\Configurator; use s9e\TextFormatter\Unparser; @@ -31,11 +27,6 @@ class Formatter */ protected $cache; - /** - * @var Dispatcher - */ - protected $events; - /** * @var string */ @@ -43,13 +34,11 @@ class Formatter /** * @param Repository $cache - * @param Dispatcher $events * @param string $cacheDir */ - public function __construct(Repository $cache, Dispatcher $events, $cacheDir) + public function __construct(Repository $cache, $cacheDir) { $this->cache = $cache; - $this->events = $events; $this->cacheDir = $cacheDir; } @@ -79,9 +68,6 @@ class Formatter { $parser = $this->getParser($context); - // Deprecated in beta 15, remove in beta 16 - $this->events->dispatch(new Parsing($parser, $context, $text)); - foreach ($this->parsingCallbacks as $callback) { $text = $callback($parser, $context, $text); } @@ -101,9 +87,6 @@ class Formatter { $renderer = $this->getRenderer(); - // Deprecated in beta 15, remove in beta 16 - $this->events->dispatch(new Rendering($renderer, $context, $xml, $request)); - foreach ($this->renderingCallbacks as $callback) { $xml = $callback($renderer, $context, $xml, $request); } @@ -153,9 +136,6 @@ class Formatter $configurator->Autolink; $configurator->tags->onDuplicate('replace'); - // Deprecated in beta 15, remove in beta 16 - $this->events->dispatch(new Configuring($configurator)); - foreach ($this->configurationCallbacks as $callback) { $callback($configurator); } diff --git a/src/Formatter/FormatterServiceProvider.php b/src/Formatter/FormatterServiceProvider.php index 31aef917a..eb750c877 100644 --- a/src/Formatter/FormatterServiceProvider.php +++ b/src/Formatter/FormatterServiceProvider.php @@ -24,7 +24,6 @@ class FormatterServiceProvider extends AbstractServiceProvider $this->app->singleton('flarum.formatter', function (Container $container) { return new Formatter( new Repository($container->make('cache.filestore')), - $container->make('events'), $this->app[Paths::class]->storage.'/formatter' ); }); diff --git a/src/Foundation/AbstractValidator.php b/src/Foundation/AbstractValidator.php index 980558337..c5b6819f7 100644 --- a/src/Foundation/AbstractValidator.php +++ b/src/Foundation/AbstractValidator.php @@ -9,8 +9,6 @@ namespace Flarum\Foundation; -use Flarum\Foundation\Event\Validating; -use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Arr; use Illuminate\Validation\Factory; use Illuminate\Validation\ValidationException; @@ -38,11 +36,6 @@ abstract class AbstractValidator */ protected $validator; - /** - * @var Dispatcher - */ - protected $events; - /** * @var TranslatorInterface */ @@ -50,13 +43,11 @@ abstract class AbstractValidator /** * @param Factory $validator - * @param Dispatcher $events * @param TranslatorInterface $translator */ - public function __construct(Factory $validator, Dispatcher $events, TranslatorInterface $translator) + public function __construct(Factory $validator, TranslatorInterface $translator) { $this->validator = $validator; - $this->events = $events; $this->translator = $translator; } @@ -102,13 +93,6 @@ abstract class AbstractValidator $validator = $this->validator->make($attributes, $rules, $this->getMessages()); - /** - * @deprecated in beta 15, removed in beta 16. - */ - $this->events->dispatch( - new Validating($this, $validator) - ); - foreach ($this->configuration as $callable) { $callable($this, $validator); } diff --git a/src/Foundation/Event/Validating.php b/src/Foundation/Event/Validating.php deleted file mode 100644 index 86c6d4cd3..000000000 --- a/src/Foundation/Event/Validating.php +++ /dev/null @@ -1,42 +0,0 @@ -type = $type; - $this->validator = $validator; - } -} diff --git a/src/Http/Middleware/CheckCsrfToken.php b/src/Http/Middleware/CheckCsrfToken.php index c9f6f9494..4b7f2e1f3 100644 --- a/src/Http/Middleware/CheckCsrfToken.php +++ b/src/Http/Middleware/CheckCsrfToken.php @@ -26,12 +26,8 @@ class CheckCsrfToken implements Middleware public function process(Request $request, Handler $handler): Response { - $path = $request->getAttribute('originalUri')->getPath(); foreach ($this->exemptRoutes as $exemptRoute) { - /** - * @deprecated path match should be removed in beta 16, only route name match should be supported. - */ - if ($exemptRoute === $request->getAttribute('routeName') || fnmatch($exemptRoute, $path)) { + if ($exemptRoute === $request->getAttribute('routeName')) { return $handler->handle($request); } } diff --git a/src/Notification/Event/Sending.php b/src/Notification/Event/Sending.php deleted file mode 100644 index 25858a2db..000000000 --- a/src/Notification/Event/Sending.php +++ /dev/null @@ -1,42 +0,0 @@ -blueprint = $blueprint; - $this->users = &$users; - } -} diff --git a/src/Notification/NotificationServiceProvider.php b/src/Notification/NotificationServiceProvider.php index 7a169e1f6..b41be729d 100644 --- a/src/Notification/NotificationServiceProvider.php +++ b/src/Notification/NotificationServiceProvider.php @@ -9,7 +9,6 @@ namespace Flarum\Notification; -use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; @@ -60,11 +59,6 @@ class NotificationServiceProvider extends AbstractServiceProvider { $blueprints = $this->app->make('flarum.notification.blueprints'); - // Deprecated in beta 15, remove in beta 16 - $this->app->make('events')->dispatch( - new ConfigureNotificationTypes($blueprints) - ); - foreach ($blueprints as $blueprint => $driversEnabledByDefault) { $this->addType($blueprint, $driversEnabledByDefault); } diff --git a/src/Notification/NotificationSyncer.php b/src/Notification/NotificationSyncer.php index 7e7a5c4ff..22072d941 100644 --- a/src/Notification/NotificationSyncer.php +++ b/src/Notification/NotificationSyncer.php @@ -11,7 +11,6 @@ namespace Flarum\Notification; use Flarum\Notification\Blueprint\BlueprintInterface; use Flarum\Notification\Driver\NotificationDriverInterface; -use Flarum\Notification\Event\Sending; use Flarum\User\User; /** @@ -110,11 +109,6 @@ class NotificationSyncer foreach (static::getNotificationDrivers() as $driverName => $driver) { $driver->send($blueprint, $newRecipients); } - - if (count($newRecipients)) { - // Deprecated in beta 15, removed in beta 16 - event(new Sending($blueprint, $newRecipients)); - } } /** diff --git a/src/Post/Event/CheckingForFlooding.php b/src/Post/Event/CheckingForFlooding.php deleted file mode 100644 index c46a920d5..000000000 --- a/src/Post/Event/CheckingForFlooding.php +++ /dev/null @@ -1,31 +0,0 @@ -actor = $actor; - } -} diff --git a/src/Post/Floodgate.php b/src/Post/Floodgate.php deleted file mode 100644 index 55374964f..000000000 --- a/src/Post/Floodgate.php +++ /dev/null @@ -1,60 +0,0 @@ -events = $events; - } - - /** - * @param User $actor - * @throws FloodingException - */ - public function assertNotFlooding(User $actor) - { - if ($actor->can('postWithoutThrottle')) { - return; - } - - if ($this->isFlooding($actor)) { - throw new FloodingException; - } - } - - /** - * @param User $actor - * @return bool - */ - public function isFlooding(User $actor): bool - { - $isFlooding = $this->events->until( - new CheckingForFlooding($actor) - ); - - return $isFlooding ?? Post::where('user_id', $actor->id)->where('created_at', '>=', new DateTime('-10 seconds'))->exists(); - } -} diff --git a/src/Post/PostServiceProvider.php b/src/Post/PostServiceProvider.php index 795d9ab13..e6e728cd6 100644 --- a/src/Post/PostServiceProvider.php +++ b/src/Post/PostServiceProvider.php @@ -10,7 +10,6 @@ namespace Flarum\Post; use DateTime; -use Flarum\Event\ConfigurePostTypes; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Post\Access\ScopePostVisibility; @@ -61,11 +60,6 @@ class PostServiceProvider extends AbstractServiceProvider DiscussionRenamedPost::class ]; - // Deprecated in beta 15, remove in beta 16. - $this->app->make('events')->dispatch( - new ConfigurePostTypes($models) - ); - foreach ($models as $model) { Post::setModel($model::$type, $model); } diff --git a/src/User/AbstractPolicy.php b/src/User/AbstractPolicy.php deleted file mode 100644 index ed0f51752..000000000 --- a/src/User/AbstractPolicy.php +++ /dev/null @@ -1,73 +0,0 @@ -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]); - } - } - } -} diff --git a/src/User/Access/Gate.php b/src/User/Access/Gate.php index cc1df4a06..98e93fa22 100644 --- a/src/User/Access/Gate.php +++ b/src/User/Access/Gate.php @@ -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. diff --git a/src/User/User.php b/src/User/User.php index 32ac7c538..7d2c05892 100644 --- a/src/User/User.php +++ b/src/User/User.php @@ -14,7 +14,6 @@ use DomainException; use Flarum\Database\AbstractModel; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Discussion\Discussion; -use Flarum\Event\ConfigureUserPreferences; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Group\Group; use Flarum\Group\Permission; @@ -142,13 +141,6 @@ class User extends AbstractModel Notification::whereSubject($user)->delete(); }); - - /** - * @deprecated beta 15, remove beta 16 - */ - static::$dispatcher->dispatch( - new ConfigureUserPreferences - ); } /** @@ -803,20 +795,6 @@ class User extends AbstractModel static::$hasher = $hasher; } - /** - * @deprecated beta 15, remove beta 16. Use `registerPreference` instead. - * - * Register a preference with a transformer and a default value. - * - * @param string $key - * @param callable $transformer - * @param mixed $default - */ - public static function addPreference($key, callable $transformer = null, $default = null) - { - return static::registerPreference($key, $transformer, $default); - } - /** * Register a preference with a transformer and a default value. * diff --git a/tests/integration/api/discussions/ShowTest.php b/tests/integration/api/discussions/ShowTest.php index cf6f82ca5..a9f091c14 100644 --- a/tests/integration/api/discussions/ShowTest.php +++ b/tests/integration/api/discussions/ShowTest.php @@ -10,10 +10,8 @@ namespace Flarum\Tests\integration\api\discussions; use Carbon\Carbon; -use Flarum\Event\ScopeModelVisibility; use Flarum\Tests\integration\RetrievesAuthorizedUsers; use Flarum\Tests\integration\TestCase; -use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Arr; class ShowTest extends TestCase @@ -118,29 +116,6 @@ class ShowTest extends TestCase $this->assertEquals(2, Arr::get($json, 'data.relationships.posts.data.0.id')); } - /** - * @test - */ - public function when_allowed_guests_can_see_hidden_posts() - { - /** @var Dispatcher $events */ - $events = $this->app()->getContainer()->make(Dispatcher::class); - - $events->listen(ScopeModelVisibility::class, function (ScopeModelVisibility $event) { - if ($event->ability === 'hidePosts') { - $event->query->whereRaw('1=1'); - } - }); - - $response = $this->send( - $this->request('GET', '/api/discussions/4') - ); - - $json = json_decode($response->getBody()->getContents(), true); - - $this->assertEquals(2, Arr::get($json, 'data.relationships.posts.data.0.id')); - } - /** * @test */ diff --git a/tests/integration/extenders/CsrfTest.php b/tests/integration/extenders/CsrfTest.php index 0b6f8cec0..ff667fe13 100644 --- a/tests/integration/extenders/CsrfTest.php +++ b/tests/integration/extenders/CsrfTest.php @@ -41,38 +41,8 @@ class CsrfTest extends TestCase /** * @test - * @deprecated */ public function create_user_post_doesnt_need_csrf_token_if_whitelisted() - { - $this->extend( - (new Extend\Csrf) - ->exemptPath('/api/users') - ); - - $response = $this->send( - $this->request('POST', '/api/users', [ - 'json' => [ - 'data' => [ - 'attributes' => $this->testUser - ] - ], - ]) - ); - - $this->assertEquals(201, $response->getStatusCode()); - - $user = User::where('username', $this->testUser['username'])->firstOrFail(); - - $this->assertEquals(0, $user->is_email_confirmed); - $this->assertEquals($this->testUser['username'], $user->username); - $this->assertEquals($this->testUser['email'], $user->email); - } - - /** - * @test - */ - public function create_user_post_doesnt_need_csrf_token_if_whitelisted_via_routename() { $this->extend( (new Extend\Csrf) @@ -97,22 +67,4 @@ class CsrfTest extends TestCase $this->assertEquals($this->testUser['username'], $user->username); $this->assertEquals($this->testUser['email'], $user->email); } - - /** - * @test - * @deprecated - */ - public function csrf_matches_wildcards_properly() - { - $this->extend( - (new Extend\Csrf) - ->exemptPath('/api/fake/*/up') - ); - - $response = $this->send( - $this->request('POST', '/api/fake/route/i/made/up') - ); - - $this->assertEquals(404, $response->getStatusCode()); - } } diff --git a/tests/integration/extenders/ModelVisibilityTest.php b/tests/integration/extenders/ModelVisibilityTest.php index 25322167e..e875997a1 100644 --- a/tests/integration/extenders/ModelVisibilityTest.php +++ b/tests/integration/extenders/ModelVisibilityTest.php @@ -18,6 +18,7 @@ use Flarum\Tests\integration\RetrievesAuthorizedUsers; use Flarum\Tests\integration\TestCase; use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Arr; class ModelVisibilityTest extends TestCase { @@ -46,6 +47,27 @@ class ModelVisibilityTest extends TestCase ]); } + /** + * @test + */ + public function when_allowed_guests_can_see_hidden_posts() + { + $this->extend( + (new Extend\ModelVisibility(CommentPost::class)) + ->scope(function (User $user, Builder $query) { + $query->whereRaw('1=1'); + }, 'hidePosts') + ); + + $response = $this->send( + $this->request('GET', '/api/discussions/2') + ); + + $json = json_decode($response->getBody()->getContents(), true); + + $this->assertEquals(1, Arr::get($json, 'data.relationships.posts.data.0.id')); + } + /** * @test */