diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-03-15 13:03:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-15 13:03:34 +0100 |
commit | 9338ef36ded767f2c35b7ec575b351859420ed09 (patch) | |
tree | 65c53c6a36f300859dc22b2d423275bcf2911367 /lib/public/Settings | |
parent | 6b09a79227a5dc98aa4620c6e5e15b610a06c806 (diff) | |
parent | df1cd1ba7e6e1f6e66a2b3229b5c082f1b81162e (diff) | |
download | nextcloud-server-9338ef36ded767f2c35b7ec575b351859420ed09.tar.gz nextcloud-server-9338ef36ded767f2c35b7ec575b351859420ed09.zip |
Merge branch 'master' into refactor/OC-Server-getShareManager
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
Diffstat (limited to 'lib/public/Settings')
-rw-r--r-- | lib/public/Settings/DeclarativeSettingsTypes.php | 145 | ||||
-rw-r--r-- | lib/public/Settings/Events/DeclarativeSettingsGetValueEvent.php | 105 | ||||
-rw-r--r-- | lib/public/Settings/Events/DeclarativeSettingsRegisterFormEvent.php | 53 | ||||
-rw-r--r-- | lib/public/Settings/Events/DeclarativeSettingsSetValueEvent.php | 87 | ||||
-rw-r--r-- | lib/public/Settings/IDeclarativeManager.php | 92 | ||||
-rw-r--r-- | lib/public/Settings/IDeclarativeSettingsForm.php | 81 | ||||
-rw-r--r-- | lib/public/Settings/IManager.php | 38 |
7 files changed, 590 insertions, 11 deletions
diff --git a/lib/public/Settings/DeclarativeSettingsTypes.php b/lib/public/Settings/DeclarativeSettingsTypes.php new file mode 100644 index 00000000000..01e20ee7cc9 --- /dev/null +++ b/lib/public/Settings/DeclarativeSettingsTypes.php @@ -0,0 +1,145 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Andrey Borysenko <andrey.borysenko@nextcloud.com> + * + * @author Andrey Borysenko <andrey.borysenko@nextcloud.com> + * + * @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/>. + * + */ + +namespace OCP\Settings; + +/** + * Declarative settings types supported in the IDeclarativeSettingsForm forms + * + * @since 29.0.0 + */ +final class DeclarativeSettingsTypes { + /** + * IDeclarativeSettingsForm section_type which is determines where the form is displayed + * + * @since 29.0.0 + */ + public const SECTION_TYPE_ADMIN = 'admin'; + + /** + * IDeclarativeSettingsForm section_type which is determines where the form is displayed + * + * @since 29.0.0 + */ + public const SECTION_TYPE_PERSONAL = 'personal'; + + /** + * IDeclarativeSettingsForm storage_type which is determines where and how the config value is stored + * + * + * For `external` storage_type the app implementing \OCP\Settings\SetDeclarativeSettingsValueEvent and \OCP\Settings\GetDeclarativeSettingsValueEvent events is responsible for storing and retrieving the config value. + * + * @since 29.0.0 + */ + public const STORAGE_TYPE_EXTERNAL = 'external'; + + /** + * IDeclarativeSettingsForm storage_type which is determines where and how the config value is stored + * + * For `internal` storage_type the config value is stored in default `appconfig` and `preferences` tables. + * For `external` storage_type the app implementing \OCP\Settings\SetDeclarativeSettingsValueEvent and \OCP\Settings\GetDeclarativeSettingsValueEvent events is responsible for storing and retrieving the config value. + * + * @since 29.0.0 + */ + public const STORAGE_TYPE_INTERNAL = 'internal'; + + /** + * NcInputField type text + * + * @since 29.0.0 + */ + public const TEXT = 'text'; + + /** + * NcInputField type password + * + * @since 29.0.0 + */ + public const PASSWORD = 'password'; + + /** + * NcInputField type email + * + * @since 29.0.0 + */ + public const EMAIL = 'email'; + + /** + * NcInputField type tel + * + * @since 29.0.0 + */ + public const TEL = 'tel'; + + /** + * NcInputField type url + * + * @since 29.0.0 + */ + public const URL = 'url'; + + /** + * NcInputField type number + * + * @since 29.0.0 + */ + public const NUMBER = 'number'; + + /** + * NcCheckboxRadioSwitch type checkbox + * + * @since 29.0.0 + */ + public const CHECKBOX = 'checkbox'; + + /** + * Multiple NcCheckboxRadioSwitch type checkbox representing a one config value (saved as JSON object) + * + * @since 29.0.0 + */ + public const MULTI_CHECKBOX = 'multi-checkbox'; + + /** + * NcCheckboxRadioSwitch type radio + * + * @since 29.0.0 + */ + public const RADIO = 'radio'; + + /** + * NcSelect + * + * @since 29.0.0 + */ + public const SELECT = 'select'; + + /** + * Multiple NcSelect representing a one config value (saved as JSON array) + * + * @since 29.0.0 + */ + public const MULTI_SELECT = 'multi-select'; +} diff --git a/lib/public/Settings/Events/DeclarativeSettingsGetValueEvent.php b/lib/public/Settings/Events/DeclarativeSettingsGetValueEvent.php new file mode 100644 index 00000000000..925bf9fe711 --- /dev/null +++ b/lib/public/Settings/Events/DeclarativeSettingsGetValueEvent.php @@ -0,0 +1,105 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Kate Döen <kate.doeen@nextcloud.com> + * + * @author Kate Döen <kate.doeen@nextcloud.com> + * + * @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/>. + * + */ + +namespace OCP\Settings\Events; + +use Exception; +use OCP\EventDispatcher\Event; +use OCP\IUser; +use OCP\Settings\IDeclarativeSettingsForm; + +/** + * @psalm-import-type DeclarativeSettingsValueTypes from IDeclarativeSettingsForm + * + * @since 29.0.0 + */ +class DeclarativeSettingsGetValueEvent extends Event { + /** + * @var ?DeclarativeSettingsValueTypes + */ + private mixed $value = null; + + /** + * @since 29.0.0 + */ + public function __construct( + private IUser $user, + private string $app, + private string $formId, + private string $fieldId, + ) { + parent::__construct(); + } + + /** + * @since 29.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + + /** + * @since 29.0.0 + */ + public function getApp(): string { + return $this->app; + } + + /** + * @since 29.0.0 + */ + public function getFormId(): string { + return $this->formId; + } + + /** + * @since 29.0.0 + */ + public function getFieldId(): string { + return $this->fieldId; + } + + /** + * @since 29.0.0 + */ + public function setValue(mixed $value): void { + $this->value = $value; + } + + /** + * @return DeclarativeSettingsValueTypes + * @throws Exception + * + * @since 29.0.0 + */ + public function getValue(): mixed { + if ($this->value === null) { + throw new Exception('Value not set'); + } + + return $this->value; + } +} diff --git a/lib/public/Settings/Events/DeclarativeSettingsRegisterFormEvent.php b/lib/public/Settings/Events/DeclarativeSettingsRegisterFormEvent.php new file mode 100644 index 00000000000..a9ea399fc20 --- /dev/null +++ b/lib/public/Settings/Events/DeclarativeSettingsRegisterFormEvent.php @@ -0,0 +1,53 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Kate Döen <kate.doeen@nextcloud.com> + * + * @author Kate Döen <kate.doeen@nextcloud.com> + * + * @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/>. + * + */ + +namespace OCP\Settings\Events; + +use OCP\EventDispatcher\Event; +use OCP\Settings\IDeclarativeManager; +use OCP\Settings\IDeclarativeSettingsForm; + +/** + * @psalm-import-type DeclarativeSettingsFormSchemaWithoutValues from IDeclarativeSettingsForm + * + * @since 29.0.0 + */ +class DeclarativeSettingsRegisterFormEvent extends Event { + /** + * @since 29.0.0 + */ + public function __construct(private IDeclarativeManager $manager) { + parent::__construct(); + } + + /** + * @param DeclarativeSettingsFormSchemaWithoutValues $schema + * @since 29.0.0 + */ + public function registerSchema(string $app, array $schema): void { + $this->manager->registerSchema($app, $schema); + } +} diff --git a/lib/public/Settings/Events/DeclarativeSettingsSetValueEvent.php b/lib/public/Settings/Events/DeclarativeSettingsSetValueEvent.php new file mode 100644 index 00000000000..f94c17681a8 --- /dev/null +++ b/lib/public/Settings/Events/DeclarativeSettingsSetValueEvent.php @@ -0,0 +1,87 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Kate Döen <kate.doeen@nextcloud.com> + * + * @author Kate Döen <kate.doeen@nextcloud.com> + * + * @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/>. + * + */ + +namespace OCP\Settings\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; +use OCP\Settings\IDeclarativeSettingsForm; + +/** + * @psalm-import-type DeclarativeSettingsValueTypes from IDeclarativeSettingsForm + * + * @since 29.0.0 + */ +class DeclarativeSettingsSetValueEvent extends Event { + /** + * @param DeclarativeSettingsValueTypes $value + * @since 29.0.0 + */ + public function __construct( + private IUser $user, + private string $app, + private string $formId, + private string $fieldId, + private mixed $value, + ) { + parent::__construct(); + } + + /** + * @since 29.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + + /** + * @since 29.0.0 + */ + public function getApp(): string { + return $this->app; + } + + /** + * @since 29.0.0 + */ + public function getFormId(): string { + return $this->formId; + } + + /** + * @since 29.0.0 + */ + public function getFieldId(): string { + return $this->fieldId; + } + + /** + * @since 29.0.0 + */ + public function getValue(): mixed { + return $this->value; + } +} diff --git a/lib/public/Settings/IDeclarativeManager.php b/lib/public/Settings/IDeclarativeManager.php new file mode 100644 index 00000000000..ac5bef6ed26 --- /dev/null +++ b/lib/public/Settings/IDeclarativeManager.php @@ -0,0 +1,92 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Kate Döen <kate.doeen@nextcloud.com> + * + * @author Kate Döen <kate.doeen@nextcloud.com> + * + * @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/>. + * + */ + +namespace OCP\Settings; + +use Exception; +use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException; +use OCP\IUser; + +/** + * @since 29.0.0 + * + * @psalm-import-type DeclarativeSettingsValueTypes from IDeclarativeSettingsForm + * @psalm-import-type DeclarativeSettingsSectionType from IDeclarativeSettingsForm + * @psalm-import-type DeclarativeSettingsFormSchemaWithValues from IDeclarativeSettingsForm + * @psalm-import-type DeclarativeSettingsFormSchemaWithoutValues from IDeclarativeSettingsForm + */ +interface IDeclarativeManager { + /** + * Registers a new declarative settings schema. + * + * @param DeclarativeSettingsFormSchemaWithoutValues $schema + * @since 29.0.0 + */ + public function registerSchema(string $app, array $schema): void; + + /** + * Load all schemas from the registration context and events. + * + * @since 29.0.0 + */ + public function loadSchemas(): void; + + /** + * Gets the IDs of the forms for the given type and section. + * + * @param DeclarativeSettingsSectionType $type + * @param string $section + * @return array<string, list<string>> + * + * @since 29.0.0 + */ + public function getFormIDs(IUser $user, string $type, string $section): array; + + /** + * Gets the forms including the field values for the given type and section. + * + * @param IUser $user Used for reading values from the personal section or for authorization for the admin section. + * @param ?DeclarativeSettingsSectionType $type If it is null the forms will not be filtered by type. + * @param ?string $section If it is null the forms will not be filtered by section. + * @return list<DeclarativeSettingsFormSchemaWithValues> + * + * @since 29.0.0 + */ + public function getFormsWithValues(IUser $user, ?string $type, ?string $section): array; + + /** + * Sets a value for the given field ID. + * + * @param IUser $user Used for storing values in the personal section or for authorization for the admin section. + * @param DeclarativeSettingsValueTypes $value + * + * @throws Exception + * @throws NotAdminException + * + * @since 29.0.0 + */ + public function setValue(IUser $user, string $app, string $formId, string $fieldId, mixed $value): void; +} diff --git a/lib/public/Settings/IDeclarativeSettingsForm.php b/lib/public/Settings/IDeclarativeSettingsForm.php new file mode 100644 index 00000000000..7513af8217c --- /dev/null +++ b/lib/public/Settings/IDeclarativeSettingsForm.php @@ -0,0 +1,81 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Kate Döen <kate.doeen@nextcloud.com> + * + * @author Kate Döen <kate.doeen@nextcloud.com> + * + * @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/>. + * + */ + +namespace OCP\Settings; + +/** + * @since 29.0.0 + * + * @psalm-type DeclarativeSettingsSectionType = 'admin'|'personal' + * + * @psalm-type DeclarativeSettingsStorageType = 'internal'|'external' + * + * @psalm-type DeclarativeSettingsValueTypes = string|int|float|bool|list<string> + * + * @psalm-type DeclarativeSettingsFormField = array{ + * id: string, + * title: string, + * description?: string, + * type: 'text'|'password'|'email'|'tel'|'url'|'number'|'checkbox'|'multi-checkbox'|'radio'|'select'|'multi-select', + * placeholder?: string, + * label?: string, + * default: mixed, + * options?: list<string|array{name: string, value: mixed}>, + * } + * + * @psalm-type DeclarativeSettingsFormFieldWithValue = DeclarativeSettingsFormField&array{ + * value: DeclarativeSettingsValueTypes, + * } + * + * @psalm-type DeclarativeSettingsFormSchema = array{ + * id: string, + * priority: int, + * section_type: DeclarativeSettingsSectionType, + * section_id: string, + * storage_type: DeclarativeSettingsStorageType, + * title: string, + * description?: string, + * doc_url?: string, + * } + * + * @psalm-type DeclarativeSettingsFormSchemaWithValues = DeclarativeSettingsFormSchema&array{ + * app: string, + * fields: list<DeclarativeSettingsFormFieldWithValue>, + * } + * + * @psalm-type DeclarativeSettingsFormSchemaWithoutValues = DeclarativeSettingsFormSchema&array{ + * fields: list<DeclarativeSettingsFormField>, + * } + */ +interface IDeclarativeSettingsForm { + /** + * Gets the schema that defines the declarative settings form + * + * @return DeclarativeSettingsFormSchemaWithoutValues + * @since 29.0.0 + */ + public function getSchema(): array; +} diff --git a/lib/public/Settings/IManager.php b/lib/public/Settings/IManager.php index 10de596dbea..dbbbf3f57e4 100644 --- a/lib/public/Settings/IManager.php +++ b/lib/public/Settings/IManager.php @@ -6,6 +6,7 @@ * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author Lukas Reschke <lukas@statuscode.ch> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license GNU AGPL version 3 or any later version * @@ -34,34 +35,48 @@ use OCP\IUser; interface IManager { /** * @since 9.1.0 + * @deprecated 29.0.0 Use {@see self::SETTINGS_ADMIN} instead */ public const KEY_ADMIN_SETTINGS = 'admin'; /** * @since 9.1.0 + * @deprecated 29.0.0 Use {@see self::SETTINGS_ADMIN} instead */ public const KEY_ADMIN_SECTION = 'admin-section'; /** * @since 13.0.0 + * @deprecated 29.0.0 Use {@see self::SETTINGS_PERSONAL} instead */ public const KEY_PERSONAL_SETTINGS = 'personal'; /** * @since 13.0.0 + * @deprecated 29.0.0 Use {@see self::SETTINGS_PERSONAL} instead */ public const KEY_PERSONAL_SECTION = 'personal-section'; /** - * @param string $type 'admin-section' or 'personal-section' - * @param string $section Class must implement OCP\Settings\ISection + * @since 29.0.0 + */ + public const SETTINGS_ADMIN = 'admin'; + + /** + * @since 29.0.0 + */ + public const SETTINGS_PERSONAL = 'personal'; + + /** + * @psalm-param self::SETTINGS_* $type + * @param class-string<IIconSection> $section * @since 14.0.0 */ public function registerSection(string $type, string $section); /** - * @param string $type 'admin' or 'personal' - * @param string $setting Class must implement OCP\Settings\ISettings + * @psalm-param self::SETTINGS_* $type + * @param class-string<ISettings> $setting * @since 14.0.0 */ public function registerSetting(string $type, string $setting); @@ -69,7 +84,7 @@ interface IManager { /** * returns a list of the admin sections * - * @return array<int, array<int, IIconSection>> array from IConSection[] where key is the priority + * @return array<int, list<IIconSection>> list of sections with priority as key * @since 9.1.0 */ public function getAdminSections(): array; @@ -77,7 +92,7 @@ interface IManager { /** * returns a list of the personal sections * - * @return array array of ISection[] where key is the priority + * @return array<int, list<IIconSection>> list of sections with priority as key * @since 13.0.0 */ public function getPersonalSections(): array; @@ -87,10 +102,10 @@ interface IManager { * * @param string $section the section id for which to load the settings * @param bool $subAdminOnly only return settings sub admins are supposed to see (since 17.0.0) - * @return array<int, array<int, ISettings>> array of ISettings[] where key is the priority + * @return array<int, list<ISettings>> list of settings with priority as key * @since 9.1.0 */ - public function getAdminSettings($section, bool $subAdminOnly = false): array; + public function getAdminSettings(string $section, bool $subAdminOnly = false): array; /** * Returns a list of admin settings that the given user can use for the give section @@ -103,7 +118,7 @@ interface IManager { /** * Returns a list of admin settings that the given user can use. * - * @return array<int, list<ISettings>> The array of admin settings there admin delegation is allowed. + * @return list<ISettings> The array of admin settings there admin delegation is allowed. * @since 23.0.0 */ public function getAllAllowedAdminSettings(IUser $user): array; @@ -112,13 +127,14 @@ interface IManager { * returns a list of the personal settings * * @param string $section the section id for which to load the settings - * @return array array of ISettings[] where key is the priority + * @return array<int, list<ISettings>> list of settings with priority as key * @since 13.0.0 */ - public function getPersonalSettings($section): array; + public function getPersonalSettings(string $section): array; /** * Get a specific section by type and id + * @psalm-param self::SETTINGS_* $type * @since 25.0.0 */ public function getSection(string $type, string $sectionId): ?IIconSection; |