OCJSController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  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 OC\Core\Controller;
  29. use bantu\IniGetWrapper\IniGetWrapper;
  30. use OC\Authentication\Token\IProvider;
  31. use OC\CapabilitiesManager;
  32. use OC\Template\JSConfigHelper;
  33. use OCP\App\IAppManager;
  34. use OCP\AppFramework\Controller;
  35. use OCP\AppFramework\Http;
  36. use OCP\AppFramework\Http\DataDisplayResponse;
  37. use OCP\Defaults;
  38. use OCP\IConfig;
  39. use OCP\IGroupManager;
  40. use OCP\IInitialStateService;
  41. use OCP\IRequest;
  42. use OCP\ISession;
  43. use OCP\IURLGenerator;
  44. use OCP\IUserSession;
  45. use OCP\L10N\IFactory;
  46. class OCJSController extends Controller {
  47. private JSConfigHelper $helper;
  48. public function __construct(string $appName,
  49. IRequest $request,
  50. IFactory $l10nFactory,
  51. Defaults $defaults,
  52. IAppManager $appManager,
  53. ISession $session,
  54. IUserSession $userSession,
  55. IConfig $config,
  56. IGroupManager $groupManager,
  57. IniGetWrapper $iniWrapper,
  58. IURLGenerator $urlGenerator,
  59. CapabilitiesManager $capabilitiesManager,
  60. IInitialStateService $initialStateService,
  61. IProvider $tokenProvider,
  62. ) {
  63. parent::__construct($appName, $request);
  64. $this->helper = new JSConfigHelper(
  65. $l10nFactory->get('lib'),
  66. $defaults,
  67. $appManager,
  68. $session,
  69. $userSession->getUser(),
  70. $config,
  71. $groupManager,
  72. $iniWrapper,
  73. $urlGenerator,
  74. $capabilitiesManager,
  75. $initialStateService,
  76. $tokenProvider
  77. );
  78. }
  79. /**
  80. * @NoCSRFRequired
  81. * @NoTwoFactorRequired
  82. * @PublicPage
  83. */
  84. public function getConfig(): DataDisplayResponse {
  85. $data = $this->helper->getConfig();
  86. return new DataDisplayResponse($data, Http::STATUS_OK, ['Content-type' => 'text/javascript']);
  87. }
  88. }