Skip to content

Commit 8315a49

Browse files
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 <kupriyanov@strato.de>
1 parent aae73b1 commit 8315a49

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

apps/files_sharing/lib/Listener/LoadAdditionalListener.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
namespace OCA\Files_Sharing\Listener;
1111

12+
use OC\InitialStateService;
1213
use OCA\Files\Event\LoadAdditionalScriptsEvent;
1314
use OCA\Files_Sharing\AppInfo\Application;
1415
use OCP\EventDispatcher\Event;
1516
use OCP\EventDispatcher\IEventListener;
1617
use OCP\Server;
18+
use OCP\IConfig;
1719
use OCP\Share\IManager;
1820
use OCP\Util;
1921

@@ -33,5 +35,14 @@ public function handle(Event $event): void {
3335
if ($shareManager->shareApiEnabled()) {
3436
Util::addInitScript(Application::APP_ID, 'init');
3537
}
38+
39+
$this->provideInitialStates();
40+
}
41+
42+
private function provideInitialStates(): void {
43+
$initialState = Server::get(InitialStateService::class);
44+
$config = Server::get(IConfig::class);
45+
$defaultAcceptSystemConfig = $config->getSystemValueBool('sharing.enable_share_accept');
46+
$initialState->provideInitialState(Application::APP_ID, 'accept_default', $defaultAcceptSystemConfig);
3647
}
3748
}

apps/files_sharing/src/files_views/shares.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ export const deletedSharesViewId = 'deletedshares'
2424
export const pendingSharesViewId = 'pendingshares'
2525
export const fileRequestViewId = 'filerequest'
2626

27+
/**
28+
* Checks if share accept approval required by nextcloud configuration.
29+
*
30+
* @returns {boolean} True if share accept approval is required, otherwise false.
31+
*/
32+
function isShareAcceptApprovalRequired(): boolean {
33+
return loadState('files_sharing', 'accept_default', false)
34+
}
35+
2736
export default () => {
2837
const Navigation = getNavigation()
2938
Navigation.register(new View({
@@ -137,6 +146,10 @@ export default () => {
137146
getContents: () => getContents(false, false, false, true),
138147
}))
139148

149+
if (!isShareAcceptApprovalRequired()) {
150+
return
151+
}
152+
140153
Navigation.register(new View({
141154
id: pendingSharesViewId,
142155
name: t('files_sharing', 'Pending shares'),

apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,36 @@ public function testHandleWithLoadAdditionalScriptsEventWithShareApiEnabled(): v
117117
// assert array $scripts contains the expected scripts
118118
$this->assertContains('files_sharing/js/init', $scriptsAfter);
119119
}
120+
121+
public function testProvideInitialStates(): void {
122+
$listener = new LoadAdditionalListener();
123+
124+
// Expect config to be queried for 'sharing.enable_share_accept'
125+
$this->config->expects($this->once())
126+
->method('getSystemValueBool')
127+
->with('sharing.enable_share_accept')
128+
->willReturn(true);
129+
130+
// Expect initial state to be provided with correct values
131+
$this->initialStateService->expects($this->once())
132+
->method('provideInitialState')
133+
->with(
134+
'files_sharing',
135+
'accept_default',
136+
true
137+
);
138+
139+
// Other dependencies required by the listener
140+
$this->shareManager->method('shareApiEnabled')->willReturn(true);
141+
142+
// Mock the server container to return the correct dependencies
143+
$this->overwriteService(IManager::class, $this->shareManager);
144+
$this->overwriteService(InitialStateService::class, $this->initialStateService);
145+
$this->overwriteService(IConfig::class, $this->config);
146+
$this->overwriteService(IFactory::class, $this->factory);
147+
148+
$listener->handle($this->event);
149+
150+
$this->assertTrue(true);
151+
}
120152
}

0 commit comments

Comments
 (0)