Capabilities.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\Files_Sharing;
  28. use OCP\Capabilities\ICapability;
  29. use OCP\Constants;
  30. use OCP\IConfig;
  31. use OCP\Share\IManager;
  32. /**
  33. * Class Capabilities
  34. *
  35. * @package OCA\Files_Sharing
  36. */
  37. class Capabilities implements ICapability {
  38. /** @var IConfig */
  39. private $config;
  40. /** @var IManager */
  41. private $shareManager;
  42. public function __construct(IConfig $config, IManager $shareManager) {
  43. $this->config = $config;
  44. $this->shareManager = $shareManager;
  45. }
  46. /**
  47. * Return this classes capabilities
  48. *
  49. * @return array
  50. */
  51. public function getCapabilities() {
  52. $res = [];
  53. if (!$this->shareManager->shareApiEnabled()) {
  54. $res['api_enabled'] = false;
  55. $res['public'] = ['enabled' => false];
  56. $res['user'] = ['send_mail' => false];
  57. $res['resharing'] = false;
  58. } else {
  59. $res['api_enabled'] = true;
  60. $public = [];
  61. $public['enabled'] = $this->shareManager->shareApiAllowLinks();
  62. if ($public['enabled']) {
  63. $public['password'] = [];
  64. $public['password']['enforced'] = $this->shareManager->shareApiLinkEnforcePassword();
  65. if ($public['password']['enforced']) {
  66. $public['password']['askForOptionalPassword'] = false;
  67. } else {
  68. $public['password']['askForOptionalPassword'] = ($this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no') === 'yes');
  69. }
  70. $public['expire_date'] = [];
  71. $public['multiple_links'] = true;
  72. $public['expire_date']['enabled'] = $this->shareManager->shareApiLinkDefaultExpireDate();
  73. if ($public['expire_date']['enabled']) {
  74. $public['expire_date']['days'] = $this->shareManager->shareApiLinkDefaultExpireDays();
  75. $public['expire_date']['enforced'] = $this->shareManager->shareApiLinkDefaultExpireDateEnforced();
  76. }
  77. $public['expire_date_internal'] = [];
  78. $public['expire_date_internal']['enabled'] = $this->shareManager->shareApiInternalDefaultExpireDate();
  79. if ($public['expire_date_internal']['enabled']) {
  80. $public['expire_date_internal']['days'] = $this->shareManager->shareApiInternalDefaultExpireDays();
  81. $public['expire_date_internal']['enforced'] = $this->shareManager->shareApiInternalDefaultExpireDateEnforced();
  82. }
  83. $public['expire_date_remote'] = [];
  84. $public['expire_date_remote']['enabled'] = $this->shareManager->shareApiRemoteDefaultExpireDate();
  85. if ($public['expire_date_remote']['enabled']) {
  86. $public['expire_date_remote']['days'] = $this->shareManager->shareApiRemoteDefaultExpireDays();
  87. $public['expire_date_remote']['enforced'] = $this->shareManager->shareApiRemoteDefaultExpireDateEnforced();
  88. }
  89. $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
  90. $public['upload'] = $this->shareManager->shareApiLinkAllowPublicUpload();
  91. $public['upload_files_drop'] = $public['upload'];
  92. }
  93. $res['public'] = $public;
  94. $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
  95. $res['user']['send_mail'] = false;
  96. $res['user']['expire_date']['enabled'] = true;
  97. // deprecated in favour of 'group', but we need to keep it for now
  98. // in order to stay compatible with older clients
  99. $res['group_sharing'] = $this->shareManager->allowGroupSharing();
  100. $res['group'] = [];
  101. $res['group']['enabled'] = $this->shareManager->allowGroupSharing();
  102. $res['group']['expire_date']['enabled'] = true;
  103. $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
  104. }
  105. //Federated sharing
  106. $res['federation'] = [
  107. 'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(),
  108. 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
  109. // old bogus one, expire_date was not working before, keeping for compatibility
  110. 'expire_date' => ['enabled' => true],
  111. // the real deal, signifies that expiration date can be set on federated shares
  112. 'expire_date_supported' => ['enabled' => true],
  113. ];
  114. // Sharee searches
  115. $res['sharee'] = [
  116. 'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false),
  117. 'always_show_unique' => $this->config->getAppValue('files_sharing', 'always_show_unique', 'yes') === 'yes',
  118. ];
  119. return [
  120. 'files_sharing' => $res,
  121. ];
  122. }
  123. }