HelpController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\Controller;
  8. use OCP\AppFramework\Controller;
  9. use OCP\AppFramework\Http\Attribute\NoAdminRequired;
  10. use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
  11. use OCP\AppFramework\Http\Attribute\OpenAPI;
  12. use OCP\AppFramework\Http\ContentSecurityPolicy;
  13. use OCP\AppFramework\Http\TemplateResponse;
  14. use OCP\IAppConfig;
  15. use OCP\IConfig;
  16. use OCP\IGroupManager;
  17. use OCP\IL10N;
  18. use OCP\INavigationManager;
  19. use OCP\IRequest;
  20. use OCP\IURLGenerator;
  21. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  22. class HelpController extends Controller {
  23. /** @var INavigationManager */
  24. private $navigationManager;
  25. /** @var IURLGenerator */
  26. private $urlGenerator;
  27. /** @var IGroupManager */
  28. private $groupManager;
  29. /** @var IL10N */
  30. private $l10n;
  31. /** @var string */
  32. private $userId;
  33. /** @var IConfig */
  34. private $config;
  35. /** @var IAppConfig */
  36. private $appConfig;
  37. public function __construct(
  38. string $appName,
  39. IRequest $request,
  40. INavigationManager $navigationManager,
  41. IURLGenerator $urlGenerator,
  42. ?string $userId,
  43. IGroupManager $groupManager,
  44. IL10N $l10n,
  45. IConfig $config,
  46. IAppConfig $appConfig,
  47. ) {
  48. parent::__construct($appName, $request);
  49. $this->navigationManager = $navigationManager;
  50. $this->urlGenerator = $urlGenerator;
  51. $this->userId = $userId;
  52. $this->groupManager = $groupManager;
  53. $this->l10n = $l10n;
  54. $this->config = $config;
  55. $this->appConfig = $appConfig;
  56. }
  57. /**
  58. * @return TemplateResponse
  59. *
  60. * @NoSubAdminRequired
  61. */
  62. #[NoCSRFRequired]
  63. #[NoAdminRequired]
  64. public function help(string $mode = 'user'): TemplateResponse {
  65. $this->navigationManager->setActiveEntry('help');
  66. $pageTitle = $this->l10n->t('Administrator documentation');
  67. if ($mode !== 'admin') {
  68. $pageTitle = $this->l10n->t('User documentation');
  69. $mode = 'user';
  70. }
  71. $documentationUrl = $this->urlGenerator->getAbsoluteURL(
  72. $this->urlGenerator->linkTo('', 'core/doc/' . $mode . '/index.html')
  73. );
  74. $urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']);
  75. $urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']);
  76. $knowledgebaseEmbedded = $this->config->getSystemValueBool('knowledgebase.embedded', false);
  77. if (!$knowledgebaseEmbedded) {
  78. $pageTitle = $this->l10n->t('Nextcloud help overview');
  79. $urlUserDocs = $this->urlGenerator->linkToDocs('user');
  80. $urlAdminDocs = $this->urlGenerator->linkToDocs('admin');
  81. }
  82. $legalNoticeUrl = $this->appConfig->getValueString('theming', 'imprintUrl');
  83. $privacyUrl = $this->appConfig->getValueString('theming', 'privacyUrl');
  84. $response = new TemplateResponse('settings', 'help', [
  85. 'admin' => $this->groupManager->isAdmin($this->userId),
  86. 'url' => $documentationUrl,
  87. 'urlUserDocs' => $urlUserDocs,
  88. 'urlAdminDocs' => $urlAdminDocs,
  89. 'mode' => $mode,
  90. 'pageTitle' => $pageTitle,
  91. 'knowledgebaseEmbedded' => $knowledgebaseEmbedded,
  92. 'legalNoticeUrl' => $legalNoticeUrl,
  93. 'privacyUrl' => $privacyUrl,
  94. ]);
  95. $policy = new ContentSecurityPolicy();
  96. $policy->addAllowedFrameDomain('\'self\'');
  97. $response->setContentSecurityPolicy($policy);
  98. return $response;
  99. }
  100. }