Capabilities.php 4.8 KB

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