Personal.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Encryption\Settings;
  7. use OCA\Encryption\Session;
  8. use OCA\Encryption\Util;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\IConfig;
  11. use OCP\IUserSession;
  12. use OCP\Settings\ISettings;
  13. class Personal implements ISettings {
  14. /** @var IConfig */
  15. private $config;
  16. /** @var Session */
  17. private $session;
  18. /** @var Util */
  19. private $util;
  20. /** @var IUserSession */
  21. private $userSession;
  22. public function __construct(IConfig $config, Session $session, Util $util, IUserSession $userSession) {
  23. $this->config = $config;
  24. $this->session = $session;
  25. $this->util = $util;
  26. $this->userSession = $userSession;
  27. }
  28. /**
  29. * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
  30. * @since 9.1
  31. */
  32. public function getForm() {
  33. $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled');
  34. $privateKeySet = $this->session->isPrivateKeySet();
  35. if (!$recoveryAdminEnabled && $privateKeySet) {
  36. return new TemplateResponse('settings', 'settings/empty', [], '');
  37. }
  38. $userId = $this->userSession->getUser()->getUID();
  39. $recoveryEnabledForUser = $this->util->isRecoveryEnabledForUser($userId);
  40. $parameters = [
  41. 'recoveryEnabled' => $recoveryAdminEnabled,
  42. 'recoveryEnabledForUser' => $recoveryEnabledForUser,
  43. 'privateKeySet' => $privateKeySet,
  44. 'initialized' => $this->session->getStatus(),
  45. ];
  46. return new TemplateResponse('encryption', 'settings-personal', $parameters, '');
  47. }
  48. /**
  49. * @return string the section ID, e.g. 'sharing'
  50. * @since 9.1
  51. */
  52. public function getSection() {
  53. return 'security';
  54. }
  55. /**
  56. * @return int whether the form should be rather on the top or bottom of
  57. * the admin section. The forms are arranged in ascending order of the
  58. * priority values. It is required to return a value between 0 and 100.
  59. *
  60. * E.g.: 70
  61. * @since 9.1
  62. */
  63. public function getPriority() {
  64. return 80;
  65. }
  66. }