diff options
Diffstat (limited to 'lib/private/Settings/Manager.php')
-rw-r--r-- | lib/private/Settings/Manager.php | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 982c2dba2ee..7e3edfa9df0 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -29,6 +29,7 @@ namespace OC\Settings; +use Closure; use OCP\AppFramework\QueryException; use OCP\IL10N; use OCP\ILogger; @@ -38,6 +39,7 @@ use OCP\L10N\IFactory; use OCP\Settings\ISettings; use OCP\Settings\IManager; use OCP\Settings\ISection; +use OCP\Settings\ISubAdminSettings; class Manager implements IManager { @@ -150,10 +152,11 @@ class Manager implements IManager { /** * @param string $type 'admin' or 'personal' * @param string $section + * @param Closure $filter optional filter to apply on all loaded ISettings * * @return ISettings[] */ - protected function getSettings(string $type, string $section): array { + protected function getSettings(string $type, string $section, Closure $filter = null): array { if (!isset($this->settings[$type])) { $this->settings[$type] = []; } @@ -162,6 +165,10 @@ class Manager implements IManager { } foreach ($this->settingClasses as $class => $settingsType) { + if ($type !== $settingsType) { + continue; + } + try { /** @var ISettings $setting */ $setting = \OC::$server->query($class); @@ -175,6 +182,9 @@ class Manager implements IManager { continue; } + if ($filter !== null && !$filter($setting)) { + continue; + } if ($setting->getSection() === null) { continue; } @@ -226,33 +236,44 @@ class Manager implements IManager { /** * @param string $section + * @param Closure $filter * * @return ISection[] */ - private function getBuiltInAdminSettings($section): array { + private function getBuiltInAdminSettings($section, Closure $filter = null): array { $forms = []; if ($section === 'overview') { /** @var ISettings $form */ $form = $this->container->query(Admin\Overview::class); - $forms[$form->getPriority()] = [$form]; + if ($filter === null || $filter($form)) { + $forms[$form->getPriority()] = [$form]; + } } if ($section === 'server') { /** @var ISettings $form */ $form = $this->container->query(Admin\Server::class); - $forms[$form->getPriority()] = [$form]; + if ($filter === null || $filter($form)) { + $forms[$form->getPriority()] = [$form]; + } $form = $this->container->query(Admin\Mail::class); - $forms[$form->getPriority()] = [$form]; + if ($filter === null || $filter($form)) { + $forms[$form->getPriority()] = [$form]; + } } if ($section === 'security') { /** @var ISettings $form */ $form = $this->container->query(Admin\Security::class); - $forms[$form->getPriority()] = [$form]; + if ($filter === null || $filter($form)) { + $forms[$form->getPriority()] = [$form]; + } } if ($section === 'sharing') { /** @var ISettings $form */ $form = $this->container->query(Admin\Sharing::class); - $forms[$form->getPriority()] = [$form]; + if ($filter === null || $filter($form)) { + $forms[$form->getPriority()] = [$form]; + } } return $forms; @@ -290,9 +311,17 @@ class Manager implements IManager { /** * @inheritdoc */ - public function getAdminSettings($section): array { - $settings = $this->getBuiltInAdminSettings($section); - $appSettings = $this->getSettings('admin', $section); + public function getAdminSettings($section, bool $subAdminOnly = false): array { + if ($subAdminOnly) { + $subAdminSettingsFilter = function(ISettings $settings) { + return $settings instanceof ISubAdminSettings; + }; + $settings = $this->getBuiltInAdminSettings($section, $subAdminSettingsFilter); + $appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter); + } else { + $settings = $this->getBuiltInAdminSettings($section); + $appSettings = $this->getSettings('admin', $section); + } foreach ($appSettings as $setting) { if (!isset($settings[$setting->getPriority()])) { |