1
0

Sharing.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 OCP\App\IAppManager;
  8. use OCP\AppFramework\Http\TemplateResponse;
  9. use OCP\AppFramework\Services\IInitialState;
  10. use OCP\Constants;
  11. use OCP\IConfig;
  12. use OCP\IL10N;
  13. use OCP\IURLGenerator;
  14. use OCP\Settings\IDelegatedSettings;
  15. use OCP\Share\IManager;
  16. use OCP\Util;
  17. class Sharing implements IDelegatedSettings {
  18. public function __construct(
  19. private IConfig $config,
  20. private IL10N $l,
  21. private IManager $shareManager,
  22. private IAppManager $appManager,
  23. private IURLGenerator $urlGenerator,
  24. private IInitialState $initialState,
  25. private string $appName,
  26. ) {
  27. }
  28. /**
  29. * @return TemplateResponse
  30. */
  31. public function getForm() {
  32. $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
  33. $linksExcludedGroups = $this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '');
  34. $excludedPasswordGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', '');
  35. $onlyShareWithGroupMembersExcludeGroupList = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', '');
  36. $parameters = [
  37. // Built-In Sharing
  38. 'enabled' => $this->getHumanBooleanConfig('core', 'shareapi_enabled', true),
  39. 'allowGroupSharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_group_sharing', true),
  40. 'allowLinks' => $this->getHumanBooleanConfig('core', 'shareapi_allow_links', true),
  41. 'allowLinksExcludeGroups' => json_decode($linksExcludedGroups, true) ?? [],
  42. 'allowPublicUpload' => $this->getHumanBooleanConfig('core', 'shareapi_allow_public_upload', true),
  43. 'allowResharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_resharing', true),
  44. 'allowShareDialogUserEnumeration' => $this->getHumanBooleanConfig('core', 'shareapi_allow_share_dialog_user_enumeration', true),
  45. 'restrictUserEnumerationToGroup' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_group'),
  46. 'restrictUserEnumerationToPhone' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_phone'),
  47. 'restrictUserEnumerationFullMatch' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match', true),
  48. 'restrictUserEnumerationFullMatchUserId' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_userid', true),
  49. 'restrictUserEnumerationFullMatchEmail' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_email', true),
  50. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn'),
  51. 'enforceLinksPassword' => Util::isPublicLinkPasswordRequired(false),
  52. 'enforceLinksPasswordExcludedGroups' => json_decode($excludedPasswordGroups) ?? [],
  53. 'enforceLinksPasswordExcludedGroupsEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
  54. 'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
  55. 'onlyShareWithGroupMembersExcludeGroupList' => json_decode($onlyShareWithGroupMembersExcludeGroupList) ?? [],
  56. 'defaultExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_expire_date'),
  57. 'expireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
  58. 'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'),
  59. 'excludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no'),
  60. 'excludeGroupsList' => json_decode($excludedGroups, true) ?? [],
  61. 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext'),
  62. 'enableLinkPasswordByDefault' => $this->getHumanBooleanConfig('core', 'shareapi_enable_link_password_by_default'),
  63. 'defaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL),
  64. 'defaultInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_internal_expire_date'),
  65. 'internalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
  66. 'enforceInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_internal_expire_date'),
  67. 'defaultRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_remote_expire_date'),
  68. 'remoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'),
  69. 'enforceRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_remote_expire_date'),
  70. ];
  71. $this->initialState->provideInitialState('sharingAppEnabled', $this->appManager->isEnabledForUser('files_sharing'));
  72. $this->initialState->provideInitialState('sharingDocumentation', $this->urlGenerator->linkToDocs('admin-sharing'));
  73. $this->initialState->provideInitialState('sharingSettings', $parameters);
  74. Util::addScript($this->appName, 'vue-settings-admin-sharing');
  75. return new TemplateResponse($this->appName, 'settings/admin/sharing', [], '');
  76. }
  77. /**
  78. * Helper function to retrive boolean values from human readable strings ('yes' / 'no')
  79. */
  80. private function getHumanBooleanConfig(string $app, string $key, bool $default = false): bool {
  81. return $this->config->getAppValue($app, $key, $default ? 'yes' : 'no') === 'yes';
  82. }
  83. /**
  84. * @return string the section ID, e.g. 'sharing'
  85. */
  86. public function getSection() {
  87. return 'sharing';
  88. }
  89. /**
  90. * @return int whether the form should be rather on the top or bottom of
  91. * the admin section. The forms are arranged in ascending order of the
  92. * priority values. It is required to return a value between 0 and 100.
  93. *
  94. * E.g.: 70
  95. */
  96. public function getPriority() {
  97. return 0;
  98. }
  99. public function getAuthorizedAppConfig(): array {
  100. return [
  101. 'core' => ['/shareapi_.*/'],
  102. ];
  103. }
  104. public function getName(): ?string {
  105. return null;
  106. }
  107. }