Skip to content

Commit 48e6ba0

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

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-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: 94 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')
@@ -243,4 +253,88 @@ public function testViewAppsAppstoreNotEnabled(): void {
243253

244254
$this->assertEquals($expected, $this->appSettingsController->viewApps());
245255
}
256+
257+
public function testDeveloperDocumentationLinkHiddenWhenConfigured(): void {
258+
$this->installer->expects($this->any())
259+
->method('isUpdateAvailable')
260+
->willReturn(false);
261+
$this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
262+
$this->config
263+
->expects($this->once())
264+
->method('getSystemValueBool')
265+
->with('appstoreenabled', true)
266+
->willReturn(true);
267+
$this->config
268+
->expects($this->once())
269+
->method('getAppValue')
270+
->with('settings', 'display_documentation_link', 'true')
271+
->willReturn('false');
272+
$this->navigationManager
273+
->expects($this->once())
274+
->method('setActiveEntry')
275+
->with('core_apps');
276+
277+
// When display_documentation_link is false, linkToDocs should not be called
278+
$this->urlGenerator
279+
->expects($this->never())
280+
->method('linkToDocs');
281+
282+
$providedStates = [];
283+
$this->initialState
284+
->expects($this->exactly(4))
285+
->method('provideInitialState')
286+
->willReturnCallback(function ($key, $value) use (&$providedStates) {
287+
$providedStates[$key] = $value;
288+
});
289+
290+
$this->appSettingsController->viewApps();
291+
292+
// Assert that the developer docs state was provided with an empty string
293+
$this->assertArrayHasKey('appstoreDeveloperDocs', $providedStates);
294+
$this->assertEquals('', $providedStates['appstoreDeveloperDocs']);
295+
}
296+
297+
public function testDeveloperDocumentationLinkShownByDefault(): void {
298+
$this->installer->expects($this->any())
299+
->method('isUpdateAvailable')
300+
->willReturn(false);
301+
$this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
302+
$this->config
303+
->expects($this->once())
304+
->method('getSystemValueBool')
305+
->with('appstoreenabled', true)
306+
->willReturn(true);
307+
$this->config
308+
->expects($this->once())
309+
->method('getAppValue')
310+
->with('settings', 'display_documentation_link', 'true')
311+
->willReturn('true');
312+
$this->navigationManager
313+
->expects($this->once())
314+
->method('setActiveEntry')
315+
->with('core_apps');
316+
317+
$developerDocsUrl = 'https://docs.nextcloud.com/server/latest/developer_manual/';
318+
319+
// When display_documentation_link is true (default), linkToDocs should be called
320+
$this->urlGenerator
321+
->expects($this->once())
322+
->method('linkToDocs')
323+
->with('developer-manual')
324+
->willReturn($developerDocsUrl);
325+
326+
$providedStates = [];
327+
$this->initialState
328+
->expects($this->exactly(4))
329+
->method('provideInitialState')
330+
->willReturnCallback(function ($key, $value) use (&$providedStates) {
331+
$providedStates[$key] = $value;
332+
});
333+
334+
$this->appSettingsController->viewApps();
335+
336+
// Assert that the developer docs state was provided with the correct URL
337+
$this->assertArrayHasKey('appstoreDeveloperDocs', $providedStates);
338+
$this->assertEquals($developerDocsUrl, $providedStates['appstoreDeveloperDocs']);
339+
}
246340
}

0 commit comments

Comments
 (0)