HelpController.php 3.1 KB

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