1
0

Sharing.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bjoern Schiessle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. * @author Sascha Wiswedel <sascha.wiswedel@nextcloud.com>
  14. * @author Vincent Petry <vincent@nextcloud.com>
  15. * @author Thomas Citharel <nextcloud@tcit.fr>
  16. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  17. *
  18. * @license AGPL-3.0-or-later
  19. *
  20. * This program is free software: you can redistribute it and/or modify
  21. * it under the terms of the GNU Affero General Public License as
  22. * published by the Free Software Foundation, either version 3 of the
  23. * License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU Affero General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU Affero General Public License
  31. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  32. *
  33. */
  34. namespace OCA\Settings\Settings\Admin;
  35. use OCP\App\IAppManager;
  36. use OCP\AppFramework\Http\TemplateResponse;
  37. use OCP\AppFramework\Services\IInitialState;
  38. use OCP\Constants;
  39. use OCP\IConfig;
  40. use OCP\IL10N;
  41. use OCP\IURLGenerator;
  42. use OCP\Settings\IDelegatedSettings;
  43. use OCP\Share\IManager;
  44. use OCP\Util;
  45. class Sharing implements IDelegatedSettings {
  46. public function __construct(
  47. private IConfig $config,
  48. private IL10N $l,
  49. private IManager $shareManager,
  50. private IAppManager $appManager,
  51. private IURLGenerator $urlGenerator,
  52. private IInitialState $initialState,
  53. private string $appName,
  54. ) {
  55. }
  56. /**
  57. * @return TemplateResponse
  58. */
  59. public function getForm() {
  60. $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
  61. $linksExcludedGroups = $this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '');
  62. $excludedPasswordGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', '');
  63. $parameters = [
  64. // Built-In Sharing
  65. 'enabled' => $this->getHumanBooleanConfig('core', 'shareapi_enabled', true),
  66. 'allowGroupSharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_group_sharing', true),
  67. 'allowLinks' => $this->getHumanBooleanConfig('core', 'shareapi_allow_links', true),
  68. 'allowLinksExcludeGroups' => json_decode($linksExcludedGroups, true) ?? [],
  69. 'allowPublicUpload' => $this->getHumanBooleanConfig('core', 'shareapi_allow_public_upload', true),
  70. 'allowResharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_resharing', true),
  71. 'allowShareDialogUserEnumeration' => $this->getHumanBooleanConfig('core', 'shareapi_allow_share_dialog_user_enumeration', true),
  72. 'restrictUserEnumerationToGroup' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_group'),
  73. 'restrictUserEnumerationToPhone' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_phone'),
  74. 'restrictUserEnumerationFullMatch' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match', true),
  75. 'restrictUserEnumerationFullMatchUserId' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_userid', true),
  76. 'restrictUserEnumerationFullMatchEmail' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_email', true),
  77. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn'),
  78. 'enforceLinksPassword' => Util::isPublicLinkPasswordRequired(false),
  79. 'enforceLinksPasswordExcludedGroups' => json_decode($excludedPasswordGroups) ?? [],
  80. 'enforceLinksPasswordExcludedGroupsEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
  81. 'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
  82. 'defaultExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_expire_date'),
  83. 'expireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
  84. 'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'),
  85. 'excludeGroups' => $this->getHumanBooleanConfig('core', 'shareapi_exclude_groups'),
  86. 'excludeGroupsList' => json_decode($excludedGroups, true) ?? [],
  87. 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
  88. 'enableLinkPasswordByDefault' => $this->getHumanBooleanConfig('core', 'shareapi_enable_link_password_by_default'),
  89. 'defaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL),
  90. 'defaultInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_internal_expire_date'),
  91. 'internalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
  92. 'enforceInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_internal_expire_date'),
  93. 'defaultRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_remote_expire_date'),
  94. 'remoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'),
  95. 'enforceRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_remote_expire_date'),
  96. ];
  97. $this->initialState->provideInitialState('sharingAppEnabled', $this->appManager->isEnabledForUser('files_sharing'));
  98. $this->initialState->provideInitialState('sharingDocumentation', $this->urlGenerator->linkToDocs('admin-sharing'));
  99. $this->initialState->provideInitialState('sharingSettings', $parameters);
  100. \OCP\Util::addScript($this->appName, 'vue-settings-admin-sharing');
  101. return new TemplateResponse($this->appName, 'settings/admin/sharing', [], '');
  102. }
  103. /**
  104. * Helper function to retrive boolean values from human readable strings ('yes' / 'no')
  105. */
  106. private function getHumanBooleanConfig(string $app, string $key, bool $default = false): bool {
  107. return $this->config->getAppValue($app, $key, $default ? 'yes' : 'no') === 'yes';
  108. }
  109. /**
  110. * @return string the section ID, e.g. 'sharing'
  111. */
  112. public function getSection() {
  113. return 'sharing';
  114. }
  115. /**
  116. * @return int whether the form should be rather on the top or bottom of
  117. * the admin section. The forms are arranged in ascending order of the
  118. * priority values. It is required to return a value between 0 and 100.
  119. *
  120. * E.g.: 70
  121. */
  122. public function getPriority() {
  123. return 0;
  124. }
  125. public function getAuthorizedAppConfig(): array {
  126. return [
  127. 'core' => ['/shareapi_.*/'],
  128. ];
  129. }
  130. public function getName(): ?string {
  131. return null;
  132. }
  133. }