選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

HelpController.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. declare(strict_types=1);
  25. namespace OCA\Settings\Controller;
  26. use OCP\AppFramework\Controller;
  27. use OCP\AppFramework\Http\ContentSecurityPolicy;
  28. use OCP\AppFramework\Http\TemplateResponse;
  29. use OCP\IGroupManager;
  30. use OCP\INavigationManager;
  31. use OCP\IRequest;
  32. use OCP\IURLGenerator;
  33. use OCP\IUserSession;
  34. class HelpController extends Controller {
  35. /** @var INavigationManager */
  36. private $navigationManager;
  37. /** @var IUserSession */
  38. private $urlGenerator;
  39. /** @var IGroupManager */
  40. private $groupManager;
  41. /** @var string */
  42. private $userId;
  43. public function __construct(
  44. string $appName,
  45. IRequest $request,
  46. INavigationManager $navigationManager,
  47. IURLGenerator $urlGenerator,
  48. ?string $userId,
  49. IGroupManager $groupManager
  50. ) {
  51. parent::__construct($appName, $request);
  52. $this->navigationManager = $navigationManager;
  53. $this->urlGenerator = $urlGenerator;
  54. $this->userId = $userId;
  55. $this->groupManager = $groupManager;
  56. }
  57. /**
  58. * @return TemplateResponse
  59. *
  60. * @NoCSRFRequired
  61. * @NoAdminRequired
  62. * @NoSubadminRequired
  63. */
  64. public function help(string $mode = 'user'): TemplateResponse {
  65. $this->navigationManager->setActiveEntry('help');
  66. if(!isset($mode) || $mode !== 'admin') {
  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. $response = new TemplateResponse('settings', 'help', [
  75. 'admin' => $this->groupManager->isAdmin($this->userId),
  76. 'url' => $documentationUrl,
  77. 'urlUserDocs' => $urlUserDocs,
  78. 'urlAdminDocs' => $urlAdminDocs,
  79. 'mode' => $mode,
  80. ]);
  81. $policy = new ContentSecurityPolicy();
  82. $policy->addAllowedFrameDomain('\'self\'');
  83. $response->setContentSecurityPolicy($policy);
  84. return $response;
  85. }
  86. }