Sharing.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. *
  17. * @license GNU AGPL version 3 or any later version
  18. *
  19. * This program is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU Affero General Public License as
  21. * published by the Free Software Foundation, either version 3 of the
  22. * License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU Affero General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Affero General Public License
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. *
  32. */
  33. namespace OCA\Settings\Settings\Admin;
  34. use OCP\App\IAppManager;
  35. use OCP\AppFramework\Http\TemplateResponse;
  36. use OCP\Constants;
  37. use OCP\IConfig;
  38. use OCP\IL10N;
  39. use OCP\Settings\IDelegatedSettings;
  40. use OCP\Share\IManager;
  41. use OCP\Util;
  42. class Sharing implements IDelegatedSettings {
  43. /** @var IConfig */
  44. private $config;
  45. /** @var IL10N */
  46. private $l;
  47. /** @var IManager */
  48. private $shareManager;
  49. /** @var IAppManager */
  50. private $appManager;
  51. public function __construct(IConfig $config, IL10N $l, IManager $shareManager, IAppManager $appManager) {
  52. $this->config = $config;
  53. $this->l = $l;
  54. $this->shareManager = $shareManager;
  55. $this->appManager = $appManager;
  56. }
  57. /**
  58. * @return TemplateResponse
  59. */
  60. public function getForm() {
  61. $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
  62. $excludeGroupsList = !is_null(json_decode($excludedGroups))
  63. ? implode('|', json_decode($excludedGroups, true)) : '';
  64. $linksExcludedGroups = $this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '');
  65. $linksExcludeGroupsList = !is_null(json_decode($linksExcludedGroups))
  66. ? implode('|', json_decode($linksExcludedGroups, true)) : '';
  67. $excludedPasswordGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', '');
  68. $excludedPasswordGroupsList = !is_null(json_decode($excludedPasswordGroups))
  69. ? implode('|', json_decode($excludedPasswordGroups, true)) : '';
  70. $parameters = [
  71. // Built-In Sharing
  72. 'sharingAppEnabled' => $this->appManager->isEnabledForUser('files_sharing'),
  73. 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
  74. 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'),
  75. 'allowLinksExcludeGroups' => $linksExcludeGroupsList,
  76. 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'),
  77. 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'),
  78. 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'),
  79. 'restrictUserEnumerationToGroup' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no'),
  80. 'restrictUserEnumerationToPhone' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no'),
  81. 'restrictUserEnumerationFullMatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes'),
  82. 'restrictUserEnumerationFullMatchUserId' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes'),
  83. 'restrictUserEnumerationFullMatchEmail' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes'),
  84. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no'),
  85. 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(false),
  86. 'passwordExcludedGroups' => $excludedPasswordGroupsList,
  87. 'passwordExcludedGroupsFeatureEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
  88. 'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
  89. 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
  90. 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),
  91. 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
  92. 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'),
  93. 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes',
  94. 'shareExcludedGroupsList' => $excludeGroupsList,
  95. 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
  96. 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
  97. 'shareApiDefaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL),
  98. 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(),
  99. 'shareDefaultInternalExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no'),
  100. 'shareInternalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
  101. 'shareInternalEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no'),
  102. 'shareDefaultRemoteExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no'),
  103. 'shareRemoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'),
  104. 'shareRemoteEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no'),
  105. ];
  106. return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');
  107. }
  108. /**
  109. * get share permission list for template
  110. *
  111. * @return array
  112. */
  113. private function getSharePermissionList() {
  114. return [
  115. [
  116. 'id' => 'cancreate',
  117. 'label' => $this->l->t('Create'),
  118. 'value' => Constants::PERMISSION_CREATE
  119. ],
  120. [
  121. 'id' => 'canupdate',
  122. 'label' => $this->l->t('Change'),
  123. 'value' => Constants::PERMISSION_UPDATE
  124. ],
  125. [
  126. 'id' => 'candelete',
  127. 'label' => $this->l->t('Delete'),
  128. 'value' => Constants::PERMISSION_DELETE
  129. ],
  130. [
  131. 'id' => 'canshare',
  132. 'label' => $this->l->t('Reshare'),
  133. 'value' => Constants::PERMISSION_SHARE
  134. ],
  135. ];
  136. }
  137. /**
  138. * @return string the section ID, e.g. 'sharing'
  139. */
  140. public function getSection() {
  141. return 'sharing';
  142. }
  143. /**
  144. * @return int whether the form should be rather on the top or bottom of
  145. * the admin section. The forms are arranged in ascending order of the
  146. * priority values. It is required to return a value between 0 and 100.
  147. *
  148. * E.g.: 70
  149. */
  150. public function getPriority() {
  151. return 0;
  152. }
  153. public function getAuthorizedAppConfig(): array {
  154. return [
  155. 'core' => ['/shareapi_.*/'],
  156. ];
  157. }
  158. public function getName(): ?string {
  159. return null;
  160. }
  161. }