/** * {@inheritdoc} */ protected function getDefaultAttributes($post) { $attributes = parent::getDefaultAttributes($post); unset($attributes['content']); $gate = $this->gate->forUser($this->actor); $canEdit = $gate->allows('edit', $post); if ($post instanceof CommentPost) { $attributes['contentHtml'] = $post->content_html; if ($canEdit) { $attributes['content'] = $post->content; } if ($gate->allows('viewIps', $post)) { $attributes['ipAddress'] = $post->ip_address; } } else { $attributes['content'] = $post->content; } if ($post->edit_time) { $attributes['editTime'] = $this->formatDate($post->edit_time); } if ($post->hide_time) { $attributes['isHidden'] = true; $attributes['hideTime'] = $this->formatDate($post->hide_time); } $attributes += ['canEdit' => $canEdit, 'canDelete' => $gate->allows('delete', $post)]; return $attributes; }
/** * {@inheritdoc} */ public function __invoke(Request $request, Response $response, callable $out = null) { $actor = $request->getAttribute('actor'); if (!$this->gate->forUser($actor)->allows('administrate')) { throw new PermissionDeniedException(); } return $out ? $out($request, $response) : $response; }
/** * {@inheritdoc} */ protected function getDefaultAttributes($model) { $gate = $this->gate->forUser($this->actor); $attributes = ['title' => $this->settings->get('forum_title'), 'description' => $this->settings->get('forum_description'), 'baseUrl' => $url = $this->app->url(), 'basePath' => parse_url($url, PHP_URL_PATH) ?: '', 'debug' => $this->app->inDebugMode(), 'apiUrl' => $this->app->url('api'), 'welcomeTitle' => $this->settings->get('welcome_title'), 'welcomeMessage' => $this->settings->get('welcome_message'), 'themePrimaryColor' => $this->settings->get('theme_primary_color'), 'allowSignUp' => (bool) $this->settings->get('allow_sign_up'), 'defaultRoute' => $this->settings->get('default_route'), 'canViewDiscussions' => $gate->allows('viewDiscussions'), 'canStartDiscussion' => $gate->allows('startDiscussion')]; if ($gate->allows('administrate')) { $attributes['adminUrl'] = $this->app->url('admin'); $attributes['version'] = $this->app->version(); } return $attributes; }
/** * {@inheritdoc} */ protected function getDefaultAttributes($discussion) { $gate = $this->gate->forUser($this->actor); $attributes = parent::getDefaultAttributes($discussion) + ['commentsCount' => (int) $discussion->comments_count, 'participantsCount' => (int) $discussion->participants_count, 'startTime' => $this->formatDate($discussion->start_time), 'lastTime' => $this->formatDate($discussion->last_time), 'lastPostNumber' => (int) $discussion->last_post_number, 'canReply' => $gate->allows('reply', $discussion), 'canRename' => $gate->allows('rename', $discussion), 'canDelete' => $gate->allows('delete', $discussion), 'canHide' => $gate->allows('hide', $discussion)]; if ($discussion->hide_time) { $attributes['isHidden'] = true; $attributes['hideTime'] = $this->formatDate($discussion->hide_time); } Discussion::setStateUser($this->actor); if ($state = $discussion->state) { $attributes += ['readTime' => $this->formatDate($state->read_time), 'readNumber' => (int) $state->read_number]; } return $attributes; }
/** * {@inheritdoc} */ protected function getDefaultAttributes($user) { $attributes = parent::getDefaultAttributes($user); $gate = $this->gate->forUser($this->actor); $canEdit = $gate->allows('edit', $user); $attributes += ['bio' => $user->bio, 'joinTime' => $this->formatDate($user->join_time), 'discussionsCount' => (int) $user->discussions_count, 'commentsCount' => (int) $user->comments_count, 'canEdit' => $canEdit, 'canDelete' => $gate->allows('delete', $user)]; if ($user->getPreference('discloseOnline')) { $attributes += ['lastSeenTime' => $this->formatDate($user->last_seen_time)]; } if ($canEdit || $this->actor->id === $user->id) { $attributes += ['isActivated' => (bool) $user->is_activated, 'email' => $user->email]; } return $attributes; }
/** * @param string $ability * @param array|mixed $arguments * @return bool */ public function can($ability, $arguments = []) { return static::$gate->forUser($this)->allows($ability, $arguments); }
/** * @param User $actor * @param string $ability * @param Post $post * @return bool */ protected function discussionAllows(User $actor, $ability, Post $post) { return $this->gate->forUser($actor)->allows($ability . 'Posts', $post->discussion); }