|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> |
| 4 | + * |
| 5 | + * @author Julius Härtl <jus@bitgrid.net> |
| 6 | + * |
| 7 | + * @license GNU AGPL version 3 or any later version |
| 8 | + * |
| 9 | + * This program is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU Affero General Public License as |
| 11 | + * published by the Free Software Foundation, either version 3 of the |
| 12 | + * License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU Affero General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Affero General Public License |
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | + * |
| 22 | + */ |
| 23 | +declare(strict_types=1); |
| 24 | + |
| 25 | +namespace OCA\Settings\Controller; |
| 26 | + |
| 27 | +use OCP\AppFramework\Controller; |
| 28 | +use OCP\AppFramework\Http\ContentSecurityPolicy; |
| 29 | +use OCP\AppFramework\Http\TemplateResponse; |
| 30 | +use OCP\IGroupManager; |
| 31 | +use OCP\INavigationManager; |
| 32 | +use OCP\IRequest; |
| 33 | +use OCP\IURLGenerator; |
| 34 | +use OCP\IUserSession; |
| 35 | + |
| 36 | +class HelpController extends Controller { |
| 37 | + |
| 38 | + /** @var INavigationManager */ |
| 39 | + private $navigationManager; |
| 40 | + /** @var IUserSession */ |
| 41 | + private $urlGenerator; |
| 42 | + /** @var IGroupManager */ |
| 43 | + private $groupManager; |
| 44 | + |
| 45 | + /** @var string */ |
| 46 | + private $userId; |
| 47 | + |
| 48 | + public function __construct( |
| 49 | + string $appName, |
| 50 | + IRequest $request, |
| 51 | + INavigationManager $navigationManager, |
| 52 | + IURLGenerator $urlGenerator, |
| 53 | + string $userId, |
| 54 | + IGroupManager $groupManager |
| 55 | + ) { |
| 56 | + parent::__construct($appName, $request); |
| 57 | + $this->navigationManager = $navigationManager; |
| 58 | + $this->urlGenerator = $urlGenerator; |
| 59 | + $this->userId = $userId; |
| 60 | + $this->groupManager = $groupManager; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @return TemplateResponse |
| 65 | + * |
| 66 | + * @NoCSRFRequired |
| 67 | + * @NoAdminRequired |
| 68 | + */ |
| 69 | + public function help(string $mode = 'user'): TemplateResponse { |
| 70 | + $this->navigationManager->setActiveEntry('help'); |
| 71 | + |
| 72 | + if(!isset($mode) || $mode !== 'admin') { |
| 73 | + $mode = 'user'; |
| 74 | + } |
| 75 | + |
| 76 | + $documentationUrl = $this->urlGenerator->getAbsoluteURL( |
| 77 | + $this->urlGenerator->linkTo('core', 'doc/' . $mode . '/index.html') |
| 78 | + ); |
| 79 | + |
| 80 | + $urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']); |
| 81 | + $urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']); |
| 82 | + |
| 83 | + $response = new TemplateResponse('settings', 'help', [ |
| 84 | + 'admin' => $this->groupManager->isAdmin($this->userId), |
| 85 | + 'url' => $documentationUrl, |
| 86 | + 'urlUserDocs' => $urlUserDocs, |
| 87 | + 'urlAdminDocs' => $urlAdminDocs, |
| 88 | + 'mode' => $mode, |
| 89 | + ]); |
| 90 | + $policy = new ContentSecurityPolicy(); |
| 91 | + $policy->addAllowedFrameDomain('\'self\''); |
| 92 | + $response->setContentSecurityPolicy($policy); |
| 93 | + return $response; |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | +} |
0 commit comments