/** * {@inheritdoc} */ public function boot() { $this->loadViewsFrom(__DIR__ . '/../../views', 'flarum'); $this->app->make('Illuminate\\Contracts\\Bus\\Dispatcher')->mapUsing(function ($command) { return get_class($command) . 'Handler@handle'; }); $this->app->make('flarum.gate')->before(function (User $actor, $ability, $model = null) { if ($actor->isAdmin() || !$model && $actor->hasPermission($ability)) { return true; } return $this->app->make('events')->until(new GetPermission($actor, $ability, [$model])); }); $this->registerPostTypes(); CommentPost::setFormatter($this->app->make('flarum.formatter')); User::setHasher($this->app->make('hash')); User::setGate($this->app->make('flarum.gate')); $events = $this->app->make('events'); $events->subscribe('Flarum\\Core\\Listener\\DiscussionMetadataUpdater'); $events->subscribe('Flarum\\Core\\Listener\\UserMetadataUpdater'); $events->subscribe('Flarum\\Core\\Listener\\EmailConfirmationMailer'); $events->subscribe('Flarum\\Core\\Listener\\DiscussionRenamedNotifier'); $events->subscribe('Flarum\\Core\\Listener\\FloodController'); $events->subscribe('Flarum\\Core\\Access\\DiscussionPolicy'); $events->subscribe('Flarum\\Core\\Access\\GroupPolicy'); $events->subscribe('Flarum\\Core\\Access\\PostPolicy'); $events->subscribe('Flarum\\Core\\Access\\UserPolicy'); $events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']); }
/** * @param PostReply $command * @return CommentPost * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(PostReply $command) { $actor = $command->actor; // Make sure the user has permission to reply to this discussion. First, // make sure the discussion exists and that the user has permission to // view it; if not, fail with a ModelNotFound exception so we don't give // away the existence of the discussion. If the user is allowed to view // it, check if they have permission to reply. $discussion = $this->discussions->findOrFail($command->discussionId, $actor); $this->assertCan($actor, 'reply', $discussion); // Create a new Post entity, persist it, and dispatch domain events. // Before persistence, though, fire an event to give plugins an // opportunity to alter the post entity based on data in the command. $post = CommentPost::reply($discussion->id, array_get($command->data, 'attributes.content'), $actor->id, $command->ipAddress); if ($actor->isAdmin() && ($time = array_get($command->data, 'attributes.time'))) { $post->time = new DateTime($time); } $this->events->fire(new PostWillBeSaved($post, $actor, $command->data)); $this->validator->assertValid($post->getAttributes()); $post->save(); $this->notifications->onePerUser(function () use($post, $actor) { $this->dispatchEventsFor($post, $actor); }); return $post; }
/** * @param $tag * @return bool */ public static function addId($tag) { $post = CommentPost::find($tag->getAttribute('id')); if ($post) { $tag->setAttribute('discussionid', (int) $post->discussion_id); $tag->setAttribute('number', (int) $post->number); return true; } }
/** * {@inheritdoc} */ public function boot() { $this->loadViewsFrom(__DIR__ . '/../../views', 'flarum'); $this->app->make('Illuminate\\Contracts\\Bus\\Dispatcher')->mapUsing(function ($command) { return get_class($command) . 'Handler@handle'; }); $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() || !$model && $actor->hasPermission($ability)) { return true; } return false; }); $this->registerPostTypes(); CommentPost::setFormatter($this->app->make('flarum.formatter')); User::setHasher($this->app->make('hash')); User::setGate($this->app->make('flarum.gate')); $events = $this->app->make('events'); $events->subscribe('Flarum\\Core\\Listener\\DiscussionMetadataUpdater'); $events->subscribe('Flarum\\Core\\Listener\\UserMetadataUpdater'); $events->subscribe('Flarum\\Core\\Listener\\EmailConfirmationMailer'); $events->subscribe('Flarum\\Core\\Listener\\DiscussionRenamedNotifier'); $events->subscribe('Flarum\\Core\\Access\\DiscussionPolicy'); $events->subscribe('Flarum\\Core\\Access\\GroupPolicy'); $events->subscribe('Flarum\\Core\\Access\\PostPolicy'); $events->subscribe('Flarum\\Core\\Access\\UserPolicy'); $events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']); }