HelpController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. public function __construct(
  24. string $appName,
  25. IRequest $request,
  26. private INavigationManager $navigationManager,
  27. private IURLGenerator $urlGenerator,
  28. /** @var string */
  29. private ?string $userId,
  30. private IGroupManager $groupManager,
  31. private IL10N $l10n,
  32. private IConfig $config,
  33. private IAppConfig $appConfig,
  34. ) {
  35. parent::__construct($appName, $request);
  36. }
  37. /**
  38. * @return TemplateResponse
  39. *
  40. * @NoSubAdminRequired
  41. */
  42. #[NoCSRFRequired]
  43. #[NoAdminRequired]
  44. public function help(string $mode = 'user'): TemplateResponse {
  45. $this->navigationManager->setActiveEntry('help');
  46. $pageTitle = $this->l10n->t('Administrator documentation');
  47. if ($mode !== 'admin') {
  48. $pageTitle = $this->l10n->t('User documentation');
  49. $mode = 'user';
  50. }
  51. $documentationUrl = $this->urlGenerator->getAbsoluteURL(
  52. $this->urlGenerator->linkTo('', 'core/doc/' . $mode . '/index.html')
  53. );
  54. $urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']);
  55. $urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']);
  56. $knowledgebaseEmbedded = $this->config->getSystemValueBool('knowledgebase.embedded', false);
  57. if (!$knowledgebaseEmbedded) {
  58. $pageTitle = $this->l10n->t('Nextcloud help overview');
  59. $urlUserDocs = $this->urlGenerator->linkToDocs('user');
  60. $urlAdminDocs = $this->urlGenerator->linkToDocs('admin');
  61. }
  62. $legalNoticeUrl = $this->appConfig->getValueString('theming', 'imprintUrl');
  63. $privacyUrl = $this->appConfig->getValueString('theming', 'privacyUrl');
  64. $response = new TemplateResponse('settings', 'help', [
  65. 'admin' => $this->groupManager->isAdmin($this->userId),
  66. 'url' => $documentationUrl,
  67. 'urlUserDocs' => $urlUserDocs,
  68. 'urlAdminDocs' => $urlAdminDocs,
  69. 'mode' => $mode,
  70. 'pageTitle' => $pageTitle,
  71. 'knowledgebaseEmbedded' => $knowledgebaseEmbedded,
  72. 'legalNoticeUrl' => $legalNoticeUrl,
  73. 'privacyUrl' => $privacyUrl,
  74. ]);
  75. $policy = new ContentSecurityPolicy();
  76. $policy->addAllowedFrameDomain('\'self\'');
  77. $response->setContentSecurityPolicy($policy);
  78. return $response;
  79. }
  80. }