aboutsummaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/lib/Capabilities.php
blob: 4c8b1ce3ec797dad930c79bae9b8d05b1fd94f14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
 * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\Provisioning_API;

use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\App\IAppManager;
use OCP\Capabilities\ICapability;

class Capabilities implements ICapability {

	/** @var IAppManager */
	private $appManager;

	public function __construct(IAppManager $appManager) {
		$this->appManager = $appManager;
	}

	/**
	 * Function an app uses to return the capabilities
	 *
	 * @return array{
	 *     provisioning_api: array{
	 *         version: string,
	 *         AccountPropertyScopesVersion: int,
	 *         AccountPropertyScopesFederatedEnabled: bool,
	 *         AccountPropertyScopesPublishedEnabled: bool,
	 *     },
	 * }
	 */
	public function getCapabilities() {
		$federatedScopeEnabled = $this->appManager->isEnabledForUser('federation');

		$publishedScopeEnabled = false;

		$federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
		if ($federatedFileSharingEnabled) {
			/** @var FederatedShareProvider $shareProvider */
			$shareProvider = \OC::$server->query(FederatedShareProvider::class);
			$publishedScopeEnabled = $shareProvider->isLookupServerUploadEnabled();
		}

		return [
			'provisioning_api' => [
				'version' => $this->appManager->getAppVersion('provisioning_api'),
				'AccountPropertyScopesVersion' => 2,
				'AccountPropertyScopesFederatedEnabled' => $federatedScopeEnabled,
				'AccountPropertyScopesPublishedEnabled' => $publishedScopeEnabled,
			]
		];
	}
}