Capabilities.php 3.7 KB

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