aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Settings/Manager.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Settings/Manager.php')
-rw-r--r--lib/private/Settings/Manager.php108
1 files changed, 40 insertions, 68 deletions
diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php
index 84fbf9426b0..78dc64c3c3f 100644
--- a/lib/private/Settings/Manager.php
+++ b/lib/private/Settings/Manager.php
@@ -1,33 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author sualko <klaus@jsxc.org>
- * @author Carl Schwan <carl@carlschwan.eu>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Settings;
@@ -48,7 +23,6 @@ use OCP\Settings\ISubAdminSettings;
use Psr\Log\LoggerInterface;
class Manager implements IManager {
-
/** @var LoggerInterface */
private $log;
@@ -80,7 +54,7 @@ class Manager implements IManager {
IServerContainer $container,
AuthorizedGroupMapper $mapper,
IGroupManager $groupManager,
- ISubAdmin $subAdmin
+ ISubAdmin $subAdmin,
) {
$this->log = $log;
$this->l10nFactory = $l10nFactory;
@@ -91,17 +65,14 @@ class Manager implements IManager {
$this->subAdmin = $subAdmin;
}
- /** @var array */
+ /** @var array<self::SETTINGS_*, list<class-string<IIconSection>>> */
protected $sectionClasses = [];
- /** @var array */
+ /** @var array<self::SETTINGS_*, array<string, IIconSection>> */
protected $sections = [];
/**
- * @param string $type 'admin' or 'personal'
- * @param string $section Class must implement OCP\Settings\IIconSection
- *
- * @return void
+ * @inheritdoc
*/
public function registerSection(string $type, string $section) {
if (!isset($this->sectionClasses[$type])) {
@@ -112,7 +83,7 @@ class Manager implements IManager {
}
/**
- * @param string $type 'admin' or 'personal'
+ * @psalm-param self::SETTINGS_* $type
*
* @return IIconSection[]
*/
@@ -126,8 +97,13 @@ class Manager implements IManager {
}
foreach (array_unique($this->sectionClasses[$type]) as $index => $class) {
- /** @var IIconSection $section */
- $section = \OC::$server->get($class);
+ try {
+ /** @var IIconSection $section */
+ $section = $this->container->get($class);
+ } catch (QueryException $e) {
+ $this->log->info($e->getMessage(), ['exception' => $e]);
+ continue;
+ }
$sectionID = $section->getID();
@@ -145,6 +121,16 @@ class Manager implements IManager {
return $this->sections[$type];
}
+ /**
+ * @inheritdoc
+ */
+ public function getSection(string $type, string $sectionId): ?IIconSection {
+ if (isset($this->sections[$type]) && isset($this->sections[$type][$sectionId])) {
+ return $this->sections[$type][$sectionId];
+ }
+ return null;
+ }
+
protected function isKnownDuplicateSectionId(string $sectionID): bool {
return in_array($sectionID, [
'connected-accounts',
@@ -152,31 +138,27 @@ class Manager implements IManager {
], true);
}
- /** @var array */
+ /** @var array<class-string<ISettings>, self::SETTINGS_*> */
protected $settingClasses = [];
- /** @var array */
+ /** @var array<self::SETTINGS_*, array<string, list<ISettings>>> */
protected $settings = [];
/**
- * @psam-param 'admin'|'personal' $type The type of the setting.
- * @param string $setting Class must implement OCP\Settings\ISettings
- * @param bool $allowedDelegation
- *
- * @return void
+ * @inheritdoc
*/
public function registerSetting(string $type, string $setting) {
$this->settingClasses[$setting] = $type;
}
/**
- * @param string $type 'admin' or 'personal'
+ * @psalm-param self::SETTINGS_* $type The type of the setting.
* @param string $section
- * @param Closure $filter optional filter to apply on all loaded ISettings
+ * @param ?Closure $filter optional filter to apply on all loaded ISettings
*
* @return ISettings[]
*/
- protected function getSettings(string $type, string $section, Closure $filter = null): array {
+ protected function getSettings(string $type, string $section, ?Closure $filter = null): array {
if (!isset($this->settings[$type])) {
$this->settings[$type] = [];
}
@@ -247,7 +229,7 @@ class Manager implements IManager {
/**
* @inheritdoc
*/
- public function getAdminSettings($section, bool $subAdminOnly = false): array {
+ public function getAdminSettings(string $section, bool $subAdminOnly = false): array {
if ($subAdminOnly) {
$subAdminSettingsFilter = function (ISettings $settings) {
return $settings instanceof ISubAdminSettings;
@@ -279,9 +261,7 @@ class Manager implements IManager {
$sections = [];
- $legacyForms = \OC_App::getForms('personal');
- if ((!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms))
- || count($this->getPersonalSettings('additional')) > 1) {
+ if (count($this->getPersonalSettings('additional')) > 1) {
$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
}
@@ -302,23 +282,9 @@ class Manager implements IManager {
}
/**
- * @param string[] $forms
- *
- * @return bool
- */
- private function hasLegacyPersonalSettingsToRender(array $forms): bool {
- foreach ($forms as $form) {
- if (trim($form) !== '') {
- return true;
- }
- }
- return false;
- }
-
- /**
* @inheritdoc
*/
- public function getPersonalSettings($section): array {
+ public function getPersonalSettings(string $section): array {
$settings = [];
$appSettings = $this->getSettings('personal', $section);
@@ -333,6 +299,9 @@ class Manager implements IManager {
return $settings;
}
+ /**
+ * @inheritdoc
+ */
public function getAllowedAdminSettings(string $section, IUser $user): array {
$isAdmin = $this->groupManager->isAdmin($user->getUID());
if ($isAdmin) {
@@ -364,6 +333,9 @@ class Manager implements IManager {
return $settings;
}
+ /**
+ * @inheritdoc
+ */
public function getAllAllowedAdminSettings(IUser $user): array {
$this->getSettings('admin', ''); // Make sure all the settings are loaded
$settings = [];