Skip to content
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
46 changes: 46 additions & 0 deletions lib/AppConfigOverwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,50 @@ public function getValue($app, $key, $default = '') {

return parent::getValue($app, $key, $default);
}

#[\Override]
public function getValueString(string $app, string $key, string $default = '', bool $lazy = false): string {
if (isset($this->overWrite[$app]) && isset($this->overWrite[$app][$key])) {
return $this->overWrite[$app][$key];
}

return parent::getValueString($app, $key, $default, $lazy);
}

#[\Override]
public function getValueBool(string $app, string $key, bool $default = false, bool $lazy = false): bool {
if (isset($this->overWrite[$app]) && isset($this->overWrite[$app][$key])) {
return in_array(strtolower($this->overWrite[$app][$key]), ['1', 'true', 'yes', 'on'], true);
}

return parent::getValueBool($app, $key, $default, $lazy);
}

#[\Override]
public function getValueInt(string $app, string $key, int $default = 0, bool $lazy = false): int {
if (isset($this->overWrite[$app]) && isset($this->overWrite[$app][$key])) {
return (int)$this->overWrite[$app][$key];
}

return parent::getValueInt($app, $key, $default, $lazy);
}

#[\Override]
public function getValueFloat(string $app, string $key, float $default = 0, bool $lazy = false): float {
if (isset($this->overWrite[$app]) && isset($this->overWrite[$app][$key])) {
return (float)$this->overWrite[$app][$key];
}

return parent::getValueFloat($app, $key, $default, $lazy);
}

#[\Override]
public function getValueArray(string $app, string $key, array $default = [], bool $lazy = false): array {
if (isset($this->overWrite[$app]) && isset($this->overWrite[$app][$key])) {
$value = json_decode($this->overWrite[$app][$key], true);
return is_array($value) ? $value : $default;
}

return parent::getValueArray($app, $key, $default, $lazy);
}
}
15 changes: 15 additions & 0 deletions tests/stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ public function __construct(
*/
public function getValue($app, $key, $default = '') {
}

public function getValueString(string $app, string $key, string $default = '', bool $lazy = false): string {
}

public function getValueBool(string $app, string $key, bool $default = false, bool $lazy = false): bool {
}

public function getValueInt(string $app, string $key, int $default = 0, bool $lazy = false): int {
}

public function getValueFloat(string $app, string $key, float $default = 0, bool $lazy = false): float {
}

public function getValueArray(string $app, string $key, array $default = [], bool $lazy = false): array {
}
}
}

Expand Down
55 changes: 55 additions & 0 deletions tests/unit/AppConfigOverwriteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

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

namespace OCA\Guests\Test\Unit;

use OCA\Guests\AppConfigOverwrite;
use OCP\Server;
use Test\TestCase;

/**
* @group DB
*/
class AppConfigOverwriteTest extends TestCase {
private const KEY = 'shareapi_only_share_with_group_members';

private ?AppConfigOverwrite $appConfig = null;

protected function setUp(): void {
parent::setUp();

$this->appConfig = Server::get(AppConfigOverwrite::class);
$this->appConfig->setOverwrite(['core' => [self::KEY => 'yes']]);
}

protected function tearDown(): void {
$this->appConfig->setOverwrite([]);

parent::tearDown();
}

/**
* The server reads the overwritten values through several getters:
* IConfig::getAppValue() ends up in getValue(), the share recipient
* autocompletion uses getValueString() and OCA\Guests\Config uses
* getValueBool(). All of them have to see the overwrite.
*/
public function testOverwriteIsAppliedToAllGetters(): void {
$this->assertSame('yes', $this->appConfig->getValue('core', self::KEY, 'no'));
$this->assertSame('yes', $this->appConfig->getValueString('core', self::KEY, 'no'));
$this->assertTrue($this->appConfig->getValueBool('core', self::KEY));
}

public function testWithoutOverwriteTheStoredValueIsUsed(): void {
$this->appConfig->setOverwrite([]);

$this->assertSame('no', $this->appConfig->getValue('core', self::KEY, 'no'));
$this->assertSame('no', $this->appConfig->getValueString('core', self::KEY, 'no'));
$this->assertFalse($this->appConfig->getValueBool('core', self::KEY));
}
}
Loading