HelpController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\OpenAPI;
  10. use OCP\AppFramework\Http\ContentSecurityPolicy;
  11. use OCP\AppFramework\Http\TemplateResponse;
  12. use OCP\IAppConfig;
  13. use OCP\IConfig;
  14. use OCP\IGroupManager;
  15. use OCP\IL10N;
  16. use OCP\INavigationManager;
  17. use OCP\IRequest;
  18. use OCP\IURLGenerator;
  19. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  20. class HelpController extends Controller {
  21. /** @var INavigationManager */
  22. private $navigationManager;
  23. /** @var IURLGenerator */
  24. private $urlGenerator;
  25. /** @var IGroupManager */
  26. private $groupManager;
  27. /** @var IL10N */
  28. private $l10n;
  29. /** @var string */
  30. private $userId;
  31. /** @var IConfig */
  32. private $config;
  33. /** @var IAppConfig */
  34. private $appConfig;
  35. public function __construct(
  36. string $appName,
  37. IRequest $request,
  38. INavigationManager $navigationManager,
  39. IURLGenerator $urlGenerator,
  40. ?string $userId,
  41. IGroupManager $groupManager,
  42. IL10N $l10n,
  43. IConfig $config,
  44. IAppConfig $appConfig,
  45. ) {
  46. parent::__construct($appName, $request);
  47. $this->navigationManager = $navigationManager;
  48. $this->urlGenerator = $urlGenerator;
  49. $this->userId = $userId;
  50. $this->groupManager = $groupManager;
  51. $this->l10n = $l10n;
  52. $this->config = $config;
  53. $this->appConfig = $appConfig;
  54. }
  55. /**
  56. * @return TemplateResponse
  57. *
  58. * @NoCSRFRequired
  59. * @NoAdminRequired
  60. * @NoSubAdminRequired
  61. */
  62. public function help(string $mode = 'user'): TemplateResponse {
  63. $this->navigationManager->setActiveEntry('help');
  64. $pageTitle = $this->l10n->t('Administrator documentation');
  65. if ($mode !== 'admin') {
  66. $pageTitle = $this->l10n->t('User documentation');
  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. $knowledgebaseEmbedded = $this->config->getSystemValueBool('knowledgebase.embedded', false);
  75. if (!$knowledgebaseEmbedded) {
  76. $pageTitle = $this->l10n->t('Nextcloud help overview');
  77. $urlUserDocs = $this->urlGenerator->linkToDocs('user');
  78. $urlAdminDocs = $this->urlGenerator->linkToDocs('admin');
  79. }
  80. $legalNoticeUrl = $this->appConfig->getValueString('theming', 'imprintUrl');
  81. $privacyUrl = $this->appConfig->getValueString('theming', 'privacyUrl');
  82. $response = new TemplateResponse('settings', 'help', [
  83. 'admin' => $this->groupManager->isAdmin($this->userId),
  84. 'url' => $documentationUrl,
  85. 'urlUserDocs' => $urlUserDocs,
  86. 'urlAdminDocs' => $urlAdminDocs,
  87. 'mode' => $mode,
  88. 'pageTitle' => $pageTitle,
  89. 'knowledgebaseEmbedded' => $knowledgebaseEmbedded,
  90. 'legalNoticeUrl' => $legalNoticeUrl,
  91. 'privacyUrl' => $privacyUrl,
  92. ]);
  93. $policy = new ContentSecurityPolicy();
  94. $policy->addAllowedFrameDomain('\'self\'');
  95. $response->setContentSecurityPolicy($policy);
  96. return $response;
  97. }
  98. }