Sharing.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 Julius Härtl <jus@bitgrid.net>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Sascha Wiswedel <sascha.wiswedel@nextcloud.com>
  12. *
  13. * @license GNU AGPL version 3 or any later version
  14. *
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License as
  17. * published by the Free Software Foundation, either version 3 of the
  18. * License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. */
  29. namespace OCA\Settings\Settings\Admin;
  30. use OC\Share\Share;
  31. use OCP\AppFramework\Http\TemplateResponse;
  32. use OCP\Constants;
  33. use OCP\IConfig;
  34. use OCP\IL10N;
  35. use OCP\Settings\ISettings;
  36. use OCP\Share\IManager;
  37. use OCP\Util;
  38. class Sharing implements ISettings {
  39. /** @var IConfig */
  40. private $config;
  41. /** @var IL10N */
  42. private $l;
  43. /** @var IManager */
  44. private $shareManager;
  45. /**
  46. * @param IConfig $config
  47. */
  48. public function __construct(IConfig $config, IL10N $l, IManager $shareManager) {
  49. $this->config = $config;
  50. $this->l = $l;
  51. $this->shareManager = $shareManager;
  52. }
  53. /**
  54. * @return TemplateResponse
  55. */
  56. public function getForm() {
  57. $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
  58. $excludeGroupsList = !is_null(json_decode($excludedGroups))
  59. ? implode('|', json_decode($excludedGroups, true)) : '';
  60. $parameters = [
  61. // Built-In Sharing
  62. 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
  63. 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'),
  64. 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'),
  65. 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'),
  66. 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'),
  67. 'restrictUserEnumerationToGroup' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no'),
  68. 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(),
  69. 'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
  70. 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
  71. 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),
  72. 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
  73. 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'),
  74. 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes',
  75. 'shareExcludedGroupsList' => $excludeGroupsList,
  76. 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
  77. 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
  78. 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL),
  79. 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(),
  80. 'shareDefaultInternalExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no'),
  81. 'shareInternalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
  82. 'shareInternalEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no'),
  83. ];
  84. return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');
  85. }
  86. /**
  87. * get share permission list for template
  88. *
  89. * @return array
  90. */
  91. private function getSharePermissionList() {
  92. return [
  93. [
  94. 'id' => 'cancreate',
  95. 'label' => $this->l->t('Create'),
  96. 'value' => Constants::PERMISSION_CREATE
  97. ],
  98. [
  99. 'id' => 'canupdate',
  100. 'label' => $this->l->t('Change'),
  101. 'value' => Constants::PERMISSION_UPDATE
  102. ],
  103. [
  104. 'id' => 'candelete',
  105. 'label' => $this->l->t('Delete'),
  106. 'value' => Constants::PERMISSION_DELETE
  107. ],
  108. [
  109. 'id' => 'canshare',
  110. 'label' => $this->l->t('Reshare'),
  111. 'value' => Constants::PERMISSION_SHARE
  112. ],
  113. ];
  114. }
  115. /**
  116. * @return string the section ID, e.g. 'sharing'
  117. */
  118. public function getSection() {
  119. return 'sharing';
  120. }
  121. /**
  122. * @return int whether the form should be rather on the top or bottom of
  123. * the admin section. The forms are arranged in ascending order of the
  124. * priority values. It is required to return a value between 0 and 100.
  125. *
  126. * E.g.: 70
  127. */
  128. public function getPriority() {
  129. return 0;
  130. }
  131. }