Skip to content

Commit 156590d

Browse files
nfebeAndyScherzinger
authored andcommitted
fix(files_sharing): Implementation conditional federation placeholder
This commits addresses an annoyance where the share input placeholder would suggest sharing via federated cloud ID even if federation was disabled. Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent 05b83dc commit 156590d

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

apps/files_sharing/lib/Capabilities.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace OCA\Files_Sharing;
99

10+
use OCP\App\IAppManager;
1011
use OCP\Capabilities\ICapability;
1112
use OCP\Constants;
1213
use OCP\IConfig;
@@ -19,14 +20,7 @@
1920
*/
2021
class Capabilities implements ICapability {
2122

22-
/** @var IConfig */
23-
private $config;
24-
/** @var IManager */
25-
private $shareManager;
26-
27-
public function __construct(IConfig $config, IManager $shareManager) {
28-
$this->config = $config;
29-
$this->shareManager = $shareManager;
23+
public function __construct(private IConfig $config, private IManager $shareManager, private IAppManager $appManager) {
3024
}
3125

3226
/**
@@ -160,14 +154,23 @@ public function getCapabilities() {
160154
}
161155

162156
//Federated sharing
163-
$res['federation'] = [
164-
'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(),
165-
'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
166-
// old bogus one, expire_date was not working before, keeping for compatibility
167-
'expire_date' => ['enabled' => true],
168-
// the real deal, signifies that expiration date can be set on federated shares
169-
'expire_date_supported' => ['enabled' => true],
170-
];
157+
if ($this->appManager->isInstalled('federation')) {
158+
$res['federation'] = [
159+
'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(),
160+
'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
161+
// old bogus one, expire_date was not working before, keeping for compatibility
162+
'expire_date' => ['enabled' => true],
163+
// the real deal, signifies that expiration date can be set on federated shares
164+
'expire_date_supported' => ['enabled' => true],
165+
];
166+
} else {
167+
$res['federation'] = [
168+
'outgoing' => false,
169+
'incoming' => false,
170+
'expire_date' => ['enabled' => false],
171+
'expire_date_supported' => ['enabled' => false],
172+
];
173+
}
171174

172175
// Sharee searches
173176
$res['sharee'] = [

apps/files_sharing/src/services/ConfigService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ export default class Config {
210210
return window.OC.appConfig.core.remoteShareAllowed === true
211211
}
212212

213+
/**
214+
* Is federation enabled ?
215+
*/
216+
get isFederationEnabled(): boolean {
217+
return this._capabilities?.files_sharing?.federation?.outgoing === true
218+
}
219+
213220
/**
214221
* Is public sharing enabled ?
215222
*/

apps/files_sharing/src/views/SharingTab.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ export default {
156156
|| !!(this.reshare && this.reshare.hasSharePermission && this.config.isResharingAllowed)
157157
},
158158
},
159-
160159
methods: {
161160
/**
162161
* Update current fileInfo and fetch new data
@@ -168,7 +167,6 @@ export default {
168167
this.resetState()
169168
this.getShares()
170169
},
171-
172170
/**
173171
* Get the existing shares infos
174172
*/

apps/files_sharing/tests/CapabilitiesTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OC\Share20\Manager;
1212
use OC\Share20\ShareDisableChecker;
1313
use OCA\Files_Sharing\Capabilities;
14+
use OCP\App\IAppManager;
1415
use OCP\EventDispatcher\IEventDispatcher;
1516
use OCP\Files\IRootFolder;
1617
use OCP\Files\Mount\IMountManager;
@@ -54,9 +55,11 @@ private function getFilesSharingPart(array $data) {
5455
* @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock
5556
* @return string[]
5657
*/
57-
private function getResults(array $map) {
58+
private function getResults(array $map, bool $federationEnabled = true) {
5859
$config = $this->getMockBuilder(IConfig::class)->disableOriginalConstructor()->getMock();
60+
$appManager = $this->getMockBuilder(IAppManager::class)->disableOriginalConstructor()->getMock();
5961
$config->method('getAppValue')->willReturnMap($map);
62+
$appManager->method('isInstalled')->with('federation')->willReturn($federationEnabled);
6063
$shareManager = new Manager(
6164
$this->createMock(LoggerInterface::class),
6265
$config,
@@ -77,7 +80,7 @@ private function getResults(array $map) {
7780
$this->createMock(ShareDisableChecker::class),
7881
$this->createMock(IDateTimeZone::class),
7982
);
80-
$cap = new Capabilities($config, $shareManager);
83+
$cap = new Capabilities($config, $shareManager, $appManager);
8184
$result = $this->getFilesSharingPart($cap->getCapabilities());
8285
return $result;
8386
}
@@ -321,4 +324,13 @@ public function testFederatedSharingExpirationDate() {
321324
$this->assertEquals(['enabled' => true], $result['federation']['expire_date']);
322325
$this->assertEquals(['enabled' => true], $result['federation']['expire_date_supported']);
323326
}
327+
328+
public function testFederatedSharingDisabled(): void {
329+
$result = $this->getResults([], false);
330+
$this->assertArrayHasKey('federation', $result);
331+
$this->assertFalse($result['federation']['incoming']);
332+
$this->assertFalse($result['federation']['outgoing']);
333+
$this->assertEquals(['enabled' => false], $result['federation']['expire_date']);
334+
$this->assertEquals(['enabled' => false], $result['federation']['expire_date_supported']);
335+
}
324336
}

0 commit comments

Comments
 (0)