Skip to content

Commit 212bc41

Browse files
committed
feat(settings): conditionally display developer documentation link based on configuration
Signed-off-by: Arsalan Ul Haq Sohni <[email protected]>
1 parent bf54725 commit 212bc41

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

apps/settings/lib/Controller/AppSettingsController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ public function viewApps(): TemplateResponse {
9292

9393
$this->initialState->provideInitialState('appstoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
9494
$this->initialState->provideInitialState('appstoreBundles', $this->getBundles());
95-
$this->initialState->provideInitialState('appstoreDeveloperDocs', $this->urlGenerator->linkToDocs('developer-manual'));
95+
96+
// Conditionally set developer docs link based on configuration
97+
$displayDocumentationLink = $this->config->getAppValue('settings', 'display_documentation_link', 'true') === 'true';
98+
$developerDocsUrl = $displayDocumentationLink ? $this->urlGenerator->linkToDocs('developer-manual') : '';
99+
$this->initialState->provideInitialState('appstoreDeveloperDocs', $developerDocsUrl);
100+
96101
$this->initialState->provideInitialState('appstoreUpdateCount', count($this->getAppsWithUpdates()));
97102

98103
if ($this->appManager->isEnabledForAnyone('app_api')) {

apps/settings/src/views/AppStoreNavigation.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
</template>
102102

103103
<NcAppNavigationItem
104+
v-if="developerDocsUrl"
104105
id="app-developer-docs"
105106
:name="t('settings', 'Developer documentation ↗')"
106107
:href="developerDocsUrl" />

apps/settings/tests/Controller/AppSettingsControllerTest.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ public function testViewApps(): void {
164164
->method('getSystemValueBool')
165165
->with('appstoreenabled', true)
166166
->willReturn(true);
167+
$this->config
168+
->expects($this->once())
169+
->method('getAppValue')
170+
->with('settings', 'display_documentation_link', 'true')
171+
->willReturn('true');
167172
$this->navigationManager
168173
->expects($this->once())
169174
->method('setActiveEntry')
@@ -209,6 +214,11 @@ public function testViewAppsAppstoreNotEnabled(): void {
209214
->method('getSystemValueBool')
210215
->with('appstoreenabled', true)
211216
->willReturn(false);
217+
$this->config
218+
->expects($this->once())
219+
->method('getAppValue')
220+
->with('settings', 'display_documentation_link', 'true')
221+
->willReturn('true');
212222
$this->navigationManager
213223
->expects($this->once())
214224
->method('setActiveEntry')
@@ -254,6 +264,11 @@ public function testDeveloperDocumentationLinkIsProvided(): void {
254264
->method('getSystemValueBool')
255265
->with('appstoreenabled', true)
256266
->willReturn(true);
267+
$this->config
268+
->expects($this->once())
269+
->method('getAppValue')
270+
->with('settings', 'display_documentation_link', 'true')
271+
->willReturn('true');
257272
$this->navigationManager
258273
->expects($this->once())
259274
->method('setActiveEntry')
@@ -297,6 +312,11 @@ public function testDeveloperDocumentationLinkWithDifferentUrls(string $expected
297312
->method('getSystemValueBool')
298313
->with('appstoreenabled', true)
299314
->willReturn(true);
315+
$this->config
316+
->expects($this->once())
317+
->method('getAppValue')
318+
->with('settings', 'display_documentation_link', 'true')
319+
->willReturn('true');
300320
$this->navigationManager
301321
->expects($this->once())
302322
->method('setActiveEntry')
@@ -332,4 +352,88 @@ public function developerDocsUrlProvider(): array {
332352
'with anchor' => ['https://docs.nextcloud.com/server/latest/developer_manual/#getting-started'],
333353
];
334354
}
355+
356+
public function testDeveloperDocumentationLinkHiddenWhenConfigured(): void {
357+
$this->installer->expects($this->any())
358+
->method('isUpdateAvailable')
359+
->willReturn(false);
360+
$this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
361+
$this->config
362+
->expects($this->once())
363+
->method('getSystemValueBool')
364+
->with('appstoreenabled', true)
365+
->willReturn(true);
366+
$this->config
367+
->expects($this->once())
368+
->method('getAppValue')
369+
->with('settings', 'display_documentation_link', 'true')
370+
->willReturn('false');
371+
$this->navigationManager
372+
->expects($this->once())
373+
->method('setActiveEntry')
374+
->with('core_apps');
375+
376+
// When display_documentation_link is false, linkToDocs should not be called
377+
$this->urlGenerator
378+
->expects($this->never())
379+
->method('linkToDocs');
380+
381+
$providedStates = [];
382+
$this->initialState
383+
->expects($this->exactly(4))
384+
->method('provideInitialState')
385+
->willReturnCallback(function ($key, $value) use (&$providedStates) {
386+
$providedStates[$key] = $value;
387+
});
388+
389+
$this->appSettingsController->viewApps();
390+
391+
// Assert that the developer docs state was provided with an empty string
392+
$this->assertArrayHasKey('appstoreDeveloperDocs', $providedStates);
393+
$this->assertEquals('', $providedStates['appstoreDeveloperDocs']);
394+
}
395+
396+
public function testDeveloperDocumentationLinkShownByDefault(): void {
397+
$this->installer->expects($this->any())
398+
->method('isUpdateAvailable')
399+
->willReturn(false);
400+
$this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
401+
$this->config
402+
->expects($this->once())
403+
->method('getSystemValueBool')
404+
->with('appstoreenabled', true)
405+
->willReturn(true);
406+
$this->config
407+
->expects($this->once())
408+
->method('getAppValue')
409+
->with('settings', 'display_documentation_link', 'true')
410+
->willReturn('true');
411+
$this->navigationManager
412+
->expects($this->once())
413+
->method('setActiveEntry')
414+
->with('core_apps');
415+
416+
$developerDocsUrl = 'https://docs.nextcloud.com/server/latest/developer_manual/';
417+
418+
// When display_documentation_link is true (default), linkToDocs should be called
419+
$this->urlGenerator
420+
->expects($this->once())
421+
->method('linkToDocs')
422+
->with('developer-manual')
423+
->willReturn($developerDocsUrl);
424+
425+
$providedStates = [];
426+
$this->initialState
427+
->expects($this->exactly(4))
428+
->method('provideInitialState')
429+
->willReturnCallback(function ($key, $value) use (&$providedStates) {
430+
$providedStates[$key] = $value;
431+
});
432+
433+
$this->appSettingsController->viewApps();
434+
435+
// Assert that the developer docs state was provided with the correct URL
436+
$this->assertArrayHasKey('appstoreDeveloperDocs', $providedStates);
437+
$this->assertEquals($developerDocsUrl, $providedStates['appstoreDeveloperDocs']);
438+
}
335439
}

0 commit comments

Comments
 (0)