Skip to content

Commit

Permalink
feat(max-duration): Add setupcheck for misconfiguration
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 14, 2024
1 parent e2b7597 commit 4e0286f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
use OCA\Talk\Settings\BeforePreferenceSetEventListener;
use OCA\Talk\Settings\Personal;
use OCA\Talk\SetupCheck\BackgroundBlurLoading;
use OCA\Talk\SetupCheck\Configuration;
use OCA\Talk\SetupCheck\FederationLockCache;
use OCA\Talk\SetupCheck\HighPerformanceBackend;
use OCA\Talk\SetupCheck\RecordingBackend;
Expand Down Expand Up @@ -341,6 +342,7 @@ public function register(IRegistrationContext $context): void {

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

$context->registerSetupCheck(Configuration::class);
$context->registerSetupCheck(HighPerformanceBackend::class);
$context->registerSetupCheck(FederationLockCache::class);
$context->registerSetupCheck(RecordingBackend::class);
Expand Down
55 changes: 55 additions & 0 deletions lib/SetupCheck/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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 OCP\AppFramework\Services\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

/**
* Check app configs and their dependencies
*/
class Configuration implements ISetupCheck {
public function __construct(
protected IL10N $l10n,
protected IConfig $config,
protected IAppConfig $appConfig,
) {
}

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

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

public function run(): SetupResult {
$errors = $warnings = [];
$maxCallDuration = $this->appConfig->getAppValueInt('max_call_duration');
if ($maxCallDuration > 0) {
if ($this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax') !== 'cron') {
$errors[] = $this->l10n->t('Forcing a call duration is only supported with system cron. Please enable system cron or remove the `max_call_duration` configuration.');
} elseif ($maxCallDuration < 3600) {
$warnings[] = $this->l10n->t('Small `max_call_duration` values (currently set to %d) are not enforceable due to technical limitations. The background job is only executed every 5 minutes, so use at own risk.', [$maxCallDuration]);
}
}

if (!empty($errors)) {
return SetupResult::error(implode("\n", $errors));
}
if (!empty($warnings)) {
return SetupResult::warning(implode("\n", $warnings));
}
return SetupResult::success();
}
}

0 comments on commit 4e0286f

Please sign in to comment.