HelpController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\INavigationManager;
  34. use OCP\IRequest;
  35. use OCP\IURLGenerator;
  36. class HelpController extends Controller {
  37. /** @var INavigationManager */
  38. private $navigationManager;
  39. /** @var IURLGenerator */
  40. private $urlGenerator;
  41. /** @var IGroupManager */
  42. private $groupManager;
  43. /** @var string */
  44. private $userId;
  45. public function __construct(
  46. string $appName,
  47. IRequest $request,
  48. INavigationManager $navigationManager,
  49. IURLGenerator $urlGenerator,
  50. ?string $userId,
  51. IGroupManager $groupManager
  52. ) {
  53. parent::__construct($appName, $request);
  54. $this->navigationManager = $navigationManager;
  55. $this->urlGenerator = $urlGenerator;
  56. $this->userId = $userId;
  57. $this->groupManager = $groupManager;
  58. }
  59. /**
  60. * @return TemplateResponse
  61. *
  62. * @NoCSRFRequired
  63. * @NoAdminRequired
  64. * @NoSubAdminRequired
  65. */
  66. public function help(string $mode = 'user'): TemplateResponse {
  67. $this->navigationManager->setActiveEntry('help');
  68. if ($mode !== 'admin') {
  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. $response = new TemplateResponse('settings', 'help', [
  77. 'admin' => $this->groupManager->isAdmin($this->userId),
  78. 'url' => $documentationUrl,
  79. 'urlUserDocs' => $urlUserDocs,
  80. 'urlAdminDocs' => $urlAdminDocs,
  81. 'mode' => $mode,
  82. ]);
  83. $policy = new ContentSecurityPolicy();
  84. $policy->addAllowedFrameDomain('\'self\'');
  85. $response->setContentSecurityPolicy($policy);
  86. return $response;
  87. }
  88. }