1
0

Capabilities.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Tobias Kaminsky <tobias@kaminsky.me>
  10. * @author Vincent Petry <vincent@nextcloud.com>
  11. * @author Kate Döen <kate.doeen@nextcloud.com>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OCA\Files_Sharing;
  29. use OCP\Capabilities\ICapability;
  30. use OCP\Constants;
  31. use OCP\IConfig;
  32. use OCP\Share\IManager;
  33. /**
  34. * Class Capabilities
  35. *
  36. * @package OCA\Files_Sharing
  37. */
  38. class Capabilities implements ICapability {
  39. /** @var IConfig */
  40. private $config;
  41. /** @var IManager */
  42. private $shareManager;
  43. public function __construct(IConfig $config, IManager $shareManager) {
  44. $this->config = $config;
  45. $this->shareManager = $shareManager;
  46. }
  47. /**
  48. * Return this classes capabilities
  49. *
  50. * @return array{
  51. * files_sharing: array{
  52. * api_enabled: bool,
  53. * public: array{
  54. * enabled: bool,
  55. * password?: array{
  56. * enforced: bool,
  57. * askForOptionalPassword: bool
  58. * },
  59. * multiple_links?: bool,
  60. * expire_date?: array{
  61. * enabled: bool,
  62. * days?: int,
  63. * enforced?: bool,
  64. * },
  65. * expire_date_internal?: array{
  66. * enabled: bool,
  67. * days?: int,
  68. * enforced?: bool,
  69. * },
  70. * expire_date_remote?: array{
  71. * enabled: bool,
  72. * days?: int,
  73. * enforced?: bool,
  74. * },
  75. * send_mail?: bool,
  76. * upload?: bool,
  77. * upload_files_drop?: bool,
  78. * },
  79. * user: array{
  80. * send_mail: bool,
  81. * expire_date?: array{
  82. * enabled: bool,
  83. * },
  84. * },
  85. * resharing: bool,
  86. * group_sharing?: bool,
  87. * group?: array{
  88. * enabled: bool,
  89. * expire_date?: array{
  90. * enabled: bool,
  91. * },
  92. * },
  93. * default_permissions?: int,
  94. * federation: array{
  95. * outgoing: bool,
  96. * incoming: bool,
  97. * expire_date: array{
  98. * enabled: bool,
  99. * },
  100. * expire_date_supported: array{
  101. * enabled: bool,
  102. * },
  103. * },
  104. * sharee: array{
  105. * query_lookup_default: bool,
  106. * always_show_unique: bool,
  107. * },
  108. * },
  109. * }
  110. */
  111. public function getCapabilities() {
  112. $res = [];
  113. if (!$this->shareManager->shareApiEnabled()) {
  114. $res['api_enabled'] = false;
  115. $res['public'] = ['enabled' => false];
  116. $res['user'] = ['send_mail' => false];
  117. $res['resharing'] = false;
  118. } else {
  119. $res['api_enabled'] = true;
  120. $public = [];
  121. $public['enabled'] = $this->shareManager->shareApiAllowLinks();
  122. if ($public['enabled']) {
  123. $public['password'] = [];
  124. $public['password']['enforced'] = $this->shareManager->shareApiLinkEnforcePassword();
  125. if ($public['password']['enforced']) {
  126. $public['password']['askForOptionalPassword'] = false;
  127. } else {
  128. $public['password']['askForOptionalPassword'] = ($this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no') === 'yes');
  129. }
  130. $public['expire_date'] = [];
  131. $public['multiple_links'] = true;
  132. $public['expire_date']['enabled'] = $this->shareManager->shareApiLinkDefaultExpireDate();
  133. if ($public['expire_date']['enabled']) {
  134. $public['expire_date']['days'] = $this->shareManager->shareApiLinkDefaultExpireDays();
  135. $public['expire_date']['enforced'] = $this->shareManager->shareApiLinkDefaultExpireDateEnforced();
  136. }
  137. $public['expire_date_internal'] = [];
  138. $public['expire_date_internal']['enabled'] = $this->shareManager->shareApiInternalDefaultExpireDate();
  139. if ($public['expire_date_internal']['enabled']) {
  140. $public['expire_date_internal']['days'] = $this->shareManager->shareApiInternalDefaultExpireDays();
  141. $public['expire_date_internal']['enforced'] = $this->shareManager->shareApiInternalDefaultExpireDateEnforced();
  142. }
  143. $public['expire_date_remote'] = [];
  144. $public['expire_date_remote']['enabled'] = $this->shareManager->shareApiRemoteDefaultExpireDate();
  145. if ($public['expire_date_remote']['enabled']) {
  146. $public['expire_date_remote']['days'] = $this->shareManager->shareApiRemoteDefaultExpireDays();
  147. $public['expire_date_remote']['enforced'] = $this->shareManager->shareApiRemoteDefaultExpireDateEnforced();
  148. }
  149. $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
  150. $public['upload'] = $this->shareManager->shareApiLinkAllowPublicUpload();
  151. $public['upload_files_drop'] = $public['upload'];
  152. }
  153. $res['public'] = $public;
  154. $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
  155. $res['user']['send_mail'] = false;
  156. $res['user']['expire_date']['enabled'] = true;
  157. // deprecated in favour of 'group', but we need to keep it for now
  158. // in order to stay compatible with older clients
  159. $res['group_sharing'] = $this->shareManager->allowGroupSharing();
  160. $res['group'] = [];
  161. $res['group']['enabled'] = $this->shareManager->allowGroupSharing();
  162. $res['group']['expire_date']['enabled'] = true;
  163. $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
  164. }
  165. //Federated sharing
  166. $res['federation'] = [
  167. 'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(),
  168. 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
  169. // old bogus one, expire_date was not working before, keeping for compatibility
  170. 'expire_date' => ['enabled' => true],
  171. // the real deal, signifies that expiration date can be set on federated shares
  172. 'expire_date_supported' => ['enabled' => true],
  173. ];
  174. // Sharee searches
  175. $res['sharee'] = [
  176. 'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false),
  177. 'always_show_unique' => $this->config->getAppValue('files_sharing', 'always_show_unique', 'yes') === 'yes',
  178. ];
  179. return [
  180. 'files_sharing' => $res,
  181. ];
  182. }
  183. }