From d6a463aa768a38905ca03c2dee5087aa26121917 Mon Sep 17 00:00:00 2001 From: Christian Lorang Date: Thu, 29 Oct 2026 10:51:56 +0100 Subject: [PATCH 1/2] chore(config): move access to other app configs to proper non deprecated methods Signed-off-by: Christian Lorang --- lib/Capabilities.php | 4 +++- lib/Controller/RoomController.php | 38 ++++++++++++++++++++----------- lib/SetupCheck/Configuration.php | 6 ++--- psalm.xml | 3 --- tests/php/CapabilitiesTest.php | 12 ++++++---- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/lib/Capabilities.php b/lib/Capabilities.php index 7229ead1969..9ddfd6c59a4 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -16,6 +16,7 @@ use OCP\AppFramework\Services\IAppConfig; use OCP\Capabilities\IPublicCapability; use OCP\Comments\ICommentsManager; +use OCP\IAppConfig as IServerAppConfig; use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; @@ -251,6 +252,7 @@ public function __construct( private readonly IConfig $serverConfig, private readonly Config $talkConfig, private readonly IAppConfig $appConfig, + private readonly IServerAppConfig $serverAppConfig, private readonly ICommentsManager $commentsManager, private readonly IUserSession $userSession, private readonly IAppManager $appManager, @@ -365,7 +367,7 @@ public function getCapabilities(): array { 'version' => $this->appManager->getAppVersion('spreed'), ]; - if ($this->serverConfig->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron') { + if ($this->serverAppConfig->getValueString('core', 'backgroundjobs_mode', 'ajax') === 'cron') { $capabilities['features'][] = 'message-expiration'; } diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index fd9fdc15950..5d825c1943c 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -108,10 +108,13 @@ use OCP\Calendar\ICreateFromString; use OCP\Calendar\IManager as ICalendarManager; use OCP\Comments\IComment; +use OCP\Config\IUserConfig; +use OCP\Config\ValueType; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudId; use OCP\Federation\ICloudIdManager; use OCP\Http\Client\IClientService; +use OCP\IAppConfig as IServerAppConfig; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; @@ -166,6 +169,8 @@ public function __construct( private readonly IConfig $config, private readonly ConfigLexicon $configLexicon, private readonly IAppConfig $appConfig, + private readonly IServerAppConfig $serverAppConfig, + private readonly IUserConfig $userConfig, private readonly Config $talkConfig, private readonly ICloudIdManager $cloudIdManager, private readonly IPhoneNumberUtil $phoneNumberUtil, @@ -192,26 +197,33 @@ public function __construct( * @return array{X-Nextcloud-Talk-Hash: string} */ protected function getTalkHashHeader(): array { - $values = [ - $this->config->getSystemValueString('version'), - $this->appConfig->getAppValueString('installed_version'), - $this->config->getAppValue('theming', 'cachebuster', '1'), - $this->config->getUserValue($this->userId, 'theming', 'userCacheBuster', '0'), - ]; - foreach ($this->configLexicon->getTalkAppConfigs() as $config) { - $key = $config->entry->getKey(); - if ($config->hash && $key !== Config::EXPERIMENTS_USERS && $key !== Config::EXPERIMENTS_GUESTS) { - $values[] = $this->config->getAppValue('spreed', $key); - } - } + $values = []; if ($this->userId !== null) { $values[] = $this->appConfig->getAppValueInt(Config::EXPERIMENTS_USERS); - $values[] = $this->config->getUserValue($this->userId, 'spreed', UserPreference::ATTACHMENT_FOLDER); + $values[] = $this->userConfig->getValueString($this->userId, 'spreed', UserPreference::ATTACHMENT_FOLDER); + $values[] = $this->userConfig->getValueString($this->userId, 'theming', 'userCacheBuster', '0'); } else { $values[] = $this->appConfig->getAppValueInt(Config::EXPERIMENTS_GUESTS); } + $values[] = $this->config->getSystemValueString('version'); + $values[] = $this->appConfig->getAppValueString('installed_version'); + $values[] = $this->serverAppConfig->getValueString('theming', 'cachebuster', '1'); + + foreach ($this->configLexicon->getTalkAppConfigs() as $config) { + $key = $config->entry->getKey(); + if ($config->hash && $key !== Config::EXPERIMENTS_USERS && $key !== Config::EXPERIMENTS_GUESTS) { + $values[] = match ($config->entry->getValueType()) { + ValueType::STRING => $this->appConfig->getAppValueString($key), + ValueType::INT => $this->appConfig->getAppValueInt($key), + ValueType::BOOL => $this->appConfig->getAppValueBool($key) ? '1' : '0', + ValueType::FLOAT => $this->appConfig->getAppValueFloat($key), + ValueType::ARRAY => json_encode($this->appConfig->getAppValueArray($key)), + default => json_encode($this->appConfig->getAppValueString($key)) // mixed and future types + }; + } + } return [ 'X-Nextcloud-Talk-Hash' => sha1(implode('#', $values)), diff --git a/lib/SetupCheck/Configuration.php b/lib/SetupCheck/Configuration.php index c07ae449ce4..3a89fa87bc4 100644 --- a/lib/SetupCheck/Configuration.php +++ b/lib/SetupCheck/Configuration.php @@ -11,7 +11,7 @@ use OCA\Talk\Config; use OCP\AppFramework\Services\IAppConfig; -use OCP\IConfig; +use OCP\IAppConfig as IServerAppConfig; use OCP\IL10N; use OCP\SetupCheck\ISetupCheck; use OCP\SetupCheck\SetupResult; @@ -22,8 +22,8 @@ class Configuration implements ISetupCheck { public function __construct( private readonly IL10N $l10n, - private readonly IConfig $config, private readonly IAppConfig $appConfig, + private readonly IServerAppConfig $serverAppConfig, ) { } @@ -42,7 +42,7 @@ public function run(): SetupResult { $errors = $warnings = []; $maxCallDuration = $this->appConfig->getAppValueInt(Config::MAX_CALL_DURATION); if ($maxCallDuration > 0) { - if ($this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax') !== 'cron') { + if ($this->serverAppConfig->getValueString('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]); diff --git a/psalm.xml b/psalm.xml index 76d77fa802a..e29e7ed9949 100644 --- a/psalm.xml +++ b/psalm.xml @@ -35,9 +35,6 @@ - - - diff --git a/tests/php/CapabilitiesTest.php b/tests/php/CapabilitiesTest.php index fcb67b9bc70..956df180827 100644 --- a/tests/php/CapabilitiesTest.php +++ b/tests/php/CapabilitiesTest.php @@ -17,6 +17,7 @@ use OCP\App\IAppManager; use OCP\AppFramework\Services\IAppConfig; use OCP\Capabilities\IPublicCapability; +use OCP\IAppConfig as IServerAppConfig; use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; @@ -36,6 +37,7 @@ class CapabilitiesTest extends TestCase { protected IConfig&MockObject $serverConfig; protected Config&MockObject $talkConfig; protected IAppConfig&MockObject $appConfig; + protected IServerAppConfig&MockObject $serverAppConfig; protected CommentsManager&MockObject $commentsManager; protected IUserSession&MockObject $userSession; protected IAppManager&MockObject $appManager; @@ -51,6 +53,7 @@ public function setUp(): void { $this->serverConfig = $this->createMock(IConfig::class); $this->talkConfig = $this->createMock(Config::class); $this->appConfig = $this->createMock(IAppConfig::class); + $this->serverAppConfig = $this->createMock(IServerAppConfig::class); $this->commentsManager = $this->createMock(CommentsManager::class); $this->userSession = $this->createMock(IUserSession::class); $this->appManager = $this->createMock(IAppManager::class); @@ -80,6 +83,7 @@ protected function getCapabilities(): Capabilities { $this->serverConfig, $this->talkConfig, $this->appConfig, + $this->serverAppConfig, $this->commentsManager, $this->userSession, $this->appManager, @@ -142,8 +146,8 @@ public function testGetCapabilitiesGuest(): void { ->with(null) ->willReturn(''); - $this->serverConfig->expects($this->any()) - ->method('getAppValue') + $this->serverAppConfig->expects($this->any()) + ->method('getValueString') ->willReturnMap([ ['core', 'backgroundjobs_mode', 'ajax', 'cron'], ]); @@ -383,8 +387,8 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea $this->taskProcessingManager->method('getAvailableTaskTypeIds') ->willReturn([TextToTextSummary::ID]); - $this->serverConfig->expects($this->any()) - ->method('getAppValue') + $this->serverAppConfig->expects($this->any()) + ->method('getValueString') ->willReturnMap([ ['core', 'backgroundjobs_mode', 'ajax', 'cron'], ]); From b35d19746b62723e8f92bafe97cbab0c0bca4712 Mon Sep 17 00:00:00 2001 From: Christian Lorang Date: Fri, 30 Oct 2026 14:48:24 +0100 Subject: [PATCH 2/2] chore: refactor get/setAppValue to non deprecated methods in talk_webhook_demo Signed-off-by: Christian Lorang --- .../talk_webhook_demo/lib/Controller/BotController.php | 6 +++--- .../talk_webhook_demo/lib/Migration/UninstallBot.php | 6 +++--- .../talk_webhook_demo/lib/Service/BotService.php | 8 ++++---- .../talk_webhook_demo/lib/Service/SummaryService.php | 6 ++++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/integration/talk_webhook_demo/lib/Controller/BotController.php b/tests/integration/talk_webhook_demo/lib/Controller/BotController.php index f7934682c60..e770679636e 100644 --- a/tests/integration/talk_webhook_demo/lib/Controller/BotController.php +++ b/tests/integration/talk_webhook_demo/lib/Controller/BotController.php @@ -18,10 +18,10 @@ use OCP\AppFramework\Http\Attribute\PublicPage; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; +use OCP\AppFramework\Services\IAppConfig as IServerAppConfig; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Http\Client\IClientService; use OCP\ICertificateManager; -use OCP\IConfig; use OCP\IRequest; use OCP\L10N\IFactory; use Psr\Log\LoggerInterface; @@ -38,7 +38,7 @@ public function __construct( protected IFactory $l10nFactory, protected LogEntryMapper $logEntryMapper, protected SummaryService $summaryService, - protected IConfig $config, + protected IServerAppConfig $serverAppConfig, protected LoggerInterface $logger, protected ICertificateManager $certificateManager, ) { @@ -66,7 +66,7 @@ public function receiveWebhook(string $lang): DataResponse { $random = $this->request->getHeader('X_NEXTCLOUD_TALK_RANDOM'); $server = rtrim($this->request->getHeader('X_NEXTCLOUD_TALK_BACKEND'), '/') . '/'; - $secretData = $this->config->getAppValue('talk_webhook_demo', 'secret_' . sha1($server)); + $secretData = $this->serverAppConfig->getAppValueString('talk_webhook_demo', 'secret_' . sha1($server)); if ($secretData === '') { $this->logger->warning('No matching secret found for server: ' . $server); $response = new DataResponse([], Http::STATUS_UNAUTHORIZED); diff --git a/tests/integration/talk_webhook_demo/lib/Migration/UninstallBot.php b/tests/integration/talk_webhook_demo/lib/Migration/UninstallBot.php index db4f01fbe29..9d1621ba07c 100644 --- a/tests/integration/talk_webhook_demo/lib/Migration/UninstallBot.php +++ b/tests/integration/talk_webhook_demo/lib/Migration/UninstallBot.php @@ -11,14 +11,14 @@ use OCA\Talk\Events\BotUninstallEvent; use OCA\TalkWebhookDemo\Service\BotService; -use OCP\IConfig; +use OCP\AppFramework\Services\IAppConfig as IServerAppConfig; use OCP\IURLGenerator; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; class UninstallBot implements IRepairStep { public function __construct( - protected IConfig $config, + protected IServerAppConfig $serverAppConfig, protected IURLGenerator $url, protected BotService $service, ) { @@ -37,7 +37,7 @@ public function run(IOutput $output): void { $backend = $this->url->getAbsoluteURL(''); $id = sha1($backend); - $secretData = $this->config->getAppValue('talk_webhook_demo', 'secret_' . $id); + $secretData = $this->serverAppConfig->getAppValueString('talk_webhook_demo', 'secret_' . $id); if ($secretData) { $secretArray = json_decode($secretData, true, 512, JSON_THROW_ON_ERROR); if ($secretArray['secret']) { diff --git a/tests/integration/talk_webhook_demo/lib/Service/BotService.php b/tests/integration/talk_webhook_demo/lib/Service/BotService.php index c4cef05cd42..40d5015562d 100644 --- a/tests/integration/talk_webhook_demo/lib/Service/BotService.php +++ b/tests/integration/talk_webhook_demo/lib/Service/BotService.php @@ -11,15 +11,15 @@ use OCA\Talk\Events\BotInstallEvent; use OCA\Talk\Events\BotUninstallEvent; use OCA\TalkWebhookDemo\Model\Bot; +use OCP\AppFramework\Services\IAppConfig as IServerAppConfig; use OCP\EventDispatcher\IEventDispatcher; -use OCP\IConfig; use OCP\IURLGenerator; use OCP\L10N\IFactory; use OCP\Security\ISecureRandom; class BotService { public function __construct( - protected IConfig $config, + protected IServerAppConfig $serverAppConfig, protected IURLGenerator $url, protected IEventDispatcher $dispatcher, protected IFactory $l10nFactory, @@ -30,7 +30,7 @@ public function __construct( public function installBot(string $backend): void { $id = sha1($backend); - $secretData = $this->config->getAppValue('talk_webhook_demo', 'secret_' . $id); + $secretData = $this->serverAppConfig->getAppValueString('talk_webhook_demo', 'secret' . $id); if ($secretData) { $secretArray = json_decode($secretData, true, 512, JSON_THROW_ON_ERROR); $secret = $secretArray['secret'] ?? $this->random->generate(64, ISecureRandom::CHAR_HUMAN_READABLE); @@ -41,7 +41,7 @@ public function installBot(string $backend): void { $this->installLanguage($secret, $lang); } - $this->config->setAppValue('talk_webhook_demo', 'secret_' . $id, json_encode([ + $this->serverAppConfig->setAppValueString('talk_webhook_demo', 'secret_' . $id, json_encode([ 'id' => $id, 'secret' => $secret, 'backend' => $backend, diff --git a/tests/integration/talk_webhook_demo/lib/Service/SummaryService.php b/tests/integration/talk_webhook_demo/lib/Service/SummaryService.php index 4d5b970ef8f..650db768131 100644 --- a/tests/integration/talk_webhook_demo/lib/Service/SummaryService.php +++ b/tests/integration/talk_webhook_demo/lib/Service/SummaryService.php @@ -11,6 +11,7 @@ use OCA\TalkWebhookDemo\Model\LogEntry; use OCA\TalkWebhookDemo\Model\LogEntryMapper; +use OCP\AppFramework\Services\IAppConfig as IServerAppConfig; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IConfig; use OCP\IDateTimeFormatter; @@ -32,6 +33,7 @@ class SummaryService { public function __construct( protected IConfig $config, + protected IServerAppConfig $serverAppConfig, protected LogEntryMapper $logEntryMapper, protected ITimeFactory $timeFactory, protected IDateTimeFormatter $dateTimeFormatter, @@ -196,7 +198,7 @@ public function summarize(string $server, string $token, string $roomName, strin } } - if (($endTimestamp - $startTimestamp) < (int)$this->config->getAppValue('talk_webhook_demo', 'min-length', '60')) { + if (($endTimestamp - $startTimestamp) < $this->serverAppConfig->getAppValueInt('talk_webhook_demo', 'min-length', 60)) { // No call summary for short calls return null; } @@ -205,7 +207,7 @@ public function summarize(string $server, string $token, string $roomName, strin sort($attendees); $systemDefault = $this->config->getSystemValueString('default_timezone', 'UTC'); - $timezoneString = $this->config->getAppValue('talk_webhook_demo', 'timezone', $systemDefault); + $timezoneString = $this->serverAppConfig->getAppValueString('talk_webhook_demo', 'timezone', $systemDefault); $timezone = null; if ($timezoneString !== 'UTC') { try {