Personal.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  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\Encryption\Settings;
  25. use OCA\Encryption\Session;
  26. use OCA\Encryption\Util;
  27. use OCP\AppFramework\Http\TemplateResponse;
  28. use OCP\IConfig;
  29. use OCP\IUserSession;
  30. use OCP\Settings\ISettings;
  31. class Personal implements ISettings {
  32. /** @var IConfig */
  33. private $config;
  34. /** @var Session */
  35. private $session;
  36. /** @var Util */
  37. private $util;
  38. /** @var IUserSession */
  39. private $userSession;
  40. public function __construct(IConfig $config, Session $session, Util $util, IUserSession $userSession) {
  41. $this->config = $config;
  42. $this->session = $session;
  43. $this->util = $util;
  44. $this->userSession = $userSession;
  45. }
  46. /**
  47. * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
  48. * @since 9.1
  49. */
  50. public function getForm() {
  51. $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled');
  52. $privateKeySet = $this->session->isPrivateKeySet();
  53. if (!$recoveryAdminEnabled && $privateKeySet) {
  54. return new TemplateResponse('settings', 'settings/empty', [], '');
  55. }
  56. $userId = $this->userSession->getUser()->getUID();
  57. $recoveryEnabledForUser = $this->util->isRecoveryEnabledForUser($userId);
  58. $parameters = [
  59. 'recoveryEnabled' => $recoveryAdminEnabled,
  60. 'recoveryEnabledForUser' => $recoveryEnabledForUser,
  61. 'privateKeySet' => $privateKeySet,
  62. 'initialized' => $this->session->getStatus(),
  63. ];
  64. return new TemplateResponse('encryption', 'settings-personal', $parameters, '');
  65. }
  66. /**
  67. * @return string the section ID, e.g. 'sharing'
  68. * @since 9.1
  69. */
  70. public function getSection() {
  71. return 'security';
  72. }
  73. /**
  74. * @return int whether the form should be rather on the top or bottom of
  75. * the admin section. The forms are arranged in ascending order of the
  76. * priority values. It is required to return a value between 0 and 100.
  77. *
  78. * E.g.: 70
  79. * @since 9.1
  80. */
  81. public function getPriority() {
  82. return 80;
  83. }
  84. }