123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace OCA\Settings\Controller;
- use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException;
- use OCP\AppFramework\Controller;
- use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
- use OCP\AppFramework\Http\TemplateResponse;
- use OCP\Group\ISubAdmin;
- use OCP\IGroupManager;
- use OCP\INavigationManager;
- use OCP\IRequest;
- use OCP\IUser;
- use OCP\IUserSession;
- use OCP\Settings\IManager as ISettingsManager;
- use OCP\Template;
- class AdminSettingsController extends Controller {
- use CommonSettingsTrait;
- public function __construct(
- $appName,
- IRequest $request,
- INavigationManager $navigationManager,
- ISettingsManager $settingsManager,
- IUserSession $userSession,
- IGroupManager $groupManager,
- ISubAdmin $subAdmin
- ) {
- parent::__construct($appName, $request);
- $this->navigationManager = $navigationManager;
- $this->settingsManager = $settingsManager;
- $this->userSession = $userSession;
- $this->groupManager = $groupManager;
- $this->subAdmin = $subAdmin;
- }
-
- public function index(string $section): TemplateResponse {
- return $this->getIndexResponse('admin', $section);
- }
-
- protected function getSettings($section) {
-
- $user = $this->userSession->getUser();
- $isSubAdmin = !$this->groupManager->isAdmin($user->getUID()) && $this->subAdmin->isSubAdmin($user);
- $settings = $this->settingsManager->getAllowedAdminSettings($section, $user);
- if (empty($settings)) {
- throw new NotAdminException("Logged in user doesn't have permission to access these settings.");
- }
- $formatted = $this->formatSettings($settings);
-
- if ($section === 'additional' && !$isSubAdmin) {
- $formatted['content'] .= $this->getLegacyForms();
- }
- return $formatted;
- }
-
- private function getLegacyForms() {
- $forms = \OC_App::getForms('admin');
- $forms = array_map(function ($form) {
- if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
- $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
- $sectionName = str_replace('</h2>', '', $sectionName);
- $anchor = strtolower($sectionName);
- $anchor = str_replace(' ', '-', $anchor);
- return [
- 'anchor' => $anchor,
- 'section-name' => $sectionName,
- 'form' => $form
- ];
- }
- return [
- 'form' => $form
- ];
- }, $forms);
- $out = new Template('settings', 'settings/additional');
- $out->assign('forms', $forms);
- return $out->fetchPage();
- }
- }
|