1
0

Sharing.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. $onlyShareWithGroupMembersExcludeGroupList = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', '');
  64. $parameters = [
  65. // Built-In Sharing
  66. 'enabled' => $this->getHumanBooleanConfig('core', 'shareapi_enabled', true),
  67. 'allowGroupSharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_group_sharing', true),
  68. 'allowLinks' => $this->getHumanBooleanConfig('core', 'shareapi_allow_links', true),
  69. 'allowLinksExcludeGroups' => json_decode($linksExcludedGroups, true) ?? [],
  70. 'allowPublicUpload' => $this->getHumanBooleanConfig('core', 'shareapi_allow_public_upload', true),
  71. 'allowResharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_resharing', true),
  72. 'allowShareDialogUserEnumeration' => $this->getHumanBooleanConfig('core', 'shareapi_allow_share_dialog_user_enumeration', true),
  73. 'restrictUserEnumerationToGroup' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_group'),
  74. 'restrictUserEnumerationToPhone' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_phone'),
  75. 'restrictUserEnumerationFullMatch' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match', true),
  76. 'restrictUserEnumerationFullMatchUserId' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_userid', true),
  77. 'restrictUserEnumerationFullMatchEmail' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_email', true),
  78. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn'),
  79. 'enforceLinksPassword' => Util::isPublicLinkPasswordRequired(false),
  80. 'passwordExcludedGroups' => json_decode($excludedPasswordGroups) ?? [],
  81. 'passwordExcludedGroupsFeatureEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
  82. 'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
  83. 'onlyShareWithGroupMembersExcludeGroupList' => json_decode($onlyShareWithGroupMembersExcludeGroupList) ?? [],
  84. 'defaultExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_expire_date'),
  85. 'expireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
  86. 'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'),
  87. 'excludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no'),
  88. 'excludeGroupsList' => json_decode($excludedGroups, true) ?? [],
  89. 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
  90. 'enableLinkPasswordByDefault' => $this->getHumanBooleanConfig('core', 'shareapi_enable_link_password_by_default'),
  91. 'defaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL),
  92. 'defaultInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_internal_expire_date'),
  93. 'internalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
  94. 'enforceInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_internal_expire_date'),
  95. 'defaultRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_remote_expire_date'),
  96. 'remoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'),
  97. 'enforceRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_remote_expire_date'),
  98. ];
  99. $this->initialState->provideInitialState('sharingAppEnabled', $this->appManager->isEnabledForUser('files_sharing'));
  100. $this->initialState->provideInitialState('sharingDocumentation', $this->urlGenerator->linkToDocs('admin-sharing'));
  101. $this->initialState->provideInitialState('sharingSettings', $parameters);
  102. \OCP\Util::addScript($this->appName, 'vue-settings-admin-sharing');
  103. return new TemplateResponse($this->appName, 'settings/admin/sharing', [], '');
  104. }
  105. /**
  106. * Helper function to retrive boolean values from human readable strings ('yes' / 'no')
  107. */
  108. private function getHumanBooleanConfig(string $app, string $key, bool $default = false): bool {
  109. return $this->config->getAppValue($app, $key, $default ? 'yes' : 'no') === 'yes';
  110. }
  111. /**
  112. * @return string the section ID, e.g. 'sharing'
  113. */
  114. public function getSection() {
  115. return 'sharing';
  116. }
  117. /**
  118. * @return int whether the form should be rather on the top or bottom of
  119. * the admin section. The forms are arranged in ascending order of the
  120. * priority values. It is required to return a value between 0 and 100.
  121. *
  122. * E.g.: 70
  123. */
  124. public function getPriority() {
  125. return 0;
  126. }
  127. public function getAuthorizedAppConfig(): array {
  128. return [
  129. 'core' => ['/shareapi_.*/'],
  130. ];
  131. }
  132. public function getName(): ?string {
  133. return null;
  134. }
  135. }