1
0

Capabilities.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_Sharing;
  8. use OCP\Capabilities\ICapability;
  9. use OCP\Constants;
  10. use OCP\IConfig;
  11. use OCP\Share\IManager;
  12. /**
  13. * Class Capabilities
  14. *
  15. * @package OCA\Files_Sharing
  16. */
  17. class Capabilities implements ICapability {
  18. public function __construct(
  19. private IConfig $config,
  20. private IManager $shareManager,
  21. ) {
  22. }
  23. /**
  24. * Return this classes capabilities
  25. *
  26. * @return array{
  27. * files_sharing: array{
  28. * api_enabled: bool,
  29. * public: array{
  30. * enabled: bool,
  31. * password?: array{
  32. * enforced: bool,
  33. * askForOptionalPassword: bool
  34. * },
  35. * multiple_links?: bool,
  36. * expire_date?: array{
  37. * enabled: bool,
  38. * days?: int,
  39. * enforced?: bool,
  40. * },
  41. * expire_date_internal?: array{
  42. * enabled: bool,
  43. * days?: int,
  44. * enforced?: bool,
  45. * },
  46. * expire_date_remote?: array{
  47. * enabled: bool,
  48. * days?: int,
  49. * enforced?: bool,
  50. * },
  51. * send_mail?: bool,
  52. * upload?: bool,
  53. * upload_files_drop?: bool,
  54. * },
  55. * user: array{
  56. * send_mail: bool,
  57. * expire_date?: array{
  58. * enabled: bool,
  59. * },
  60. * },
  61. * resharing: bool,
  62. * group_sharing?: bool,
  63. * group?: array{
  64. * enabled: bool,
  65. * expire_date?: array{
  66. * enabled: bool,
  67. * },
  68. * },
  69. * default_permissions?: int,
  70. * federation: array{
  71. * outgoing: bool,
  72. * incoming: bool,
  73. * expire_date: array{
  74. * enabled: bool,
  75. * },
  76. * expire_date_supported: array{
  77. * enabled: bool,
  78. * },
  79. * },
  80. * sharee: array{
  81. * query_lookup_default: bool,
  82. * always_show_unique: bool,
  83. * },
  84. * },
  85. * }
  86. */
  87. public function getCapabilities() {
  88. $res = [];
  89. if (!$this->shareManager->shareApiEnabled()) {
  90. $res['api_enabled'] = false;
  91. $res['public'] = ['enabled' => false];
  92. $res['user'] = ['send_mail' => false];
  93. $res['resharing'] = false;
  94. } else {
  95. $res['api_enabled'] = true;
  96. $public = [];
  97. $public['enabled'] = $this->shareManager->shareApiAllowLinks();
  98. if ($public['enabled']) {
  99. $public['password'] = [];
  100. $public['password']['enforced'] = $this->shareManager->shareApiLinkEnforcePassword();
  101. if ($public['password']['enforced']) {
  102. $public['password']['askForOptionalPassword'] = false;
  103. } else {
  104. $public['password']['askForOptionalPassword'] = ($this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no') === 'yes');
  105. }
  106. $public['expire_date'] = [];
  107. $public['multiple_links'] = true;
  108. $public['expire_date']['enabled'] = $this->shareManager->shareApiLinkDefaultExpireDate();
  109. if ($public['expire_date']['enabled']) {
  110. $public['expire_date']['days'] = $this->shareManager->shareApiLinkDefaultExpireDays();
  111. $public['expire_date']['enforced'] = $this->shareManager->shareApiLinkDefaultExpireDateEnforced();
  112. }
  113. $public['expire_date_internal'] = [];
  114. $public['expire_date_internal']['enabled'] = $this->shareManager->shareApiInternalDefaultExpireDate();
  115. if ($public['expire_date_internal']['enabled']) {
  116. $public['expire_date_internal']['days'] = $this->shareManager->shareApiInternalDefaultExpireDays();
  117. $public['expire_date_internal']['enforced'] = $this->shareManager->shareApiInternalDefaultExpireDateEnforced();
  118. }
  119. $public['expire_date_remote'] = [];
  120. $public['expire_date_remote']['enabled'] = $this->shareManager->shareApiRemoteDefaultExpireDate();
  121. if ($public['expire_date_remote']['enabled']) {
  122. $public['expire_date_remote']['days'] = $this->shareManager->shareApiRemoteDefaultExpireDays();
  123. $public['expire_date_remote']['enforced'] = $this->shareManager->shareApiRemoteDefaultExpireDateEnforced();
  124. }
  125. $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
  126. $public['upload'] = $this->shareManager->shareApiLinkAllowPublicUpload();
  127. $public['upload_files_drop'] = $public['upload'];
  128. }
  129. $res['public'] = $public;
  130. $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
  131. $res['user']['send_mail'] = false;
  132. $res['user']['expire_date']['enabled'] = true;
  133. // deprecated in favour of 'group', but we need to keep it for now
  134. // in order to stay compatible with older clients
  135. $res['group_sharing'] = $this->shareManager->allowGroupSharing();
  136. $res['group'] = [];
  137. $res['group']['enabled'] = $this->shareManager->allowGroupSharing();
  138. $res['group']['expire_date']['enabled'] = true;
  139. $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
  140. }
  141. //Federated sharing
  142. $res['federation'] = [
  143. 'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(),
  144. 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
  145. // old bogus one, expire_date was not working before, keeping for compatibility
  146. 'expire_date' => ['enabled' => true],
  147. // the real deal, signifies that expiration date can be set on federated shares
  148. 'expire_date_supported' => ['enabled' => true],
  149. ];
  150. // Sharee searches
  151. $res['sharee'] = [
  152. 'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false),
  153. 'always_show_unique' => $this->config->getAppValue('files_sharing', 'always_show_unique', 'yes') === 'yes',
  154. ];
  155. return [
  156. 'files_sharing' => $res,
  157. ];
  158. }
  159. }