Skip to content

Commit

Permalink
Split capability
Browse files Browse the repository at this point in the history
The "federated" and "published" scopes are independent one from each
other, so the capability that encompassed both needs to be split.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu committed Aug 18, 2021
1 parent ce70600 commit b006c9c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
9 changes: 6 additions & 3 deletions apps/provisioning_api/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@ public function __construct(IAppManager $appManager) {
* @return array Array containing the apps capabilities
*/
public function getCapabilities() {
$federationScopesEnabled = false;
$federatedScopeEnabled = $this->appManager->isEnabledForUser('federation');

$publishedScopeEnabled = false;

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

return [
'provisioning_api' => [
'version' => $this->appManager->getAppVersion('provisioning_api'),
'AccountPropertyScopesVersion' => 2,
'AccountPropertyScopesFederationEnabled' => $federationScopesEnabled,
'AccountPropertyScopesFederatedEnabled' => $federatedScopeEnabled,
'AccountPropertyScopesPublishedEnabled' => $publishedScopeEnabled,
]
];
}
Expand Down
24 changes: 15 additions & 9 deletions apps/provisioning_api/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,25 @@ public function setUp(): void {

public function getCapabilitiesProvider() {
return [
[false, false, false],
[true, false, false],
[true, true, true],
[true, false, false, true, false],
[true, true, false, true, false],
[true, true, true, true, true],
[false, false, false, false, false],
[false, true, false, false, false],
[false, true, true, false, true],
];
}

/**
* @dataProvider getCapabilitiesProvider
*/
public function testGetCapabilities($federationAppEnabled, $lookupServerEnabled, $expectedFederationScopesEnabled) {
$this->appManager->expects($this->once())
->method('isEnabledForUser')
->with('federatedfilesharing')
->willReturn($federationAppEnabled);
public function testGetCapabilities($federationAppEnabled, $federatedFileSharingAppEnabled, $lookupServerEnabled, $expectedFederatedScopeEnabled, $expectedPublishedScopeEnabled) {
$this->appManager->expects($this->any())
->method('isEnabledForUser')
->will($this->returnValueMap([
['federation', null, $federationAppEnabled],
['federatedfilesharing', null, $federatedFileSharingAppEnabled],
]));

$federatedShareProvider = $this->createMock(FederatedShareProvider::class);
$this->overwriteService(FederatedShareProvider::class, $federatedShareProvider);
Expand All @@ -83,7 +88,8 @@ public function testGetCapabilities($federationAppEnabled, $lookupServerEnabled,
'provisioning_api' => [
'version' => '1.12',
'AccountPropertyScopesVersion' => 2,
'AccountPropertyScopesFederationEnabled' => $expectedFederationScopesEnabled,
'AccountPropertyScopesFederatedEnabled' => $expectedFederatedScopeEnabled,
'AccountPropertyScopesPublishedEnabled' => $expectedPublishedScopeEnabled,
],
];
$this->assertSame($expected, $this->capabilities->getCapabilities());
Expand Down

0 comments on commit b006c9c

Please sign in to comment.