diff --git a/apps/dav/lib/Settings/CalDAVSettings.php b/apps/dav/lib/Settings/CalDAVSettings.php index 75bb70c530a96..7c738a83148f0 100644 --- a/apps/dav/lib/Settings/CalDAVSettings.php +++ b/apps/dav/lib/Settings/CalDAVSettings.php @@ -6,6 +6,7 @@ namespace OCA\DAV\Settings; use OCA\DAV\AppInfo\Application; +use OCP\App\IAppManager; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\IConfig; @@ -21,6 +22,7 @@ class CalDAVSettings implements IDelegatedSettings { private $initialState; private IURLGenerator $urlGenerator; + private IAppManager $appManager; private const defaults = [ 'sendInvitations' => 'yes', @@ -36,10 +38,11 @@ class CalDAVSettings implements IDelegatedSettings { * @param IConfig $config * @param IInitialState $initialState */ - public function __construct(IConfig $config, IInitialState $initialState, IURLGenerator $urlGenerator) { + public function __construct(IConfig $config, IInitialState $initialState, IURLGenerator $urlGenerator, IAppManager $appManager) { $this->config = $config; $this->initialState = $initialState; $this->urlGenerator = $urlGenerator; + $this->appManager = $appManager; } public function getForm(): TemplateResponse { @@ -51,10 +54,11 @@ public function getForm(): TemplateResponse { return new TemplateResponse(Application::APP_ID, 'settings-admin-caldav'); } - /** - * @return string - */ - public function getSection() { + public function getSection(): ?string { + if (!$this->appManager->isBackendRequired(IAppManager::BACKEND_CALDAV)) { + return null; + } + return 'groupware'; } diff --git a/apps/dav/tests/unit/Settings/CalDAVSettingsTest.php b/apps/dav/tests/unit/Settings/CalDAVSettingsTest.php index 46a8db6f3eb28..ed497d006e14d 100644 --- a/apps/dav/tests/unit/Settings/CalDAVSettingsTest.php +++ b/apps/dav/tests/unit/Settings/CalDAVSettingsTest.php @@ -6,6 +6,7 @@ namespace OCA\DAV\Tests\Unit\DAV\Settings; use OCA\DAV\Settings\CalDAVSettings; +use OCP\App\IAppManager; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\IConfig; @@ -24,6 +25,9 @@ class CalDAVSettingsTest extends TestCase { /** @var IURLGenerator|MockObject */ private $urlGenerator; + /** @var IAppManager|MockObject */ + private $appManager; + private CalDAVSettings $settings; protected function setUp(): void { @@ -32,7 +36,8 @@ protected function setUp(): void { $this->config = $this->createMock(IConfig::class); $this->initialState = $this->createMock(IInitialState::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->settings = new CalDAVSettings($this->config, $this->initialState, $this->urlGenerator); + $this->appManager = $this->createMock(IAppManager::class); + $this->settings = new CalDAVSettings($this->config, $this->initialState, $this->urlGenerator, $this->appManager); } public function testGetForm(): void { @@ -65,10 +70,23 @@ public function testGetForm(): void { } public function testGetSection(): void { + $this->appManager->expects(self::once()) + ->method('isBackendRequired') + ->with(IAppManager::BACKEND_CALDAV) + ->willReturn(true); $this->assertEquals('groupware', $this->settings->getSection()); } + public function testGetSectionWithoutCaldavBackend(): void { + $this->appManager->expects(self::once()) + ->method('isBackendRequired') + ->with(IAppManager::BACKEND_CALDAV) + ->willReturn(false); + $this->assertEquals(null, $this->settings->getSection()); + } + public function testGetPriority(): void { $this->assertEquals(10, $this->settings->getPriority()); } + } diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 52a88a724ffb1..482d45ca19146 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -875,4 +875,14 @@ public function setDefaultApps(array $defaultApps): void { $this->config->setSystemValue('defaultapp', join(',', $defaultApps)); } + + public function isBackendRequired(string $backend): bool { + foreach ($this->appInfos as $appInfo) { + if (isset($appInfo['backends'][$backend])) { + return true; + } + } + + return false; + } } diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php index d29b1d6596d99..66dc64aca72e8 100644 --- a/lib/private/App/InfoParser.php +++ b/lib/private/App/InfoParser.php @@ -113,6 +113,9 @@ public function parse($file) { if (!array_key_exists('personal-section', $array['settings'])) { $array['settings']['personal-section'] = []; } + if (!array_key_exists('backends', $array)) { + $array['backends'] = []; + } if (array_key_exists('types', $array)) { if (is_array($array['types'])) { diff --git a/lib/public/App/IAppManager.php b/lib/public/App/IAppManager.php index 508143426f585..2d302b5e4408e 100644 --- a/lib/public/App/IAppManager.php +++ b/lib/public/App/IAppManager.php @@ -19,6 +19,11 @@ * @since 8.0.0 */ interface IAppManager { + /** + * @since 30.0.0 + */ + const BACKEND_CALDAV = 'caldav'; + /** * Returns the app information from "appinfo/info.xml". * @@ -261,4 +266,14 @@ public function getDefaultApps(): array; * @since 28.0.0 */ public function setDefaultApps(array $defaultApps): void; + + /** + * Check whether the given backend is required by at least one app. + * + * @param self::BACKEND_* $backend Name of the backend, one of `self::BACKEND_*` + * @return bool True if at least one app requires the backend + * + * @since 30.0.0 + */ + public function isBackendRequired(string $backend): bool; } diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index 8527f18a2c054..589521e28f199 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -87,5 +87,8 @@ "admin-section": [], "personal": [], "personal-section": [] + }, + "backends": { + "caldav": "" } } diff --git a/tests/data/app/navigation-one-item.json b/tests/data/app/navigation-one-item.json index c9002da6b0dba..8268521ba4aa9 100644 --- a/tests/data/app/navigation-one-item.json +++ b/tests/data/app/navigation-one-item.json @@ -81,5 +81,6 @@ "live-migration": [], "uninstall": [] }, - "two-factor-providers": [] -} \ No newline at end of file + "two-factor-providers": [], + "backends": {} +} diff --git a/tests/data/app/navigation-two-items.json b/tests/data/app/navigation-two-items.json index a7579217238fd..2c18db9a17caa 100644 --- a/tests/data/app/navigation-two-items.json +++ b/tests/data/app/navigation-two-items.json @@ -87,5 +87,6 @@ "live-migration": [], "uninstall": [] }, - "two-factor-providers": [] -} \ No newline at end of file + "two-factor-providers": [], + "backends": {} +} diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index 9044c00f3536e..c5b9d30f75b2b 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -35,4 +35,7 @@ Linux + + +