Personal.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Sharing\Settings;
  8. use OCA\Files_Sharing\AppInfo\Application;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\AppFramework\Services\IInitialState;
  11. use OCP\IConfig;
  12. use OCP\Settings\ISettings;
  13. class Personal implements ISettings {
  14. /** @var IConfig */
  15. private $config;
  16. /** @var IInitialState */
  17. private $initialState;
  18. /** @var string */
  19. private $userId;
  20. public function __construct(IConfig $config, IInitialState $initialState, string $userId) {
  21. $this->config = $config;
  22. $this->initialState = $initialState;
  23. $this->userId = $userId;
  24. }
  25. public function getForm(): TemplateResponse {
  26. $defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes';
  27. $shareFolderSystemConfig = $this->config->getSystemValue('share_folder', '/');
  28. $acceptDefault = $this->config->getUserValue($this->userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes';
  29. $enforceAccept = $this->config->getSystemValueBool('sharing.force_share_accept', false);
  30. $allowCustomDirectory = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true);
  31. $shareFolderDefault = $this->config->getUserValue($this->userId, Application::APP_ID, 'share_folder', $shareFolderSystemConfig);
  32. $this->initialState->provideInitialState('accept_default', $acceptDefault);
  33. $this->initialState->provideInitialState('enforce_accept', $enforceAccept);
  34. $this->initialState->provideInitialState('allow_custom_share_folder', $allowCustomDirectory);
  35. $this->initialState->provideInitialState('share_folder', $shareFolderDefault);
  36. $this->initialState->provideInitialState('default_share_folder', $shareFolderSystemConfig);
  37. return new TemplateResponse('files_sharing', 'Settings/personal');
  38. }
  39. public function getSection(): string {
  40. return 'sharing';
  41. }
  42. public function getPriority(): int {
  43. return 90;
  44. }
  45. }