mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 01:30:50 -04:00
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>
This commit is contained in:
parent
feb0f463ac
commit
2533bb5052
4 changed files with 42 additions and 15 deletions
|
|
@ -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'] = [
|
||||
|
|
|
|||
|
|
@ -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 ?
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue