From 2533bb50524ee1207d5d8364b543cc5af7bb783d Mon Sep 17 00:00:00 2001 From: nfebe Date: Thu, 7 Aug 2025 06:14:40 +0100 Subject: [PATCH] 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 --- apps/files_sharing/lib/Capabilities.php | 28 +++++++++++++------ .../src/services/ConfigService.ts | 7 +++++ apps/files_sharing/src/views/SharingTab.vue | 6 ++-- apps/files_sharing/tests/CapabilitiesTest.php | 16 +++++++++-- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/apps/files_sharing/lib/Capabilities.php b/apps/files_sharing/lib/Capabilities.php index 1f491216abe..3763bb66ad6 100644 --- a/apps/files_sharing/lib/Capabilities.php +++ b/apps/files_sharing/lib/Capabilities.php @@ -6,6 +6,7 @@ */ namespace OCA\Files_Sharing; +use OCP\App\IAppManager; use OCP\Capabilities\ICapability; use OCP\Constants; use OCP\IConfig; @@ -17,10 +18,10 @@ use OCP\Share\IManager; * @package OCA\Files_Sharing */ class Capabilities implements ICapability { - public function __construct( private IConfig $config, private IManager $shareManager, + private IAppManager $appManager, ) { } @@ -157,14 +158,23 @@ class Capabilities implements ICapability { } //Federated sharing - $res['federation'] = [ - 'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(), - 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes', - // old bogus one, expire_date was not working before, keeping for compatibility - 'expire_date' => ['enabled' => true], - // the real deal, signifies that expiration date can be set on federated shares - 'expire_date_supported' => ['enabled' => true], - ]; + if ($this->appManager->isInstalled('federation')) { + $res['federation'] = [ + 'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(), + 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes', + // old bogus one, expire_date was not working before, keeping for compatibility + 'expire_date' => ['enabled' => true], + // the real deal, signifies that expiration date can be set on federated shares + 'expire_date_supported' => ['enabled' => true], + ]; + } else { + $res['federation'] = [ + 'outgoing' => false, + 'incoming' => false, + 'expire_date' => ['enabled' => false], + 'expire_date_supported' => ['enabled' => false], + ]; + } // Sharee searches $res['sharee'] = [ diff --git a/apps/files_sharing/src/services/ConfigService.ts b/apps/files_sharing/src/services/ConfigService.ts index f75f34c7936..547038f362d 100644 --- a/apps/files_sharing/src/services/ConfigService.ts +++ b/apps/files_sharing/src/services/ConfigService.ts @@ -212,6 +212,13 @@ export default class Config { return window.OC.appConfig.core.remoteShareAllowed === true } + /** + * Is federation enabled ? + */ + get isFederationEnabled(): boolean { + return this._capabilities?.files_sharing?.federation?.outgoing === true + } + /** * Is public sharing enabled ? */ diff --git a/apps/files_sharing/src/views/SharingTab.vue b/apps/files_sharing/src/views/SharingTab.vue index fd88d9a2193..706ddc3cb46 100644 --- a/apps/files_sharing/src/views/SharingTab.vue +++ b/apps/files_sharing/src/views/SharingTab.vue @@ -272,14 +272,13 @@ export default { externalShareInputPlaceholder() { if (!this.isLinkSharingAllowed) { - return t('files_sharing', 'Federated cloud ID') + return this.config.isFederationEnabled ? t('files_sharing', 'Federated cloud ID') : '' } - return this.config.showFederatedSharesAsInternal + return !this.config.showFederatedSharesAsInternal && !this.config.isFederationEnabled ? t('files_sharing', 'Email') : t('files_sharing', 'Email, federated cloud id') }, }, - methods: { /** * Update current fileInfo and fetch new data @@ -291,7 +290,6 @@ export default { this.resetState() this.getShares() }, - /** * Get the existing shares infos */ diff --git a/apps/files_sharing/tests/CapabilitiesTest.php b/apps/files_sharing/tests/CapabilitiesTest.php index 737362e2195..1e4c00d298f 100644 --- a/apps/files_sharing/tests/CapabilitiesTest.php +++ b/apps/files_sharing/tests/CapabilitiesTest.php @@ -10,6 +10,7 @@ use OC\KnownUser\KnownUserService; use OC\Share20\Manager; use OC\Share20\ShareDisableChecker; use OCA\Files_Sharing\Capabilities; +use OCP\App\IAppManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountManager; @@ -54,9 +55,11 @@ class CapabilitiesTest extends \Test\TestCase { * @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock * @return string[] */ - private function getResults(array $map) { + private function getResults(array $map, bool $federationEnabled = true) { $config = $this->getMockBuilder(IConfig::class)->disableOriginalConstructor()->getMock(); + $appManager = $this->getMockBuilder(IAppManager::class)->disableOriginalConstructor()->getMock(); $config->method('getAppValue')->willReturnMap($map); + $appManager->method('isInstalled')->with('federation')->willReturn($federationEnabled); $shareManager = new Manager( $this->createMock(LoggerInterface::class), $config, @@ -78,7 +81,7 @@ class CapabilitiesTest extends \Test\TestCase { $this->createMock(IDateTimeZone::class), $this->createMock(IAppConfig::class), ); - $cap = new Capabilities($config, $shareManager); + $cap = new Capabilities($config, $shareManager, $appManager); $result = $this->getFilesSharingPart($cap->getCapabilities()); return $result; } @@ -322,4 +325,13 @@ class CapabilitiesTest extends \Test\TestCase { $this->assertEquals(['enabled' => true], $result['federation']['expire_date']); $this->assertEquals(['enabled' => true], $result['federation']['expire_date_supported']); } + + public function testFederatedSharingDisabled(): void { + $result = $this->getResults([], false); + $this->assertArrayHasKey('federation', $result); + $this->assertFalse($result['federation']['incoming']); + $this->assertFalse($result['federation']['outgoing']); + $this->assertEquals(['enabled' => false], $result['federation']['expire_date']); + $this->assertEquals(['enabled' => false], $result['federation']['expire_date_supported']); + } }