Personal.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Files_External\Settings;
  7. use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
  8. use OCA\Files_External\Service\BackendService;
  9. use OCA\Files_External\Service\UserGlobalStoragesService;
  10. use OCP\AppFramework\Http\TemplateResponse;
  11. use OCP\Encryption\IManager;
  12. use OCP\IUserSession;
  13. use OCP\Settings\ISettings;
  14. class Personal implements ISettings {
  15. /** @var IManager */
  16. private $encryptionManager;
  17. /** @var UserGlobalStoragesService */
  18. private $userGlobalStoragesService;
  19. /** @var BackendService */
  20. private $backendService;
  21. /** @var GlobalAuth */
  22. private $globalAuth;
  23. /** @var IUserSession */
  24. private $userSession;
  25. public function __construct(
  26. IManager $encryptionManager,
  27. UserGlobalStoragesService $userGlobalStoragesService,
  28. BackendService $backendService,
  29. GlobalAuth $globalAuth,
  30. IUserSession $userSession
  31. ) {
  32. $this->encryptionManager = $encryptionManager;
  33. $this->userGlobalStoragesService = $userGlobalStoragesService;
  34. $this->backendService = $backendService;
  35. $this->globalAuth = $globalAuth;
  36. $this->userSession = $userSession;
  37. }
  38. /**
  39. * @return TemplateResponse
  40. */
  41. public function getForm() {
  42. $uid = $this->userSession->getUser()->getUID();
  43. $parameters = [
  44. 'encryptionEnabled' => $this->encryptionManager->isEnabled(),
  45. 'visibilityType' => BackendService::VISIBILITY_PERSONAL,
  46. 'storages' => $this->userGlobalStoragesService->getStorages(),
  47. 'backends' => $this->backendService->getAvailableBackends(),
  48. 'authMechanisms' => $this->backendService->getAuthMechanisms(),
  49. 'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
  50. 'allowUserMounting' => $this->backendService->isUserMountingAllowed(),
  51. 'globalCredentials' => $this->globalAuth->getAuth($uid),
  52. 'globalCredentialsUid' => $uid,
  53. ];
  54. return new TemplateResponse('files_external', 'settings', $parameters, '');
  55. }
  56. /**
  57. * @return string the section ID, e.g. 'sharing'
  58. */
  59. public function getSection() {
  60. return 'externalstorages';
  61. }
  62. /**
  63. * @return int whether the form should be rather on the top or bottom of
  64. * the admin section. The forms are arranged in ascending order of the
  65. * priority values. It is required to return a value between 0 and 100.
  66. *
  67. * E.g.: 70
  68. */
  69. public function getPriority() {
  70. return 40;
  71. }
  72. }