1
0

DeclarativeAdminSettings.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files\Settings;
  8. use OCA\Files\Service\SettingsService;
  9. use OCP\IL10N;
  10. use OCP\IUser;
  11. use OCP\Settings\DeclarativeSettingsTypes;
  12. use OCP\Settings\IDeclarativeSettingsFormWithHandlers;
  13. class DeclarativeAdminSettings implements IDeclarativeSettingsFormWithHandlers {
  14. public function __construct(
  15. private IL10N $l,
  16. private SettingsService $service,
  17. ) {
  18. }
  19. public function getValue(string $fieldId, IUser $user): mixed {
  20. return match($fieldId) {
  21. 'windows_support' => $this->service->hasFilesWindowsSupport(),
  22. default => throw new \InvalidArgumentException('Unexpected field id ' . $fieldId),
  23. };
  24. }
  25. public function setValue(string $fieldId, mixed $value, IUser $user): void {
  26. switch ($fieldId) {
  27. case 'windows_support':
  28. $this->service->setFilesWindowsSupport((bool)$value);
  29. break;
  30. }
  31. }
  32. public function getSchema(): array {
  33. return [
  34. 'id' => 'files-filename-support',
  35. 'priority' => 10,
  36. 'section_type' => DeclarativeSettingsTypes::SECTION_TYPE_ADMIN,
  37. 'section_id' => 'server',
  38. 'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_EXTERNAL,
  39. 'title' => $this->l->t('Files compatibility'),
  40. 'description' => $this->l->t('Allow to restrict filenames to ensure files can be synced with all clients. By default all filenames valid on POSIX (e.g. Linux or macOS) are allowed.'),
  41. 'fields' => [
  42. [
  43. 'id' => 'windows_support',
  44. 'title' => $this->l->t('Enforce Windows compatibility'),
  45. 'description' => $this->l->t('This will block filenames not valid on Windows systems, like using reserved names or special characters. But this will not enforce compatibility of case sensitivity.'),
  46. 'type' => DeclarativeSettingsTypes::CHECKBOX,
  47. 'default' => false,
  48. ],
  49. ],
  50. ];
  51. }
  52. }