Personal.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Files_External\Settings;
  25. use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
  26. use OCA\Files_External\Service\BackendService;
  27. use OCA\Files_External\Service\UserGlobalStoragesService;
  28. use OCP\AppFramework\Http\TemplateResponse;
  29. use OCP\Encryption\IManager;
  30. use OCP\IUserSession;
  31. use OCP\Settings\ISettings;
  32. class Personal implements ISettings {
  33. /** @var IManager */
  34. private $encryptionManager;
  35. /** @var UserGlobalStoragesService */
  36. private $userGlobalStoragesService;
  37. /** @var BackendService */
  38. private $backendService;
  39. /** @var GlobalAuth */
  40. private $globalAuth;
  41. /** @var IUserSession */
  42. private $userSession;
  43. public function __construct(
  44. IManager $encryptionManager,
  45. UserGlobalStoragesService $userGlobalStoragesService,
  46. BackendService $backendService,
  47. GlobalAuth $globalAuth,
  48. IUserSession $userSession
  49. ) {
  50. $this->encryptionManager = $encryptionManager;
  51. $this->userGlobalStoragesService = $userGlobalStoragesService;
  52. $this->backendService = $backendService;
  53. $this->globalAuth = $globalAuth;
  54. $this->userSession = $userSession;
  55. }
  56. /**
  57. * @return TemplateResponse
  58. */
  59. public function getForm() {
  60. $uid = $this->userSession->getUser()->getUID();
  61. $parameters = [
  62. 'encryptionEnabled' => $this->encryptionManager->isEnabled(),
  63. 'visibilityType' => BackendService::VISIBILITY_PERSONAL,
  64. 'storages' => $this->userGlobalStoragesService->getStorages(),
  65. 'backends' => $this->backendService->getAvailableBackends(),
  66. 'authMechanisms' => $this->backendService->getAuthMechanisms(),
  67. 'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
  68. 'allowUserMounting' => $this->backendService->isUserMountingAllowed(),
  69. 'globalCredentials' => $this->globalAuth->getAuth($uid),
  70. 'globalCredentialsUid' => $uid,
  71. ];
  72. return new TemplateResponse('files_external', 'settings', $parameters, '');
  73. }
  74. /**
  75. * @return string the section ID, e.g. 'sharing'
  76. */
  77. public function getSection() {
  78. return 'externalstorages';
  79. }
  80. /**
  81. * @return int whether the form should be rather on the top or bottom of
  82. * the admin section. The forms are arranged in ascending order of the
  83. * priority values. It is required to return a value between 0 and 100.
  84. *
  85. * E.g.: 70
  86. */
  87. public function getPriority() {
  88. return 40;
  89. }
  90. }