Capabilities.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 Vincent Petry <vincent@nextcloud.com>
  4. *
  5. * @author Vincent Petry <vincent@nextcloud.com>
  6. * @author Kate Döen <kate.doeen@nextcloud.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  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
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Provisioning_API;
  25. use OCA\FederatedFileSharing\FederatedShareProvider;
  26. use OCP\App\IAppManager;
  27. use OCP\Capabilities\ICapability;
  28. class Capabilities implements ICapability {
  29. /** @var IAppManager */
  30. private $appManager;
  31. public function __construct(IAppManager $appManager) {
  32. $this->appManager = $appManager;
  33. }
  34. /**
  35. * Function an app uses to return the capabilities
  36. *
  37. * @return array{
  38. * provisioning_api: array{
  39. * version: string,
  40. * AccountPropertyScopesVersion: int,
  41. * AccountPropertyScopesFederatedEnabled: bool,
  42. * AccountPropertyScopesPublishedEnabled: bool,
  43. * },
  44. * }
  45. */
  46. public function getCapabilities() {
  47. $federatedScopeEnabled = $this->appManager->isEnabledForUser('federation');
  48. $publishedScopeEnabled = false;
  49. $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
  50. if ($federatedFileSharingEnabled) {
  51. /** @var FederatedShareProvider $shareProvider */
  52. $shareProvider = \OC::$server->query(FederatedShareProvider::class);
  53. $publishedScopeEnabled = $shareProvider->isLookupServerUploadEnabled();
  54. }
  55. return [
  56. 'provisioning_api' => [
  57. 'version' => $this->appManager->getAppVersion('provisioning_api'),
  58. 'AccountPropertyScopesVersion' => 2,
  59. 'AccountPropertyScopesFederatedEnabled' => $federatedScopeEnabled,
  60. 'AccountPropertyScopesPublishedEnabled' => $publishedScopeEnabled,
  61. ]
  62. ];
  63. }
  64. }