3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module;
25 use Friendica\BaseModule;
26 use Friendica\Core\L10n;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session\Capability\IHandleUserSessions;
29 use Friendica\Navigation\SystemMessages;
30 use Friendica\Network\HTTPException;
31 use Friendica\Util\Profiler;
32 use Psr\Log\LoggerInterface;
35 * This abstract module is meant to be extended by all modules that are reserved to moderator users.
37 * It performs a blanket permission check in all the module methods as long as the relevant `parent::method()` is
38 * called in the inheriting module.
40 * Additionally, it puts together the moderation page aside with all the moderation links.
42 * @package Friendica\Module
44 abstract class BaseModeration extends BaseModule
46 /** @var IHandleUserSessions */
48 /** @var SystemMessages */
49 protected $systemMessages;
55 public function __construct(App\Page $page, App $app, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
57 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
59 $this->session = $session;
60 $this->systemMessages = $systemMessages;
66 * Checks moderator access and throws exceptions if not logged-in moderator
68 * @param bool $interactive
70 * @throws HTTPException\ForbiddenException
71 * @throws HTTPException\InternalServerErrorException
73 public function checkModerationAccess(bool $interactive = false)
75 if (!$this->session->getLocalUserId()) {
77 $this->systemMessages->addNotice($this->t('Please login to continue.'));
78 $this->session->set('return_path', $this->args->getQueryString());
79 $this->baseUrl->redirect('login');
81 throw new HTTPException\UnauthorizedException($this->t('Please login to continue.'));
85 if (!$this->app->isSiteAdmin()) {
86 throw new HTTPException\ForbiddenException($this->t('You don\'t have access to administration pages.'));
89 if ($this->session->getSubManagedUserId()) {
90 throw new HTTPException\ForbiddenException($this->t('Submanaged account can\'t access the administration pages. Please log back in as the main account.'));
94 protected function content(array $request = []): string
96 $this->checkModerationAccess(true);
99 $this->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('moderation/settings_head.tpl'), []);
105 // array(url, name, extra css classes)
106 // not part of $aside to make the template more adjustable
108 'information' => [$this->t('Information'), [
109 'overview' => ['moderation', $this->t('Overview'), 'overview'],
111 'configuration' => [$this->t('Configuration'), [
112 'users' => ['moderation/users', $this->t('Users'), 'users'],
114 'tools' => [$this->t('Tools'), [
115 'contactblock' => ['moderation/blocklist/contact', $this->t('Contact Blocklist'), 'contactblock'],
116 'blocklist' => ['moderation/blocklist/server', $this->t('Server Blocklist'), 'blocklist'],
117 'deleteitem' => ['moderation/item/delete', $this->t('Delete Item'), 'deleteitem'],
119 'diagnostics' => [$this->t('Diagnostics'), [
120 'itemsource' => ['moderation/item/source', $this->t('Item Source'), 'itemsource'],
124 $t = Renderer::getMarkupTemplate('moderation/aside.tpl');
125 $this->page['aside'] .= Renderer::replaceMacros($t, [
126 '$subpages' => $aside_sub,
127 '$admtxt' => $this->t('Moderation'),
128 '$h_pending' => $this->t('User registrations waiting for confirmation'),
129 '$modurl' => 'moderation/'