Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] fix(setupchecks): Add setup checks for current checks #13260

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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
11 changes: 11 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
use OCA\Talk\Search\UnifiedSearchCSSLoader;
use OCA\Talk\Search\UnifiedSearchFilterPlugin;
use OCA\Talk\Settings\Personal;
use OCA\Talk\SetupCheck\BackgroundBlurLoading;
use OCA\Talk\SetupCheck\FederationLockCache;
use OCA\Talk\SetupCheck\RecommendCache;
use OCA\Talk\SetupCheck\RecordingBackend;
use OCA\Talk\SetupCheck\SIPConfiguration;
use OCA\Talk\Share\Listener as ShareListener;
use OCA\Talk\Signaling\Listener as SignalingListener;
use OCA\Talk\Status\Listener as StatusListener;
Expand Down Expand Up @@ -332,6 +337,12 @@ public function register(IRegistrationContext $context): void {
$context->registerTalkBackend(TalkBackend::class);

$context->registerTeamResourceProvider(TalkTeamResourceProvider::class);

$context->registerSetupCheck(RecommendCache::class);
$context->registerSetupCheck(FederationLockCache::class);
$context->registerSetupCheck(RecordingBackend::class);
$context->registerSetupCheck(SIPConfiguration::class);
$context->registerSetupCheck(BackgroundBlurLoading::class);
}

public function boot(IBootContext $context): void {
Expand Down
66 changes: 66 additions & 0 deletions lib/SetupCheck/BackgroundBlurLoading.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\SetupCheck;

use OCA\Settings\SetupChecks\CheckServerResponseTrait;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;
use Psr\Log\LoggerInterface;

/**
* Check whether the WASM URLs works
*/
class BackgroundBlurLoading implements ISetupCheck {
use CheckServerResponseTrait;

public function __construct(
protected IL10N $l10n,
protected IConfig $config,
protected IURLGenerator $urlGenerator,
protected IClientService $clientService,
protected LoggerInterface $logger,
) {
}

public function getCategory(): string {
return 'talk';
}

public function getName(): string {
return $this->l10n->t('Background blur');
}

public function run(): SetupResult {
$url = $this->urlGenerator->linkTo('spreed', 'js/tflite.wasm');
$noResponse = true;
$responses = $this->runHEAD($url);
foreach ($responses as $response) {
$noResponse = false;
if ($response->getStatusCode() === 200) {
return SetupResult::success();
}
}

if ($noResponse) {
return SetupResult::info(
$this->l10n->t('Could not check for WASM loading support. Please check manually if your web server serves `.wasm` files.') . "\n" . $this->serverConfigHelp(),
$this->urlGenerator->linkToDocs('admin-nginx'),
);
}
return SetupResult::warning(
$this->l10n->t('Your web server is not properly set up to deliver `.wasm` files. This is typically an issue with the Nginx configuration. For background blur it needs an adjustment to also deliver `.wasm` files. Compare your Nginx configuration to the recommended configuration in our documentation.'),
$this->urlGenerator->linkToDocs('admin-nginx'),
);

}
}
48 changes: 48 additions & 0 deletions lib/SetupCheck/FederationLockCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\SetupCheck;

use OC\Memcache\NullCache;
use OCA\Talk\Config;
use OCP\ICacheFactory;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class FederationLockCache implements ISetupCheck {
public function __construct(
readonly protected Config $talkConfig,
readonly protected ICacheFactory $cacheFactory,
readonly protected IURLGenerator $urlGenerator,
readonly protected IL10N $l,
) {
}

public function getCategory(): string {
return 'talk';
}

public function getName(): string {
return $this->l->t('Federation');
}

public function run(): SetupResult {
if (!$this->talkConfig->isFederationEnabled()) {
return SetupResult::success();
}
if (!$this->cacheFactory->createLocking('talkroom_') instanceof NullCache) {
return SetupResult::success();
}
return SetupResult::warning(
$this->l->t('It is highly recommended to configure "memcache.locking" when Talk Federation is enabled.'),
$this->urlGenerator->linkToDocs('admin-cache'),
);
}
}
47 changes: 47 additions & 0 deletions lib/SetupCheck/RecommendCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\SetupCheck;

use OCA\Talk\Config;
use OCP\ICacheFactory;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class RecommendCache implements ISetupCheck {
public function __construct(
readonly protected Config $talkConfig,
readonly protected ICacheFactory $cacheFactory,
readonly protected IURLGenerator $urlGenerator,
readonly protected IL10N $l,
) {
}

public function getCategory(): string {
return 'talk';
}

public function getName(): string {
return $this->l->t('High-performance backend');
}

public function run(): SetupResult {
if ($this->talkConfig->getSignalingMode() === Config::SIGNALING_INTERNAL) {
return SetupResult::success();
}
if ($this->cacheFactory->isAvailable()) {
return SetupResult::success();
}
return SetupResult::warning(
$this->l->t('It is highly recommended to configure a memory cache when running Nextcloud Talk with a High-performance backend.'),
$this->urlGenerator->linkToDocs('admin-cache'),
);
}
}
40 changes: 40 additions & 0 deletions lib/SetupCheck/RecordingBackend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\SetupCheck;

use OCA\Talk\Config;
use OCP\IL10N;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class RecordingBackend implements ISetupCheck {
public function __construct(
readonly protected Config $talkConfig,
readonly protected IL10N $l,
) {
}

public function getCategory(): string {
return 'talk';
}

public function getName(): string {
return $this->l->t('Recording backend');
}

public function run(): SetupResult {
if ($this->talkConfig->getSignalingMode() !== Config::SIGNALING_INTERNAL) {
return SetupResult::success();
}
if (empty($this->talkConfig->getRecordingServers())) {
return SetupResult::success();
}
return SetupResult::error($this->l->t('Using the recording backend requires a High-performance backend.'));
}
}
40 changes: 40 additions & 0 deletions lib/SetupCheck/SIPConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\SetupCheck;

use OCA\Talk\Config;
use OCP\IL10N;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class SIPConfiguration implements ISetupCheck {
public function __construct(
readonly protected Config $talkConfig,
readonly protected IL10N $l,
) {
}

public function getCategory(): string {
return 'talk';
}

public function getName(): string {
return $this->l->t('SIP dial-in');
}

public function run(): SetupResult {
if ($this->talkConfig->getSignalingMode() !== Config::SIGNALING_INTERNAL) {
return SetupResult::success();
}
if ($this->talkConfig->getSIPSharedSecret() === '' && $this->talkConfig->getDialInInfo() === '') {
return SetupResult::success();
}
return SetupResult::error($this->l->t('Using the SIP functionality requires a High-performance backend.'));
}
}
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<file name="tests/stubs/oc_core_command_base.php" />
<file name="tests/stubs/oc_hooks_emitter.php" />
<file name="tests/stubs/oc_http_client_response.php" />
<file name="tests/stubs/oc_memcache.php" />
<file name="tests/stubs/oca_circles.php" />
<file name="tests/stubs/oca_federation_trustedservers.php" />
<file name="tests/stubs/oca_files_events.php" />
Expand Down
10 changes: 5 additions & 5 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
<code><![CDATA[BeforeTemplateRenderedEvent]]></code>
</UndefinedClass>
</file>
<file src="lib/Chat/ChatManager.php">
<UndefinedClass>
<code><![CDATA[NullCache]]></code>
</UndefinedClass>
</file>
<file src="lib/Chat/Parser/SystemMessage.php">
<UndefinedClass>
<code><![CDATA[\OC_Util]]></code>
Expand Down Expand Up @@ -84,6 +79,11 @@
<code><![CDATA[NoUserException]]></code>
</UndefinedClass>
</file>
<file src="lib/SetupCheck/BackgroundBlurLoading.php">
<UndefinedTrait>
<code><![CDATA[CheckServerResponseTrait]]></code>
</UndefinedTrait>
</file>
<file src="lib/Share/Listener.php">
<UndefinedClass>
<code><![CDATA[$event->getView()]]></code>
Expand Down
50 changes: 50 additions & 0 deletions tests/stubs/oc_memcache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Memcache {

use OCP\IMemcache;

class NullCache implements IMemcache {
public function add($key, $value, $ttl = 0) {
}

public function inc($key, $step = 1) {
}

public function dec($key, $step = 1) {
}

public function cas($key, $old, $new) {
}

public function cad($key, $old) {
}

public function ncad(string $key, mixed $old): bool {
}
}

class ArrayCache implements IMemcache {
public function add($key, $value, $ttl = 0) {
}

public function inc($key, $step = 1) {
}

public function dec($key, $step = 1) {
}

public function cas($key, $old, $new) {
}

public function cad($key, $old) {
}

public function ncad(string $key, mixed $old): bool {
}
}
}
24 changes: 24 additions & 0 deletions tests/stubs/oca_settings_setupchecks_checkserverresponsetrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\SetupChecks {
use Generator;

trait CheckServerResponseTrait {
protected function serverConfigHelp(): string {
}
}

trait CheckServerResponseTrait2 {
protected function serverConfigHelp(): string {
}

protected function runHEAD(string $url, bool $ignoreSSL = true, bool $httpErrors = true): Generator {
}

protected function runRequest(string $method, string $url, array $options = []): Generator {
}
}
}
Loading