Capabilities.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Tobias Kaminsky <tobias@kaminsky.me>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Files_Sharing;
  25. use OCP\Capabilities\ICapability;
  26. use OCP\Constants;
  27. use OCP\IConfig;
  28. /**
  29. * Class Capabilities
  30. *
  31. * @package OCA\Files_Sharing
  32. */
  33. class Capabilities implements ICapability {
  34. /** @var IConfig */
  35. private $config;
  36. public function __construct(IConfig $config) {
  37. $this->config = $config;
  38. }
  39. /**
  40. * Return this classes capabilities
  41. *
  42. * @return array
  43. */
  44. public function getCapabilities() {
  45. $res = [];
  46. if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') {
  47. $res['api_enabled'] = false;
  48. $res['public'] = ['enabled' => false];
  49. $res['user'] = ['send_mail' => false];
  50. $res['resharing'] = false;
  51. } else {
  52. $res['api_enabled'] = true;
  53. $public = [];
  54. $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes';
  55. if ($public['enabled']) {
  56. $public['password'] = [];
  57. $public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes');
  58. if ($public['password']['enforced']) {
  59. $public['password']['askForOptionalPassword'] = false;
  60. } else {
  61. $public['password']['askForOptionalPassword'] = ($this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no') === 'yes');
  62. }
  63. $public['expire_date'] = [];
  64. $public['multiple_links'] = true;
  65. $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
  66. if ($public['expire_date']['enabled']) {
  67. $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
  68. $public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
  69. }
  70. $public['expire_date_internal'] = [];
  71. $public['expire_date_internal']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes';
  72. if ($public['expire_date_internal']['enabled']) {
  73. $public['expire_date_internal']['days'] = $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7');
  74. $public['expire_date_internal']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
  75. }
  76. $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
  77. $public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes';
  78. $public['upload_files_drop'] = $public['upload'];
  79. }
  80. $res['public'] = $public;
  81. $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
  82. $res['user']['send_mail'] = false;
  83. $res['user']['expire_date']['enabled'] = true;
  84. // deprecated in favour of 'group', but we need to keep it for now
  85. // in order to stay compatible with older clients
  86. $res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';
  87. $res['group'] = [];
  88. $res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';
  89. $res['group']['expire_date']['enabled'] = true;
  90. $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
  91. }
  92. //Federated sharing
  93. $res['federation'] = [
  94. 'outgoing' => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes',
  95. 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
  96. 'expire_date' => ['enabled' => true]
  97. ];
  98. // Sharee searches
  99. $res['sharee'] = [
  100. 'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false)
  101. ];
  102. return [
  103. 'files_sharing' => $res,
  104. ];
  105. }
  106. }