1
0

HelpController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. * @author Kate Döen <kate.doeen@nextcloud.com>
  12. *
  13. * @license GNU AGPL version 3 or any later version
  14. *
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License as
  17. * published by the Free Software Foundation, either version 3 of the
  18. * License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. */
  29. namespace OCA\Settings\Controller;
  30. use OCP\AppFramework\Controller;
  31. use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
  32. use OCP\AppFramework\Http\ContentSecurityPolicy;
  33. use OCP\AppFramework\Http\TemplateResponse;
  34. use OCP\IGroupManager;
  35. use OCP\IL10N;
  36. use OCP\INavigationManager;
  37. use OCP\IRequest;
  38. use OCP\IURLGenerator;
  39. use OCP\IConfig;
  40. #[IgnoreOpenAPI]
  41. class HelpController extends Controller {
  42. /** @var INavigationManager */
  43. private $navigationManager;
  44. /** @var IURLGenerator */
  45. private $urlGenerator;
  46. /** @var IGroupManager */
  47. private $groupManager;
  48. /** @var IL10N */
  49. private $l10n;
  50. /** @var string */
  51. private $userId;
  52. /** @var IConfig */
  53. private $config;
  54. public function __construct(
  55. string $appName,
  56. IRequest $request,
  57. INavigationManager $navigationManager,
  58. IURLGenerator $urlGenerator,
  59. ?string $userId,
  60. IGroupManager $groupManager,
  61. IL10N $l10n,
  62. IConfig $config,
  63. ) {
  64. parent::__construct($appName, $request);
  65. $this->navigationManager = $navigationManager;
  66. $this->urlGenerator = $urlGenerator;
  67. $this->userId = $userId;
  68. $this->groupManager = $groupManager;
  69. $this->l10n = $l10n;
  70. $this->config = $config;
  71. }
  72. /**
  73. * @return TemplateResponse
  74. *
  75. * @NoCSRFRequired
  76. * @NoAdminRequired
  77. * @NoSubAdminRequired
  78. */
  79. public function help(string $mode = 'user'): TemplateResponse {
  80. $this->navigationManager->setActiveEntry('help');
  81. $pageTitle = $this->l10n->t('Administrator documentation');
  82. if ($mode !== 'admin') {
  83. $pageTitle = $this->l10n->t('User documentation');
  84. $mode = 'user';
  85. }
  86. $documentationUrl = $this->urlGenerator->getAbsoluteURL(
  87. $this->urlGenerator->linkTo('', 'core/doc/' . $mode . '/index.html')
  88. );
  89. $urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']);
  90. $urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']);
  91. $knowledgebaseEmbedded = $this->config->getSystemValueBool('knowledgebase.embedded', false);
  92. if (!$knowledgebaseEmbedded) {
  93. $pageTitle = $this->l10n->t('Nextcloud help overview');
  94. $urlUserDocs = $this->urlGenerator->linkToDocs('user');
  95. $urlAdminDocs = $this->urlGenerator->linkToDocs('admin');
  96. }
  97. $response = new TemplateResponse('settings', 'help', [
  98. 'admin' => $this->groupManager->isAdmin($this->userId),
  99. 'url' => $documentationUrl,
  100. 'urlUserDocs' => $urlUserDocs,
  101. 'urlAdminDocs' => $urlAdminDocs,
  102. 'mode' => $mode,
  103. 'pageTitle' => $pageTitle,
  104. 'knowledgebaseEmbedded' => $knowledgebaseEmbedded,
  105. ]);
  106. $policy = new ContentSecurityPolicy();
  107. $policy->addAllowedFrameDomain('\'self\'');
  108. $response->setContentSecurityPolicy($policy);
  109. return $response;
  110. }
  111. }