1
0

Security.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Settings\Settings\Admin;
  7. use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
  8. use OCP\AppFramework\Http\TemplateResponse;
  9. use OCP\AppFramework\Services\IInitialState;
  10. use OCP\Encryption\IManager;
  11. use OCP\IURLGenerator;
  12. use OCP\IUserManager;
  13. use OCP\Settings\ISettings;
  14. class Security implements ISettings {
  15. private MandatoryTwoFactor $mandatoryTwoFactor;
  16. public function __construct(
  17. private IManager $manager,
  18. private IUserManager $userManager,
  19. MandatoryTwoFactor $mandatoryTwoFactor,
  20. private IInitialState $initialState,
  21. private IURLGenerator $urlGenerator,
  22. ) {
  23. $this->mandatoryTwoFactor = $mandatoryTwoFactor;
  24. }
  25. /**
  26. * @return TemplateResponse
  27. */
  28. public function getForm(): TemplateResponse {
  29. $encryptionModules = $this->manager->getEncryptionModules();
  30. $defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
  31. $encryptionModuleList = [];
  32. foreach ($encryptionModules as $module) {
  33. $encryptionModuleList[$module['id']]['displayName'] = $module['displayName'];
  34. $encryptionModuleList[$module['id']]['default'] = false;
  35. if ($module['id'] === $defaultEncryptionModuleId) {
  36. $encryptionModuleList[$module['id']]['default'] = true;
  37. }
  38. }
  39. $this->initialState->provideInitialState('mandatory2FAState', $this->mandatoryTwoFactor->getState());
  40. $this->initialState->provideInitialState('two-factor-admin-doc', $this->urlGenerator->linkToDocs('admin-2fa'));
  41. $this->initialState->provideInitialState('encryption-enabled', $this->manager->isEnabled());
  42. $this->initialState->provideInitialState('encryption-ready', $this->manager->isReady());
  43. $this->initialState->provideInitialState('external-backends-enabled', count($this->userManager->getBackends()) > 1);
  44. $this->initialState->provideInitialState('encryption-modules', $encryptionModuleList);
  45. $this->initialState->provideInitialState('encryption-admin-doc', $this->urlGenerator->linkToDocs('admin-encryption'));
  46. return new TemplateResponse('settings', 'settings/admin/security', [], '');
  47. }
  48. /**
  49. * @return string the section ID, e.g. 'sharing'
  50. */
  51. public function getSection(): string {
  52. return 'security';
  53. }
  54. /**
  55. * @return int whether the form should be rather on the top or bottom of
  56. * the admin section. The forms are arranged in ascending order of the
  57. * priority values. It is required to return a value between 0 and 100.
  58. *
  59. * E.g.: 70
  60. */
  61. public function getPriority(): int {
  62. return 10;
  63. }
  64. }