Skip to content

Commit 718ef5d

Browse files
authored
Merge pull request #46510 from nextcloud/feat/info-xml-backends
feat: hide caldav server settings if no app uses the caldav backend
2 parents 7cb67c6 + e42bcea commit 718ef5d

12 files changed

Lines changed: 138 additions & 12 deletions

File tree

apps/dav/lib/Settings/CalDAVSettings.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace OCA\DAV\Settings;
77

88
use OCA\DAV\AppInfo\Application;
9+
use OCP\App\IAppManager;
910
use OCP\AppFramework\Http\TemplateResponse;
1011
use OCP\AppFramework\Services\IInitialState;
1112
use OCP\IConfig;
@@ -21,6 +22,7 @@ class CalDAVSettings implements IDelegatedSettings {
2122
private $initialState;
2223

2324
private IURLGenerator $urlGenerator;
25+
private IAppManager $appManager;
2426

2527
private const defaults = [
2628
'sendInvitations' => 'yes',
@@ -36,10 +38,11 @@ class CalDAVSettings implements IDelegatedSettings {
3638
* @param IConfig $config
3739
* @param IInitialState $initialState
3840
*/
39-
public function __construct(IConfig $config, IInitialState $initialState, IURLGenerator $urlGenerator) {
41+
public function __construct(IConfig $config, IInitialState $initialState, IURLGenerator $urlGenerator, IAppManager $appManager) {
4042
$this->config = $config;
4143
$this->initialState = $initialState;
4244
$this->urlGenerator = $urlGenerator;
45+
$this->appManager = $appManager;
4346
}
4447

4548
public function getForm(): TemplateResponse {
@@ -51,10 +54,11 @@ public function getForm(): TemplateResponse {
5154
return new TemplateResponse(Application::APP_ID, 'settings-admin-caldav');
5255
}
5356

54-
/**
55-
* @return string
56-
*/
57-
public function getSection() {
57+
public function getSection(): ?string {
58+
if (!$this->appManager->isBackendRequired(IAppManager::BACKEND_CALDAV)) {
59+
return null;
60+
}
61+
5862
return 'groupware';
5963
}
6064

apps/dav/tests/unit/Settings/CalDAVSettingsTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace OCA\DAV\Tests\Unit\DAV\Settings;
77

88
use OCA\DAV\Settings\CalDAVSettings;
9+
use OCP\App\IAppManager;
910
use OCP\AppFramework\Http\TemplateResponse;
1011
use OCP\AppFramework\Services\IInitialState;
1112
use OCP\IConfig;
@@ -24,6 +25,9 @@ class CalDAVSettingsTest extends TestCase {
2425
/** @var IURLGenerator|MockObject */
2526
private $urlGenerator;
2627

28+
/** @var IAppManager|MockObject */
29+
private $appManager;
30+
2731
private CalDAVSettings $settings;
2832

2933
protected function setUp(): void {
@@ -32,7 +36,8 @@ protected function setUp(): void {
3236
$this->config = $this->createMock(IConfig::class);
3337
$this->initialState = $this->createMock(IInitialState::class);
3438
$this->urlGenerator = $this->createMock(IURLGenerator::class);
35-
$this->settings = new CalDAVSettings($this->config, $this->initialState, $this->urlGenerator);
39+
$this->appManager = $this->createMock(IAppManager::class);
40+
$this->settings = new CalDAVSettings($this->config, $this->initialState, $this->urlGenerator, $this->appManager);
3641
}
3742

3843
public function testGetForm(): void {
@@ -65,10 +70,23 @@ public function testGetForm(): void {
6570
}
6671

6772
public function testGetSection(): void {
73+
$this->appManager->expects(self::once())
74+
->method('isBackendRequired')
75+
->with(IAppManager::BACKEND_CALDAV)
76+
->willReturn(true);
6877
$this->assertEquals('groupware', $this->settings->getSection());
6978
}
7079

80+
public function testGetSectionWithoutCaldavBackend(): void {
81+
$this->appManager->expects(self::once())
82+
->method('isBackendRequired')
83+
->with(IAppManager::BACKEND_CALDAV)
84+
->willReturn(false);
85+
$this->assertEquals(null, $this->settings->getSection());
86+
}
87+
7188
public function testGetPriority(): void {
7289
$this->assertEquals(10, $this->settings->getPriority());
7390
}
91+
7492
}

lib/private/App/AppManager.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,16 @@ public function setDefaultApps(array $defaultApps): void {
875875

876876
$this->config->setSystemValue('defaultapp', join(',', $defaultApps));
877877
}
878+
879+
public function isBackendRequired(string $backend): bool {
880+
foreach ($this->appInfos as $appInfo) {
881+
foreach ($appInfo['dependencies']['backend'] as $appBackend) {
882+
if ($backend === $appBackend) {
883+
return true;
884+
}
885+
}
886+
}
887+
888+
return false;
889+
}
878890
}

lib/private/App/InfoParser.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ public function parse($file) {
113113
if (!array_key_exists('personal-section', $array['settings'])) {
114114
$array['settings']['personal-section'] = [];
115115
}
116+
if (!array_key_exists('dependencies', $array)) {
117+
$array['dependencies'] = [];
118+
}
119+
if (!array_key_exists('backend', $array['dependencies'])) {
120+
$array['dependencies']['backend'] = [];
121+
}
116122

117123
if (array_key_exists('types', $array)) {
118124
if (is_array($array['types'])) {
@@ -177,10 +183,12 @@ public function parse($file) {
177183
if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) {
178184
$array['settings']['personal-section'] = [$array['settings']['personal-section']];
179185
}
180-
181186
if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) {
182187
$array['navigations']['navigation'] = [$array['navigations']['navigation']];
183188
}
189+
if (isset($array['dependencies']['backend']) && !is_array($array['dependencies']['backend'])) {
190+
$array['dependencies']['backend'] = [$array['dependencies']['backend']];
191+
}
184192

185193
if ($this->cache !== null) {
186194
$this->cache->set($fileCacheKey, json_encode($array));

lib/public/App/IAppManager.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
* @since 8.0.0
2020
*/
2121
interface IAppManager {
22+
/**
23+
* @since 30.0.0
24+
*/
25+
public const BACKEND_CALDAV = 'caldav';
26+
2227
/**
2328
* Returns the app information from "appinfo/info.xml".
2429
*
@@ -261,4 +266,14 @@ public function getDefaultApps(): array;
261266
* @since 28.0.0
262267
*/
263268
public function setDefaultApps(array $defaultApps): void;
269+
270+
/**
271+
* Check whether the given backend is required by at least one app.
272+
*
273+
* @param self::BACKEND_* $backend Name of the backend, one of `self::BACKEND_*`
274+
* @return bool True if at least one app requires the backend
275+
*
276+
* @since 30.0.0
277+
*/
278+
public function isBackendRequired(string $backend): bool;
264279
}

resources/app-info-shipped.xsd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@
575575
maxOccurs="1"/>
576576
<xs:element name="architecture" type="architecture" minOccurs="0"
577577
maxOccurs="unbounded"/>
578+
<xs:element name="backend" type="backend" minOccurs="0"
579+
maxOccurs="unbounded"/>
578580
</xs:sequence>
579581
</xs:complexType>
580582

@@ -757,4 +759,9 @@
757759
</xs:restriction>
758760
</xs:simpleType>
759761

762+
<xs:simpleType name="backend">
763+
<xs:restriction base="xs:string">
764+
<xs:enumeration value="caldav"/>
765+
</xs:restriction>
766+
</xs:simpleType>
760767
</xs:schema>

resources/app-info.xsd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@
563563
maxOccurs="1"/>
564564
<xs:element name="architecture" type="architecture" minOccurs="0"
565565
maxOccurs="unbounded"/>
566+
<xs:element name="backend" type="backend" minOccurs="0"
567+
maxOccurs="unbounded"/>
566568
</xs:sequence>
567569
</xs:complexType>
568570

@@ -737,4 +739,10 @@
737739
value="[a-zA-Z_][0-9a-zA-Z_]*(\\[a-zA-Z_][0-9a-zA-Z_]*)*"/>
738740
</xs:restriction>
739741
</xs:simpleType>
742+
743+
<xs:simpleType name="backend">
744+
<xs:restriction base="xs:string">
745+
<xs:enumeration value="caldav"/>
746+
</xs:restriction>
747+
</xs:simpleType>
740748
</xs:schema>

tests/data/app/expected-info.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
"min-version": "7.0.1",
6666
"max-version": "8"
6767
}
68-
}
68+
},
69+
"backend": [
70+
"caldav"
71+
]
6972
},
7073
"repair-steps": {
7174
"install": [],

tests/data/app/navigation-one-item.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"min-version": "16",
3030
"max-version": "16"
3131
}
32-
}
32+
},
33+
"backend": []
3334
},
3435
"background-jobs": [
3536
"OCA\\Activity\\BackgroundJob\\EmailNotification",
@@ -82,4 +83,4 @@
8283
"uninstall": []
8384
},
8485
"two-factor-providers": []
85-
}
86+
}

tests/data/app/navigation-two-items.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"min-version": "16",
3030
"max-version": "16"
3131
}
32-
}
32+
},
33+
"backend": []
3334
},
3435
"background-jobs": [
3536
"OCA\\Activity\\BackgroundJob\\EmailNotification",
@@ -88,4 +89,4 @@
8889
"uninstall": []
8990
},
9091
"two-factor-providers": []
91-
}
92+
}

0 commit comments

Comments
 (0)