Personal.php 1.8 KB

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