From 4a2893c917b5ab7dc728d2e06f04e1b8912d9bfa Mon Sep 17 00:00:00 2001 From: "Misha M.-Kupriyanov" Date: Thu, 22 May 2025 18:23:37 +0200 Subject: [PATCH] feat(files-sharing): show pending shares menu only if feature enabled # menu is removed on ./occ config:system:set --value true --type boolean -- sharing.enable_share_accept # menu is shown on ./occ config:system:set --value false --type boolean -- sharing.enable_share_accept Signed-off-by: Misha M.-Kupriyanov --- .../lib/Listener/LoadAdditionalListener.php | 11 +++++++ apps/files_sharing/src/files_views/shares.ts | 13 ++++++++ .../Listener/LoadAdditionalListenerTest.php | 32 +++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/apps/files_sharing/lib/Listener/LoadAdditionalListener.php b/apps/files_sharing/lib/Listener/LoadAdditionalListener.php index b089c8309b7..3d9fdb2df81 100644 --- a/apps/files_sharing/lib/Listener/LoadAdditionalListener.php +++ b/apps/files_sharing/lib/Listener/LoadAdditionalListener.php @@ -8,11 +8,13 @@ declare(strict_types=1); */ namespace OCA\Files_Sharing\Listener; +use OC\InitialStateService; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files_Sharing\AppInfo\Application; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\Server; +use OCP\IConfig; use OCP\Share\IManager; use OCP\Util; @@ -31,5 +33,14 @@ class LoadAdditionalListener implements IEventListener { if ($shareManager->shareApiEnabled() && class_exists('\OCA\Files\App')) { Util::addInitScript(Application::APP_ID, 'init'); } + + $this->provideInitialStates(); + } + + private function provideInitialStates(): void { + $initialState = Server::get(InitialStateService::class); + $config = Server::get(IConfig::class); + $defaultAcceptSystemConfig = $config->getSystemValueBool('sharing.enable_share_accept'); + $initialState->provideInitialState(Application::APP_ID, 'accept_default', $defaultAcceptSystemConfig); } } diff --git a/apps/files_sharing/src/files_views/shares.ts b/apps/files_sharing/src/files_views/shares.ts index 297fd4796fd..fbdff852b57 100644 --- a/apps/files_sharing/src/files_views/shares.ts +++ b/apps/files_sharing/src/files_views/shares.ts @@ -24,6 +24,15 @@ export const deletedSharesViewId = 'deletedshares' export const pendingSharesViewId = 'pendingshares' export const fileRequestViewId = 'filerequest' +/** + * Checks if share accept approval required by nextcloud configuration. + * + * @returns {boolean} True if share accept approval is required, otherwise false. + */ +function isShareAcceptApprovalRequired(): boolean { + return loadState('files_sharing', 'accept_default', false) +} + export default () => { const Navigation = getNavigation() Navigation.register(new View({ @@ -137,6 +146,10 @@ export default () => { getContents: () => getContents(false, false, false, true), })) + if (!isShareAcceptApprovalRequired()) { + return + } + Navigation.register(new View({ id: pendingSharesViewId, name: t('files_sharing', 'Pending shares'), diff --git a/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php b/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php index 75bee35d58a..e72a6c49c4e 100644 --- a/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php +++ b/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php @@ -117,4 +117,36 @@ class LoadAdditionalListenerTest extends TestCase { // assert array $scripts contains the expected scripts $this->assertContains('files_sharing/js/init', $scriptsAfter); } + + public function testProvideInitialStates(): void { + $listener = new LoadAdditionalListener(); + + // Expect config to be queried for 'sharing.enable_share_accept' + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('sharing.enable_share_accept') + ->willReturn(true); + + // Expect initial state to be provided with correct values + $this->initialStateService->expects($this->once()) + ->method('provideInitialState') + ->with( + 'files_sharing', + 'accept_default', + true + ); + + // Other dependencies required by the listener + $this->shareManager->method('shareApiEnabled')->willReturn(true); + + // Mock the server container to return the correct dependencies + $this->overwriteService(IManager::class, $this->shareManager); + $this->overwriteService(InitialStateService::class, $this->initialStateService); + $this->overwriteService(IConfig::class, $this->config); + $this->overwriteService(IFactory::class, $this->factory); + + $listener->handle($this->event); + + $this->assertTrue(true); + } }