1
0

SettingsController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Hinrich Mahler <nextcloud@mahlerhome.de>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Files_Sharing\Controller;
  26. use OCA\Files_Sharing\AppInfo\Application;
  27. use OCP\AppFramework\Controller;
  28. use OCP\AppFramework\Http\JSONResponse;
  29. use OCP\IConfig;
  30. use OCP\IRequest;
  31. class SettingsController extends Controller {
  32. /** @var IConfig */
  33. private $config;
  34. /** @var string */
  35. private $userId;
  36. public function __construct(IRequest $request,
  37. IConfig $config,
  38. string $userId) {
  39. parent::__construct(Application::APP_ID, $request);
  40. $this->config = $config;
  41. $this->userId = $userId;
  42. }
  43. /**
  44. * @NoAdminRequired
  45. */
  46. public function setDefaultAccept(bool $accept): JSONResponse {
  47. $this->config->setUserValue($this->userId, Application::APP_ID, 'default_accept', $accept ? 'yes' : 'no');
  48. return new JSONResponse();
  49. }
  50. /**
  51. * @NoAdminRequired
  52. */
  53. public function setUserShareFolder(string $shareFolder): JSONResponse {
  54. $this->config->setUserValue($this->userId, Application::APP_ID, 'share_folder', $shareFolder);
  55. return new JSONResponse();
  56. }
  57. /**
  58. * @NoAdminRequired
  59. */
  60. public function resetUserShareFolder(): JSONResponse {
  61. $this->config->deleteUserValue($this->userId, Application::APP_ID, 'share_folder');
  62. return new JSONResponse();
  63. }
  64. }