aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/Command/Config/Preset.php71
-rw-r--r--core/register_command.php2
-rw-r--r--lib/composer/composer/autoload_classmap.php2
-rw-r--r--lib/composer/composer/autoload_static.php2
-rw-r--r--lib/private/AppConfig.php35
-rw-r--r--lib/private/Config/ConfigManager.php17
-rw-r--r--lib/private/Config/UserConfig.php32
-rw-r--r--lib/unstable/Config/Lexicon/ConfigLexiconEntry.php24
-rw-r--r--lib/unstable/Config/Lexicon/Preset.php46
-rw-r--r--tests/lib/AppConfigTest.php4
-rw-r--r--tests/lib/Config/LexiconTest.php25
-rw-r--r--tests/lib/Config/TestConfigLexicon_E.php15
12 files changed, 256 insertions, 19 deletions
diff --git a/core/Command/Config/Preset.php b/core/Command/Config/Preset.php
new file mode 100644
index 00000000000..9f1424dcc54
--- /dev/null
+++ b/core/Command/Config/Preset.php
@@ -0,0 +1,71 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OC\Core\Command\Config;
+
+use NCU\Config\Lexicon\Preset as ConfigLexiconPreset;
+use OC\Config\ConfigManager;
+use OC\Core\Command\Base;
+use OCP\IConfig;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class Preset extends Base {
+ public function __construct(
+ private readonly IConfig $config,
+ private readonly ConfigManager $configManager,
+ ) {
+ parent::__construct();
+ }
+
+ protected function configure() {
+ parent::configure();
+ $this->setName('config:preset')
+ ->setDescription('Select a config preset')
+ ->addArgument('preset', InputArgument::OPTIONAL, 'Preset to use for all unset config values', '')
+ ->addOption('list', '', InputOption::VALUE_NONE, 'display available preset');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int {
+ if ($input->getOption('list')) {
+ $this->getEnum('', $list);
+ $this->writeArrayInOutputFormat($input, $output, $list);
+ return self::SUCCESS;
+ }
+
+ $presetArg = $input->getArgument('preset');
+ if ($presetArg !== '') {
+ $preset = $this->getEnum($presetArg, $list);
+ if ($preset === null) {
+ $output->writeln('<error>Invalid preset: ' . $presetArg . '</error>');
+ $output->writeln('Available presets: ' . implode(', ', $list));
+ return self::INVALID;
+ }
+
+ $this->configManager->setLexiconPreset($preset);
+ }
+
+ $current = ConfigLexiconPreset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? ConfigLexiconPreset::NONE;
+ $this->writeArrayInOutputFormat($input, $output, [$current->name], 'current preset: ');
+ return self::SUCCESS;
+ }
+
+ private function getEnum(string $name, ?array &$list = null): ?ConfigLexiconPreset {
+ $list = [];
+ foreach (ConfigLexiconPreset::cases() as $case) {
+ $list[] = $case->name;
+ if (strtolower($case->name) === strtolower($name)) {
+ return $case;
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/core/register_command.php b/core/register_command.php
index 9a5bf308254..ed64983e762 100644
--- a/core/register_command.php
+++ b/core/register_command.php
@@ -27,6 +27,7 @@ use OC\Core\Command\Config\App\GetConfig;
use OC\Core\Command\Config\App\SetConfig;
use OC\Core\Command\Config\Import;
use OC\Core\Command\Config\ListConfigs;
+use OC\Core\Command\Config\Preset;
use OC\Core\Command\Db\AddMissingColumns;
use OC\Core\Command\Db\AddMissingIndices;
use OC\Core\Command\Db\AddMissingPrimaryKeys;
@@ -149,6 +150,7 @@ if ($config->getSystemValueBool('installed', false)) {
$application->add(Server::get(SetConfig::class));
$application->add(Server::get(Import::class));
$application->add(Server::get(ListConfigs::class));
+ $application->add(Server::get(Preset::class));
$application->add(Server::get(Command\Config\System\DeleteConfig::class));
$application->add(Server::get(Command\Config\System\GetConfig::class));
$application->add(Server::get(Command\Config\System\SetConfig::class));
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index ede6993f4aa..b3505bdd8e0 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -14,6 +14,7 @@ return array(
'NCU\\Config\\Lexicon\\ConfigLexiconEntry' => $baseDir . '/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php',
'NCU\\Config\\Lexicon\\ConfigLexiconStrictness' => $baseDir . '/lib/unstable/Config/Lexicon/ConfigLexiconStrictness.php',
'NCU\\Config\\Lexicon\\IConfigLexicon' => $baseDir . '/lib/unstable/Config/Lexicon/IConfigLexicon.php',
+ 'NCU\\Config\\Lexicon\\Preset' => $baseDir . '/lib/unstable/Config/Lexicon/Preset.php',
'NCU\\Config\\ValueType' => $baseDir . '/lib/unstable/Config/ValueType.php',
'NCU\\Federation\\ISignedCloudFederationProvider' => $baseDir . '/lib/unstable/Federation/ISignedCloudFederationProvider.php',
'NCU\\Security\\Signature\\Enum\\DigestAlgorithm' => $baseDir . '/lib/unstable/Security/Signature/Enum/DigestAlgorithm.php',
@@ -1250,6 +1251,7 @@ return array(
'OC\\Core\\Command\\Config\\App\\SetConfig' => $baseDir . '/core/Command/Config/App/SetConfig.php',
'OC\\Core\\Command\\Config\\Import' => $baseDir . '/core/Command/Config/Import.php',
'OC\\Core\\Command\\Config\\ListConfigs' => $baseDir . '/core/Command/Config/ListConfigs.php',
+ 'OC\\Core\\Command\\Config\\Preset' => $baseDir . '/core/Command/Config/Preset.php',
'OC\\Core\\Command\\Config\\System\\Base' => $baseDir . '/core/Command/Config/System/Base.php',
'OC\\Core\\Command\\Config\\System\\CastHelper' => $baseDir . '/core/Command/Config/System/CastHelper.php',
'OC\\Core\\Command\\Config\\System\\DeleteConfig' => $baseDir . '/core/Command/Config/System/DeleteConfig.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 27e832438db..15ae0a9373f 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -55,6 +55,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'NCU\\Config\\Lexicon\\ConfigLexiconEntry' => __DIR__ . '/../../..' . '/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php',
'NCU\\Config\\Lexicon\\ConfigLexiconStrictness' => __DIR__ . '/../../..' . '/lib/unstable/Config/Lexicon/ConfigLexiconStrictness.php',
'NCU\\Config\\Lexicon\\IConfigLexicon' => __DIR__ . '/../../..' . '/lib/unstable/Config/Lexicon/IConfigLexicon.php',
+ 'NCU\\Config\\Lexicon\\Preset' => __DIR__ . '/../../..' . '/lib/unstable/Config/Lexicon/Preset.php',
'NCU\\Config\\ValueType' => __DIR__ . '/../../..' . '/lib/unstable/Config/ValueType.php',
'NCU\\Federation\\ISignedCloudFederationProvider' => __DIR__ . '/../../..' . '/lib/unstable/Federation/ISignedCloudFederationProvider.php',
'NCU\\Security\\Signature\\Enum\\DigestAlgorithm' => __DIR__ . '/../../..' . '/lib/unstable/Security/Signature/Enum/DigestAlgorithm.php',
@@ -1291,6 +1292,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Command\\Config\\App\\SetConfig' => __DIR__ . '/../../..' . '/core/Command/Config/App/SetConfig.php',
'OC\\Core\\Command\\Config\\Import' => __DIR__ . '/../../..' . '/core/Command/Config/Import.php',
'OC\\Core\\Command\\Config\\ListConfigs' => __DIR__ . '/../../..' . '/core/Command/Config/ListConfigs.php',
+ 'OC\\Core\\Command\\Config\\Preset' => __DIR__ . '/../../..' . '/core/Command/Config/Preset.php',
'OC\\Core\\Command\\Config\\System\\Base' => __DIR__ . '/../../..' . '/core/Command/Config/System/Base.php',
'OC\\Core\\Command\\Config\\System\\CastHelper' => __DIR__ . '/../../..' . '/core/Command/Config/System/CastHelper.php',
'OC\\Core\\Command\\Config\\System\\DeleteConfig' => __DIR__ . '/../../..' . '/core/Command/Config/System/DeleteConfig.php',
diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php
index 476adbb93e0..0eb91fb1be4 100644
--- a/lib/private/AppConfig.php
+++ b/lib/private/AppConfig.php
@@ -14,6 +14,7 @@ use JsonException;
use NCU\Config\Lexicon\ConfigLexiconEntry;
use NCU\Config\Lexicon\ConfigLexiconStrictness;
use NCU\Config\Lexicon\IConfigLexicon;
+use NCU\Config\Lexicon\Preset;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\Config\ConfigManager;
use OCP\DB\Exception as DBException;
@@ -64,12 +65,13 @@ class AppConfig implements IAppConfig {
/** @var array<string, array{entries: array<string, ConfigLexiconEntry>, aliases: array<string, string>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
private array $configLexiconDetails = [];
private bool $ignoreLexiconAliases = false;
-
+ private ?Preset $configLexiconPreset = null;
/** @var ?array<string, string> */
private ?array $appVersionsCache = null;
public function __construct(
protected IDBConnection $connection,
+ protected IConfig $config,
protected LoggerInterface $logger,
protected ICrypto $crypto,
) {
@@ -438,9 +440,17 @@ class AppConfig implements IAppConfig {
): string {
$this->assertParams($app, $key, valueType: $type);
$origKey = $key;
- if (!$this->matchAndApplyLexiconDefinition($app, $key, $lazy, $type, $default)) {
- return $default; // returns default if strictness of lexicon is set to WARNING (block and report)
+ $matched = $this->matchAndApplyLexiconDefinition($app, $key, $lazy, $type, $default);
+ if ($default === null) {
+ // there is no logical reason for it to be null
+ throw new \Exception('default cannot be null');
+ }
+
+ // returns default if strictness of lexicon is set to WARNING (block and report)
+ if (!$matched) {
+ return $default;
}
+
$this->loadConfig($app, $lazy);
/**
@@ -1146,7 +1156,8 @@ class AppConfig implements IAppConfig {
*/
public function clearCache(bool $reload = false): void {
$this->lazyLoaded = $this->fastLoaded = false;
- $this->lazyCache = $this->fastCache = $this->valueTypes = [];
+ $this->lazyCache = $this->fastCache = $this->valueTypes = $this->configLexiconDetails = [];
+ $this->configLexiconPreset = null;
if (!$reload) {
return;
@@ -1592,7 +1603,7 @@ class AppConfig implements IAppConfig {
string &$key,
?bool &$lazy = null,
int &$type = self::VALUE_MIXED,
- string &$default = '',
+ ?string &$default = null,
): bool {
if (in_array($key,
[
@@ -1629,7 +1640,11 @@ class AppConfig implements IAppConfig {
}
$lazy = $configValue->isLazy();
- $default = $configValue->getDefault() ?? $default; // default from Lexicon got priority
+ // only look for default if needed, default from Lexicon got priority
+ if ($default !== null) {
+ $default = $configValue->getDefault($this->getLexiconPreset()) ?? $default;
+ }
+
if ($configValue->isFlagged(self::FLAG_SENSITIVE)) {
$type |= self::VALUE_SENSITIVE;
}
@@ -1715,6 +1730,14 @@ class AppConfig implements IAppConfig {
$this->ignoreLexiconAliases = $ignore;
}
+ private function getLexiconPreset(): Preset {
+ if ($this->configLexiconPreset === null) {
+ $this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;
+ }
+
+ return $this->configLexiconPreset;
+ }
+
/**
* Returns the installed versions of all apps
*
diff --git a/lib/private/Config/ConfigManager.php b/lib/private/Config/ConfigManager.php
index 1980269e2ca..67466617941 100644
--- a/lib/private/Config/ConfigManager.php
+++ b/lib/private/Config/ConfigManager.php
@@ -12,10 +12,12 @@ use JsonException;
use NCU\Config\Exceptions\TypeConflictException;
use NCU\Config\IUserConfig;
use NCU\Config\Lexicon\ConfigLexiconEntry;
+use NCU\Config\Lexicon\Preset;
use NCU\Config\ValueType;
use OC\AppConfig;
use OCP\App\IAppManager;
use OCP\IAppConfig;
+use OCP\IConfig;
use OCP\Server;
use Psr\Log\LoggerInterface;
@@ -25,12 +27,16 @@ use Psr\Log\LoggerInterface;
* @since 32.0.0
*/
class ConfigManager {
+ /** @since 32.0.0 */
+ public const PRESET_CONFIGKEY = 'config_preset';
+
/** @var AppConfig|null $appConfig */
private ?IAppConfig $appConfig = null;
/** @var UserConfig|null $userConfig */
private ?IUserConfig $userConfig = null;
public function __construct(
+ private readonly IConfig $config,
private readonly LoggerInterface $logger,
) {
}
@@ -75,6 +81,17 @@ class ConfigManager {
}
/**
+ * store in config.php the new preset
+ * refresh cached preset
+ */
+ public function setLexiconPreset(Preset $preset): void {
+ $this->config->setSystemValue(self::PRESET_CONFIGKEY, $preset->value);
+ $this->loadConfigServices();
+ $this->appConfig->clearCache();
+ $this->userConfig->clearCacheAll();
+ }
+
+ /**
* config services cannot be load at __construct() or install will fail
*/
private function loadConfigServices(): void {
diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php
index 7848f1728e3..fb0bf954f57 100644
--- a/lib/private/Config/UserConfig.php
+++ b/lib/private/Config/UserConfig.php
@@ -17,6 +17,7 @@ use NCU\Config\Exceptions\UnknownKeyException;
use NCU\Config\IUserConfig;
use NCU\Config\Lexicon\ConfigLexiconEntry;
use NCU\Config\Lexicon\ConfigLexiconStrictness;
+use NCU\Config\Lexicon\Preset;
use NCU\Config\ValueType;
use OC\AppFramework\Bootstrap\Coordinator;
use OCP\DB\Exception as DBException;
@@ -66,6 +67,7 @@ class UserConfig implements IUserConfig {
/** @var array<string, array{entries: array<string, ConfigLexiconEntry>, aliases: array<string, string>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
private array $configLexiconDetails = [];
private bool $ignoreLexiconAliases = false;
+ private ?Preset $configLexiconPreset = null;
public function __construct(
protected IDBConnection $connection,
@@ -721,10 +723,17 @@ class UserConfig implements IUserConfig {
): string {
$this->assertParams($userId, $app, $key);
$origKey = $key;
- if (!$this->matchAndApplyLexiconDefinition($userId, $app, $key, $lazy, $type, default: $default)) {
- // returns default if strictness of lexicon is set to WARNING (block and report)
+ $matched = $this->matchAndApplyLexiconDefinition($userId, $app, $key, $lazy, $type, default: $default);
+ if ($default === null) {
+ // there is no logical reason for it to be null
+ throw new \Exception('default cannot be null');
+ }
+
+ // returns default if strictness of lexicon is set to WARNING (block and report)
+ if (!$matched) {
return $default;
}
+
$this->loadConfig($userId, $lazy);
/**
@@ -1625,7 +1634,8 @@ class UserConfig implements IUserConfig {
*/
public function clearCacheAll(): void {
$this->lazyLoaded = $this->fastLoaded = [];
- $this->lazyCache = $this->fastCache = $this->valueDetails = [];
+ $this->lazyCache = $this->fastCache = $this->valueDetails = $this->configLexiconDetails = [];
+ $this->configLexiconPreset = null;
}
/**
@@ -1886,7 +1896,7 @@ class UserConfig implements IUserConfig {
?bool &$lazy = null,
ValueType &$type = ValueType::MIXED,
int &$flags = 0,
- string &$default = '',
+ ?string &$default = null,
): bool {
$configDetails = $this->getConfigDetailsFromLexicon($app);
if (array_key_exists($key, $configDetails['aliases']) && !$this->ignoreLexiconAliases) {
@@ -1924,8 +1934,10 @@ class UserConfig implements IUserConfig {
return true;
}
- // default from Lexicon got priority but it can still be overwritten by admin
- $default = $this->getSystemDefault($app, $configValue) ?? $configValue->getDefault() ?? $default;
+ // only look for default if needed, default from Lexicon got priority if not overwritten by admin
+ if ($default !== null) {
+ $default = $this->getSystemDefault($app, $configValue) ?? $configValue->getDefault($this->getLexiconPreset()) ?? $default;
+ }
// returning false will make get() returning $default and set() not changing value in database
return !$enforcedValue;
@@ -2025,4 +2037,12 @@ class UserConfig implements IUserConfig {
public function ignoreLexiconAliases(bool $ignore): void {
$this->ignoreLexiconAliases = $ignore;
}
+
+ private function getLexiconPreset(): Preset {
+ if ($this->configLexiconPreset === null) {
+ $this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;
+ }
+
+ return $this->configLexiconPreset;
+ }
}
diff --git a/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php b/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php
index d0d9b4cbd23..068d89ce764 100644
--- a/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php
+++ b/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
namespace NCU\Config\Lexicon;
+use Closure;
use NCU\Config\ValueType;
/**
@@ -24,7 +25,7 @@ class ConfigLexiconEntry {
private ?string $default = null;
/**
- * @param string $key config key
+ * @param string $key config key, can only contain alphanumerical chars and -._
* @param ValueType $type type of config value
* @param string $definition optional description of config key available when using occ command
* @param bool $lazy set config value as lazy
@@ -39,7 +40,7 @@ class ConfigLexiconEntry {
public function __construct(
private readonly string $key,
private readonly ValueType $type,
- private null|string|int|float|bool|array $defaultRaw = null,
+ private null|string|int|float|bool|array|Closure $defaultRaw = null,
string $definition = '',
private readonly bool $lazy = false,
private readonly int $flags = 0,
@@ -47,6 +48,11 @@ class ConfigLexiconEntry {
private readonly ?string $rename = null,
private readonly int $options = 0,
) {
+ // key can only contain alphanumeric chars and underscore "_"
+ if (preg_match('/[^[:alnum:]_]/', $key)) {
+ throw new \Exception('invalid config key');
+ }
+
/** @psalm-suppress UndefinedClass */
if (\OC::$CLI) { // only store definition if ran from CLI
$this->definition = $definition;
@@ -124,15 +130,23 @@ class ConfigLexiconEntry {
* @return string|null NULL if no default is set
* @experimental 31.0.0
*/
- public function getDefault(): ?string {
+ public function getDefault(Preset $preset): ?string {
+ if ($this->default !== null) {
+ return $this->default;
+ }
+
if ($this->defaultRaw === null) {
return null;
}
- if ($this->default === null) {
- $this->default = $this->convertToString($this->defaultRaw);
+ if ($this->defaultRaw instanceof Closure) {
+ /** @psalm-suppress MixedAssignment we expect closure to returns string|int|float|bool|array */
+ $this->defaultRaw = ($this->defaultRaw)($preset);
}
+ /** @psalm-suppress MixedArgument closure should be managed previously */
+ $this->default = $this->convertToString($this->defaultRaw);
+
return $this->default;
}
diff --git a/lib/unstable/Config/Lexicon/Preset.php b/lib/unstable/Config/Lexicon/Preset.php
new file mode 100644
index 00000000000..92a6fd8cbfa
--- /dev/null
+++ b/lib/unstable/Config/Lexicon/Preset.php
@@ -0,0 +1,46 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+namespace NCU\Config\Lexicon;
+
+/**
+ * list of preset to handle the default behavior of the instance
+ *
+ * @see ConfigLexiconEntry::preset
+ *
+ * - **Preset::LARGE** - Large size organisation (> 50k accounts)
+ * - **Preset::MEDIUM** - Medium size organisation (> 100 accounts)
+ * - **Preset::SMALL** - Small size organisation (< 100 accounts)
+ * - **Preset::SHARED** - Shared hosting
+ * - **Preset::EDUCATION** - School/University
+ * - **Preset::CLUB** - Club/Association
+ * - **Preset::FAMILY** - Family
+ * - **Preset::PRIVATE** - Private
+ *
+ * @experimental 32.0.0
+ */
+enum Preset: int {
+ /** @experimental 32.0.0 */
+ case LARGE = 8;
+ /** @experimental 32.0.0 */
+ case MEDIUM = 7;
+ /** @experimental 32.0.0 */
+ case SMALL = 6;
+ /** @experimental 32.0.0 */
+ case SHARED = 5;
+ /** @experimental 32.0.0 */
+ case EDUCATION = 4;
+ /** @experimental 32.0.0 */
+ case CLUB = 3;
+ /** @experimental 32.0.0 */
+ case FAMILY = 2;
+ /** @experimental 32.0.0 */
+ case PRIVATE = 1;
+ /** @experimental 32.0.0 */
+ case NONE = 0;
+}
diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php
index 408e4321d4f..4c579bc4f09 100644
--- a/tests/lib/AppConfigTest.php
+++ b/tests/lib/AppConfigTest.php
@@ -12,6 +12,7 @@ use OC\AppConfig;
use OCP\Exceptions\AppConfigTypeConflictException;
use OCP\Exceptions\AppConfigUnknownKeyException;
use OCP\IAppConfig;
+use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Security\ICrypto;
use OCP\Server;
@@ -27,6 +28,7 @@ use Psr\Log\LoggerInterface;
class AppConfigTest extends TestCase {
protected IAppConfig $appConfig;
protected IDBConnection $connection;
+ private IConfig $config;
private LoggerInterface $logger;
private ICrypto $crypto;
@@ -89,6 +91,7 @@ class AppConfigTest extends TestCase {
parent::setUp();
$this->connection = Server::get(IDBConnection::class);
+ $this->config = Server::get(IConfig::class);
$this->logger = Server::get(LoggerInterface::class);
$this->crypto = Server::get(ICrypto::class);
@@ -179,6 +182,7 @@ class AppConfigTest extends TestCase {
/** @var AppConfig $config */
$config = new AppConfig(
$this->connection,
+ $this->config,
$this->logger,
$this->crypto,
);
diff --git a/tests/lib/Config/LexiconTest.php b/tests/lib/Config/LexiconTest.php
index 530767a7416..760ac08a147 100644
--- a/tests/lib/Config/LexiconTest.php
+++ b/tests/lib/Config/LexiconTest.php
@@ -10,6 +10,7 @@ namespace Tests\lib\Config;
use NCU\Config\Exceptions\TypeConflictException;
use NCU\Config\Exceptions\UnknownKeyException;
use NCU\Config\IUserConfig;
+use NCU\Config\Lexicon\Preset;
use OC\AppConfig;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\Config\ConfigManager;
@@ -203,4 +204,28 @@ class LexiconTest extends TestCase {
$this->configManager->migrateConfigLexiconKeys(TestConfigLexicon_I::APPID);
$this->assertSame(false, $this->appConfig->getValueBool(TestConfigLexicon_I::APPID, 'key4'));
}
+
+ public function testAppConfigLexiconPreset() {
+ $this->configManager->setLexiconPreset(Preset::FAMILY);
+ $this->assertSame('family', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key3'));
+ }
+
+ public function testAppConfigLexiconPresets() {
+ $this->configManager->setLexiconPreset(Preset::MEDIUM);
+ $this->assertSame('club+medium', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key3'));
+ $this->configManager->setLexiconPreset(Preset::FAMILY);
+ $this->assertSame('family', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key3'));
+ }
+
+ public function testUserConfigLexiconPreset() {
+ $this->configManager->setLexiconPreset(Preset::FAMILY);
+ $this->assertSame('family', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key3'));
+ }
+
+ public function testUserConfigLexiconPresets() {
+ $this->configManager->setLexiconPreset(Preset::MEDIUM);
+ $this->assertSame('club+medium', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key3'));
+ $this->configManager->setLexiconPreset(Preset::FAMILY);
+ $this->assertSame('family', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key3'));
+ }
}
diff --git a/tests/lib/Config/TestConfigLexicon_E.php b/tests/lib/Config/TestConfigLexicon_E.php
index e0890cbd76e..197c3dc21b1 100644
--- a/tests/lib/Config/TestConfigLexicon_E.php
+++ b/tests/lib/Config/TestConfigLexicon_E.php
@@ -12,6 +12,7 @@ use NCU\Config\IUserConfig;
use NCU\Config\Lexicon\ConfigLexiconEntry;
use NCU\Config\Lexicon\ConfigLexiconStrictness;
use NCU\Config\Lexicon\IConfigLexicon;
+use NCU\Config\Lexicon\Preset;
use NCU\Config\ValueType;
use OCP\IAppConfig;
@@ -25,14 +26,24 @@ class TestConfigLexicon_E implements IConfigLexicon {
public function getAppConfigs(): array {
return [
new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IAppConfig::FLAG_SENSITIVE),
- new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false)
+ new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false),
+ new ConfigLexiconEntry('key3', ValueType::STRING, fn (Preset $p): string => match ($p) {
+ Preset::FAMILY => 'family',
+ Preset::CLUB, Preset::MEDIUM => 'club+medium',
+ default => 'none',
+ }, 'test key'),
];
}
public function getUserConfigs(): array {
return [
new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IUserConfig::FLAG_SENSITIVE),
- new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false)
+ new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false),
+ new ConfigLexiconEntry('key3', ValueType::STRING, fn (Preset $p): string => match ($p) {
+ Preset::FAMILY => 'family',
+ Preset::CLUB, Preset::MEDIUM => 'club+medium',
+ default => 'none',
+ }, 'test key'),
];
}
}