Capabilities.php 6.2 KB

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