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
4 changes: 3 additions & 1 deletion lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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';
}

Expand Down
38 changes: 25 additions & 13 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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)),
Expand Down
6 changes: 3 additions & 3 deletions lib/SetupCheck/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
) {
}

Expand All @@ -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]);
Expand Down
3 changes: 0 additions & 3 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
<directory name="lib"/>
</errorLevel>
<errorLevel type="suppress">
<referencedMethod name="OCP\IConfig::getAppValue"/>
<referencedMethod name="OCP\IConfig::setAppValue"/>
<referencedMethod name="OCP\IConfig::deleteAppValue"/>
<referencedMethod name="OCP\IConfig::getUserValue"/>
<referencedMethod name="OCP\IConfig::setUserValue"/>
<referencedMethod name="OCP\IConfig::getUserValueForUsers"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand All @@ -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']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,7 @@ class SummaryService {

public function __construct(
protected IConfig $config,
protected IServerAppConfig $serverAppConfig,
protected LogEntryMapper $logEntryMapper,
protected ITimeFactory $timeFactory,
protected IDateTimeFormatter $dateTimeFormatter,
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions tests/php/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -80,6 +83,7 @@ protected function getCapabilities(): Capabilities {
$this->serverConfig,
$this->talkConfig,
$this->appConfig,
$this->serverAppConfig,
$this->commentsManager,
$this->userSession,
$this->appManager,
Expand Down Expand Up @@ -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'],
]);
Expand Down Expand Up @@ -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'],
]);
Expand Down
Loading