Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
WIP: add helper method for settings to provide initial state
Signed-off-by: Andrey Borysenko <[email protected]>
  • Loading branch information
andrey18106 committed Oct 17, 2024
commit dfc468ce4a0ca9f58183ed658b984d8b9f0792ab
51 changes: 14 additions & 37 deletions lib/Controller/ExAppsPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,22 @@
* ExApps actions controller similar to default one with project-specific changes and additions
*/
class ExAppsPageController extends Controller {
private IInitialState $initialStateService;
private IConfig $config;
private AppAPIService $service;
private DaemonConfigService $daemonConfigService;
private DockerActions $dockerActions;
private CategoryFetcher $categoryFetcher;
private IFactory $l10nFactory;
private ExAppFetcher $exAppFetcher;
private IL10N $l10n;
private LoggerInterface $logger;
private IAppManager $appManager;

public function __construct(
IRequest $request,
IConfig $config,
IInitialState $initialStateService,
AppAPIService $service,
DaemonConfigService $daemonConfigService,
DockerActions $dockerActions,
CategoryFetcher $categoryFetcher,
IFactory $l10nFactory,
ExAppFetcher $exAppFetcher,
IL10N $l10n,
LoggerInterface $logger,
IAppManager $appManager,
private readonly IConfig $config,
private readonly AppAPIService $service,
private readonly DaemonConfigService $daemonConfigService,
private readonly DockerActions $dockerActions,
private readonly CategoryFetcher $categoryFetcher,
private readonly IFactory $l10nFactory,
private readonly ExAppFetcher $exAppFetcher,
private readonly IL10N $l10n,
private readonly LoggerInterface $logger,
private readonly IAppManager $appManager,
private readonly ExAppService $exAppService,
) {
parent::__construct(Application::APP_ID, $request);

$this->initialStateService = $initialStateService;
$this->config = $config;
$this->service = $service;
$this->daemonConfigService = $daemonConfigService;
$this->dockerActions = $dockerActions;
$this->categoryFetcher = $categoryFetcher;
$this->l10nFactory = $l10nFactory;
$this->l10n = $l10n;
$this->exAppFetcher = $exAppFetcher;
$this->logger = $logger;
$this->appManager = $appManager;
}

/**
Expand Down Expand Up @@ -228,7 +204,7 @@ public function listApps(): JSONResponse {
}))[0]['releases'][0]['version'];
}

$appData['canUnInstall'] = !$appData['active'] && $appData['removable']
$appData['canUninstall'] = !$appData['active'] && $appData['removable']
&& (isset($appData['status']['action']) && $appData['status']['action'] !== 'deploy')
|| (isset($appData['status']['action']) && $appData['status']['action'] === 'init')
|| !empty($appData['status']['error']);
Expand Down Expand Up @@ -286,9 +262,10 @@ private function buildLocalAppsList(array $apps, array $exApps): array {
'appstore' => false,
'installed' => true,
'name' => $exApp->getName(),
'description' => '',
'description' => $this->l10n->t('This app is not installed from the AppStore. No extra information available. Only enable/disable and remove actions are allowed.'),
'summary' => '',
'license' => '',
'licence' => '',
'author' => '',
'shipped' => false,
'version' => $exApp->getVersion(),
Expand All @@ -306,7 +283,7 @@ private function buildLocalAppsList(array $apps, array $exApps): array {
'missingMaxOwnCloudVersion' => false,
'missingMinOwnCloudVersion' => false,
'canInstall' => true, // to allow "remove" command for manual-install
'canUnInstall' => !($exApp->getEnabled() === 1),
'canUninstall' => !($exApp->getEnabled() === 1),
'isCompatible' => true,
'screenshot' => '',
'score' => 0,
Expand Down
58 changes: 58 additions & 0 deletions lib/Service/ExAppsPageService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace OCA\AppAPI\Service;

use OCA\AppAPI\DeployActions\DockerActions;
use OCA\AppAPI\Fetcher\ExAppFetcher;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use Psr\Log\LoggerInterface;

class ExAppsPageService {

public function __construct(
private readonly ExAppFetcher $exAppFetcher,
private readonly DaemonConfigService $daemonConfigService,
private readonly DockerActions $dockerActions,
private readonly IConfig $config,
private readonly IAppManager $appManager,
private readonly LoggerInterface $logger,
) {
}

/**
* Helper method for settings app to provide initial state for Apps management UI
*
* @since 30.0.2
*/
public function provideAppApiState(IInitialState $initialState): void {
$appApiEnabled = $this->appManager->isInstalled('app_api');
$initialState->provideInitialState('appApiEnabled', $appApiEnabled);
$daemonConfigAccessible = false;
$defaultDaemonConfig = null;

if ($appApiEnabled) {
$initialState->provideInitialState('appstoreExAppUpdateCount', count($this->exAppFetcher->getExAppsWithUpdates()));

$defaultDaemonConfigName = $this->config->getAppValue('app_api', 'default_daemon_config');
if ($defaultDaemonConfigName !== '') {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($defaultDaemonConfigName);
if ($daemonConfig !== null) {
$defaultDaemonConfig = $daemonConfig->jsonSerialize();
unset($defaultDaemonConfig['deploy_config']['haproxy_password']);
$this->dockerActions->initGuzzleClient($daemonConfig);
$daemonConfigAccessible = $this->dockerActions->ping($this->dockerActions->buildDockerUrl($daemonConfig));
if (!$daemonConfigAccessible) {
$this->logger->warning(sprintf('Deploy daemon "%s" is not accessible by Nextcloud. Please verify its configuration', $daemonConfig->getName()));
}
}
}
}

$initialState->provideInitialState('defaultDaemonConfigAccessible', $daemonConfigAccessible);
$initialState->provideInitialState('defaultDaemonConfig', $defaultDaemonConfig);
}
}
3 changes: 1 addition & 2 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@
<file src="lib/Controller/ExAppsPageController.php">
<UndefinedClass>
<code><![CDATA[$this->categoryFetcher]]></code>
<code><![CDATA[CategoryFetcher]]></code>
<code><![CDATA[CategoryFetcher]]></code>
<code><![CDATA[DependencyAnalyzer]]></code>
<code><![CDATA[OC_App]]></code>
<code><![CDATA[Platform]]></code>
<code><![CDATA[VersionParser]]></code>
<code><![CDATA[private]]></code>
</UndefinedClass>
</file>
<file src="lib/Fetcher/AppAPIFetcher.php">
Expand Down