You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AdminSettingsController.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Settings\Controller;
  27. use OCP\AppFramework\Controller;
  28. use OCP\AppFramework\Http\TemplateResponse;
  29. use OCP\Group\ISubAdmin;
  30. use OCP\IGroupManager;
  31. use OCP\INavigationManager;
  32. use OCP\IRequest;
  33. use OCP\IUser;
  34. use OCP\IUserSession;
  35. use OCP\Settings\IManager as ISettingsManager;
  36. use OCP\Template;
  37. class AdminSettingsController extends Controller {
  38. use CommonSettingsTrait;
  39. public function __construct(
  40. $appName,
  41. IRequest $request,
  42. INavigationManager $navigationManager,
  43. ISettingsManager $settingsManager,
  44. IUserSession $userSession,
  45. IGroupManager $groupManager,
  46. ISubAdmin $subAdmin
  47. ) {
  48. parent::__construct($appName, $request);
  49. $this->navigationManager = $navigationManager;
  50. $this->settingsManager = $settingsManager;
  51. $this->userSession = $userSession;
  52. $this->groupManager = $groupManager;
  53. $this->subAdmin = $subAdmin;
  54. }
  55. /**
  56. * @param string $section
  57. * @return TemplateResponse
  58. *
  59. * @NoCSRFRequired
  60. * @SubAdminRequired
  61. */
  62. public function index($section) {
  63. return $this->getIndexResponse('admin', $section);
  64. }
  65. /**
  66. * @param string $section
  67. * @return array
  68. */
  69. protected function getSettings($section) {
  70. /** @var IUser $user */
  71. $user = $this->userSession->getUser();
  72. $isSubAdmin = !$this->groupManager->isAdmin($user->getUID()) && $this->subAdmin->isSubAdmin($user);
  73. $settings = $this->settingsManager->getAdminSettings(
  74. $section,
  75. $isSubAdmin
  76. );
  77. $formatted = $this->formatSettings($settings);
  78. // Do not show legacy forms for sub admins
  79. if($section === 'additional' && !$isSubAdmin) {
  80. $formatted['content'] .= $this->getLegacyForms();
  81. }
  82. return $formatted;
  83. }
  84. /**
  85. * @return bool|string
  86. */
  87. private function getLegacyForms() {
  88. $forms = \OC_App::getForms('admin');
  89. $forms = array_map(function ($form) {
  90. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  91. $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
  92. $sectionName = str_replace('</h2>', '', $sectionName);
  93. $anchor = strtolower($sectionName);
  94. $anchor = str_replace(' ', '-', $anchor);
  95. return [
  96. 'anchor' => $anchor,
  97. 'section-name' => $sectionName,
  98. 'form' => $form
  99. ];
  100. }
  101. return [
  102. 'form' => $form
  103. ];
  104. }, $forms);
  105. $out = new Template('settings', 'settings/additional');
  106. $out->assign('forms', $forms);
  107. return $out->fetchPage();
  108. }
  109. }