Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/settings/lib/Controller/AppSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
Expand Down Expand Up @@ -76,6 +77,7 @@ public function __construct(
private IInitialState $initialState,
private AppDiscoverFetcher $discoverFetcher,
private IClientService $clientService,
private IAppConfig $appConfig,
) {
parent::__construct($appName, $request);
$this->appData = $appDataFactory->get('appstore');
Expand All @@ -92,7 +94,12 @@ public function viewApps(): TemplateResponse {

$this->initialState->provideInitialState('appstoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
$this->initialState->provideInitialState('appstoreBundles', $this->getBundles());
$this->initialState->provideInitialState('appstoreDeveloperDocs', $this->urlGenerator->linkToDocs('developer-manual'));

// Conditionally set developer docs link based on configuration
$displayDocumentationLink = $this->appConfig->getValueBool('settings', 'display_documentation_link', true);
$developerDocsUrl = $displayDocumentationLink ? $this->urlGenerator->linkToDocs('developer-manual') : '';
$this->initialState->provideInitialState('appstoreDeveloperDocs', $developerDocsUrl);

$this->initialState->provideInitialState('appstoreUpdateCount', count($this->getAppsWithUpdates()));

if ($this->appManager->isEnabledForAnyone('app_api')) {
Expand Down
1 change: 1 addition & 0 deletions apps/settings/src/views/AppStoreNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
</template>

<NcAppNavigationItem
v-if="developerDocsUrl"
id="app-developer-docs"
:name="t('settings', 'Developer documentation ↗')"
:href="developerDocsUrl" />
Expand Down
126 changes: 124 additions & 2 deletions apps/settings/tests/Controller/AppSettingsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\AppFramework\Services\IInitialState;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
Expand All @@ -40,6 +41,7 @@ class AppSettingsControllerTest extends TestCase {
private IRequest&MockObject $request;
private IL10N&MockObject $l10n;
private IConfig&MockObject $config;
private IAppConfig&MockObject $appConfig;
private INavigationManager&MockObject $navigationManager;
private AppManager&MockObject $appManager;
private CategoryFetcher&MockObject $categoryFetcher;
Expand All @@ -65,6 +67,7 @@ protected function setUp(): void {
->method('t')
->willReturnArgument(0);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->navigationManager = $this->createMock(INavigationManager::class);
$this->appManager = $this->createMock(AppManager::class);
$this->categoryFetcher = $this->createMock(CategoryFetcher::class);
Expand Down Expand Up @@ -96,6 +99,7 @@ protected function setUp(): void {
$this->initialState,
$this->discoverFetcher,
$this->clientService,
$this->appConfig,
);
}

Expand Down Expand Up @@ -164,14 +168,31 @@ public function testViewApps(): void {
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);
$this->appConfig
->expects($this->once())
->method('getValueBool')
->with('settings', 'display_documentation_link', true)
->willReturn(true);
$this->navigationManager
->expects($this->once())
->method('setActiveEntry')
->with('core_apps');

// Test that developer docs link is generated correctly
$this->urlGenerator
->expects($this->once())
->method('linkToDocs')
->with('developer-manual')
->willReturn('https://docs.nextcloud.com/server/latest/developer_manual/');

$this->initialState
->expects($this->exactly(4))
->method('provideInitialState');
->method('provideInitialState')
->willReturnCallback(function ($key, $value) {
if ($key === 'appstoreDeveloperDocs') {
$this->assertEquals('https://docs.nextcloud.com/server/latest/developer_manual/', $value);
}
});

$policy = new ContentSecurityPolicy();
$policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
Expand All @@ -197,14 +218,31 @@ public function testViewAppsAppstoreNotEnabled(): void {
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(false);
$this->appConfig
->expects($this->once())
->method('getValueBool')
->with('settings', 'display_documentation_link', true)
->willReturn(true);
$this->navigationManager
->expects($this->once())
->method('setActiveEntry')
->with('core_apps');

// Test that developer docs link is still generated even when appstore is disabled
$this->urlGenerator
->expects($this->once())
->method('linkToDocs')
->with('developer-manual')
->willReturn('https://docs.nextcloud.com/server/latest/developer_manual/');

$this->initialState
->expects($this->exactly(4))
->method('provideInitialState');
->method('provideInitialState')
->willReturnCallback(function ($key, $value) {
if ($key === 'appstoreDeveloperDocs') {
$this->assertEquals('https://docs.nextcloud.com/server/latest/developer_manual/', $value);
}
});

$policy = new ContentSecurityPolicy();
$policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
Expand All @@ -219,4 +257,88 @@ public function testViewAppsAppstoreNotEnabled(): void {

$this->assertEquals($expected, $this->appSettingsController->viewApps());
}

public function testDeveloperDocumentationLinkHiddenWhenConfigured(): void {
$this->installer->expects($this->any())
->method('isUpdateAvailable')
->willReturn(false);
$this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
$this->config
->expects($this->once())
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);
$this->appConfig
->expects($this->once())
->method('getValueBool')
->with('settings', 'display_documentation_link', true)
->willReturn(false);
$this->navigationManager
->expects($this->once())
->method('setActiveEntry')
->with('core_apps');

// When display_documentation_link is false, linkToDocs should not be called
$this->urlGenerator
->expects($this->never())
->method('linkToDocs');

$providedStates = [];
$this->initialState
->expects($this->exactly(4))
->method('provideInitialState')
->willReturnCallback(function ($key, $value) use (&$providedStates) {
$providedStates[$key] = $value;
});

$this->appSettingsController->viewApps();

// Assert that the developer docs state was provided with an empty string
$this->assertArrayHasKey('appstoreDeveloperDocs', $providedStates);
$this->assertEquals('', $providedStates['appstoreDeveloperDocs']);
}

public function testDeveloperDocumentationLinkShownByDefault(): void {
$this->installer->expects($this->any())
->method('isUpdateAvailable')
->willReturn(false);
$this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
$this->config
->expects($this->once())
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);
$this->appConfig
->expects($this->once())
->method('getValueBool')
->with('settings', 'display_documentation_link', true)
->willReturn(true);
$this->navigationManager
->expects($this->once())
->method('setActiveEntry')
->with('core_apps');

$developerDocsUrl = 'https://docs.nextcloud.com/server/latest/developer_manual/';

// When display_documentation_link is true (default), linkToDocs should be called
$this->urlGenerator
->expects($this->once())
->method('linkToDocs')
->with('developer-manual')
->willReturn($developerDocsUrl);

$providedStates = [];
$this->initialState
->expects($this->exactly(4))
->method('provideInitialState')
->willReturnCallback(function ($key, $value) use (&$providedStates) {
$providedStates[$key] = $value;
});

$this->appSettingsController->viewApps();

// Assert that the developer docs state was provided with the correct URL
$this->assertArrayHasKey('appstoreDeveloperDocs', $providedStates);
$this->assertEquals($developerDocsUrl, $providedStates['appstoreDeveloperDocs']);
}
}
Loading