HelpController.php 2.8 KB

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