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>
This commit is contained in:
Misha M.-Kupriyanov 2025-05-22 18:23:37 +02:00 committed by Mikhailo Matiyenko-Kupriyanov
parent 58a37108da
commit 4a2893c917
3 changed files with 56 additions and 0 deletions

View file

@ -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);
}
}

View file

@ -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'),

View file

@ -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);
}
}