Personal.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Hinrich Mahler <nextcloud@mahlerhome.de>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Files_Sharing\Settings;
  27. use OCA\Files_Sharing\AppInfo\Application;
  28. use OCP\AppFramework\Http\TemplateResponse;
  29. use OCP\AppFramework\Services\IInitialState;
  30. use OCP\IConfig;
  31. use OCP\Settings\ISettings;
  32. class Personal implements ISettings {
  33. /** @var IConfig */
  34. private $config;
  35. /** @var IInitialState */
  36. private $initialState;
  37. /** @var string */
  38. private $userId;
  39. public function __construct(IConfig $config, IInitialState $initialState, string $userId) {
  40. $this->config = $config;
  41. $this->initialState = $initialState;
  42. $this->userId = $userId;
  43. }
  44. public function getForm(): TemplateResponse {
  45. $defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes';
  46. $shareFolderSystemConfig = $this->config->getSystemValue('share_folder', '/');
  47. $acceptDefault = $this->config->getUserValue($this->userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes';
  48. $enforceAccept = $this->config->getSystemValueBool('sharing.force_share_accept', false);
  49. $allowCustomDirectory = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true);
  50. $shareFolderDefault = $this->config->getUserValue($this->userId, Application::APP_ID, 'share_folder', $shareFolderSystemConfig);
  51. $this->initialState->provideInitialState('accept_default', $acceptDefault);
  52. $this->initialState->provideInitialState('enforce_accept', $enforceAccept);
  53. $this->initialState->provideInitialState('allow_custom_share_folder', $allowCustomDirectory);
  54. $this->initialState->provideInitialState('share_folder', $shareFolderDefault);
  55. $this->initialState->provideInitialState('default_share_folder', $shareFolderSystemConfig);
  56. return new TemplateResponse('files_sharing', 'Settings/personal');
  57. }
  58. public function getSection(): string {
  59. return 'sharing';
  60. }
  61. public function getPriority(): int {
  62. return 90;
  63. }
  64. }