diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index ab0f12233d4..acded1ed539 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1219,6 +1219,7 @@ return array( 'OC\\Comments\\ManagerFactory' => $baseDir . '/lib/private/Comments/ManagerFactory.php', 'OC\\Config' => $baseDir . '/lib/private/Config.php', 'OC\\Config\\ConfigManager' => $baseDir . '/lib/private/Config/ConfigManager.php', + 'OC\\Config\\PresetManager' => $baseDir . '/lib/private/Config/PresetManager.php', 'OC\\Config\\UserConfig' => $baseDir . '/lib/private/Config/UserConfig.php', 'OC\\Console\\Application' => $baseDir . '/lib/private/Console/Application.php', 'OC\\Console\\TimestampFormatter' => $baseDir . '/lib/private/Console/TimestampFormatter.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 3d32ee7e567..bb20a68eae3 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1260,6 +1260,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Comments\\ManagerFactory' => __DIR__ . '/../../..' . '/lib/private/Comments/ManagerFactory.php', 'OC\\Config' => __DIR__ . '/../../..' . '/lib/private/Config.php', 'OC\\Config\\ConfigManager' => __DIR__ . '/../../..' . '/lib/private/Config/ConfigManager.php', + 'OC\\Config\\PresetManager' => __DIR__ . '/../../..' . '/lib/private/Config/PresetManager.php', 'OC\\Config\\UserConfig' => __DIR__ . '/../../..' . '/lib/private/Config/UserConfig.php', 'OC\\Console\\Application' => __DIR__ . '/../../..' . '/lib/private/Console/Application.php', 'OC\\Console\\TimestampFormatter' => __DIR__ . '/../../..' . '/lib/private/Console/TimestampFormatter.php', diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index c4ea7a5c1db..cef612536d6 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -16,7 +16,6 @@ use OC\Config\ConfigManager; use OC\Config\PresetManager; use OCP\Config\Lexicon\Entry; use OCP\Config\Lexicon\ILexicon; -use OCP\Config\Lexicon\Preset; use OCP\Config\Lexicon\Strictness; use OCP\Config\ValueType; use OCP\DB\Exception as DBException; @@ -28,7 +27,6 @@ use OCP\IAppConfig; use OCP\IConfig; use OCP\IDBConnection; use OCP\Security\ICrypto; -use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -1136,7 +1134,7 @@ class AppConfig implements IAppConfig { ]); } - return array_filter($details, static fn($v): bool => ($v !== null)); + return array_filter($details, static fn ($v): bool => ($v !== null)); } /** diff --git a/lib/private/Config/ConfigManager.php b/lib/private/Config/ConfigManager.php index 3b057c09402..28397402249 100644 --- a/lib/private/Config/ConfigManager.php +++ b/lib/private/Config/ConfigManager.php @@ -14,10 +14,8 @@ use OCP\App\IAppManager; use OCP\Config\Exceptions\TypeConflictException; use OCP\Config\IUserConfig; use OCP\Config\Lexicon\Entry; -use OCP\Config\Lexicon\Preset; use OCP\Config\ValueType; use OCP\IAppConfig; -use OCP\IConfig; use OCP\Server; use Psr\Log\LoggerInterface; diff --git a/lib/private/Config/PresetManager.php b/lib/private/Config/PresetManager.php index 70dfd2e2101..d9c029d15c2 100644 --- a/lib/private/Config/PresetManager.php +++ b/lib/private/Config/PresetManager.php @@ -13,8 +13,6 @@ use OCP\IConfig; /** * tools to maintains configurations - * - * @since 32.0.0 */ class PresetManager { private const PRESET_CONFIGKEY = 'config_preset'; @@ -37,6 +35,9 @@ class PresetManager { $this->configManager->clearConfigCaches(); } + /** + * returns currently selected Preset + */ public function getLexiconPreset(): Preset { if ($this->configLexiconPreset === null) { $this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(self::PRESET_CONFIGKEY, 0)) ?? Preset::NONE; diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php index 6f296b6c605..4ddad3ec2f2 100644 --- a/lib/private/Config/UserConfig.php +++ b/lib/private/Config/UserConfig.php @@ -18,7 +18,6 @@ use OCP\Config\Exceptions\UnknownKeyException; use OCP\Config\IUserConfig; use OCP\Config\Lexicon\Entry; use OCP\Config\Lexicon\ILexicon; -use OCP\Config\Lexicon\Preset; use OCP\Config\Lexicon\Strictness; use OCP\Config\ValueType; use OCP\DB\Exception as DBException; @@ -27,7 +26,6 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; use OCP\IDBConnection; use OCP\Security\ICrypto; -use OCP\Server; use Psr\Log\LoggerInterface; /** diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php index d0b4e1bcc45..c38412f6bd0 100644 --- a/lib/private/Profile/ProfileManager.php +++ b/lib/private/Profile/ProfileManager.php @@ -327,22 +327,23 @@ class ProfileManager implements IProfileManager { /** * modify property visibility, based on current Preset + * + * @psalm-suppress UnhandledMatchCondition if conditions are not met, we do not change $visibility */ private function applyDefaultProfilePreset(string $property, string &$visibility): void { - $overwrite = match($this->presetManager->getLexiconPreset()) { - Preset::SHARED, Preset::SCHOOL, Preset::UNIVERSITY => match($property) { - IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_HIDE, - }, - Preset::PRIVATE, Preset::FAMILY, Preset::CLUB => match($property) { - IAccountManager::PROPERTY_EMAIL => self::VISIBILITY_SHOW, - }, - Preset::SMALL, Preset::MEDIUM, Preset::LARGE => match($property) { - IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_SHOW, - }, - default => null, - }; - - if ($overwrite === null) { + try { + $overwrite = match ($this->presetManager->getLexiconPreset()) { + Preset::SHARED, Preset::SCHOOL, Preset::UNIVERSITY => match ($property) { + IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_HIDE, + }, + Preset::PRIVATE, Preset::FAMILY, Preset::CLUB => match ($property) { + IAccountManager::PROPERTY_EMAIL => self::VISIBILITY_SHOW, + }, + Preset::SMALL, Preset::MEDIUM, Preset::LARGE => match ($property) { + IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_SHOW, + }, + }; + } catch (\UnhandledMatchError) { return; } diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php index 03405bf96ca..0ae917a1d9f 100644 --- a/tests/lib/AppConfigTest.php +++ b/tests/lib/AppConfigTest.php @@ -9,6 +9,8 @@ namespace Test; use InvalidArgumentException; use OC\AppConfig; +use OC\Config\ConfigManager; +use OC\Config\PresetManager; use OCP\Exceptions\AppConfigTypeConflictException; use OCP\Exceptions\AppConfigUnknownKeyException; use OCP\IAppConfig; @@ -29,6 +31,8 @@ class AppConfigTest extends TestCase { protected IAppConfig $appConfig; protected IDBConnection $connection; private IConfig $config; + private ConfigManager $configManager; + private PresetManager $presetManager; private LoggerInterface $logger; private ICrypto $crypto; @@ -99,6 +103,8 @@ class AppConfigTest extends TestCase { $this->connection = Server::get(IDBConnection::class); $this->config = Server::get(IConfig::class); + $this->configManager = Server::get(ConfigManager::class); + $this->presetManager = Server::get(PresetManager::class); $this->logger = Server::get(LoggerInterface::class); $this->crypto = Server::get(ICrypto::class); @@ -190,6 +196,8 @@ class AppConfigTest extends TestCase { $config = new AppConfig( $this->connection, $this->config, + $this->configManager, + $this->presetManager, $this->logger, $this->crypto, ); diff --git a/tests/lib/Config/LexiconTest.php b/tests/lib/Config/LexiconTest.php index def9e152853..d7e9b12a1cf 100644 --- a/tests/lib/Config/LexiconTest.php +++ b/tests/lib/Config/LexiconTest.php @@ -10,6 +10,7 @@ namespace Tests\lib\Config; use OC\AppConfig; use OC\AppFramework\Bootstrap\Coordinator; use OC\Config\ConfigManager; +use OC\Config\PresetManager; use OCP\Config\Exceptions\TypeConflictException; use OCP\Config\Exceptions\UnknownKeyException; use OCP\Config\IUserConfig; @@ -32,6 +33,7 @@ class LexiconTest extends TestCase { private IAppConfig $appConfig; private IUserConfig $userConfig; private ConfigManager $configManager; + private PresetManager $presetManager; protected function setUp(): void { parent::setUp(); @@ -45,6 +47,7 @@ class LexiconTest extends TestCase { $this->appConfig = Server::get(IAppConfig::class); $this->userConfig = Server::get(IUserConfig::class); $this->configManager = Server::get(ConfigManager::class); + $this->presetManager = Server::get(PresetManager::class); } protected function tearDown(): void { @@ -206,26 +209,26 @@ class LexiconTest extends TestCase { } public function testAppConfigLexiconPreset() { - $this->configManager->setLexiconPreset(Preset::FAMILY); + $this->presetManager->setLexiconPreset(Preset::FAMILY); $this->assertSame('family', $this->appConfig->getValueString(TestLexicon_E::APPID, 'key3')); } public function testAppConfigLexiconPresets() { - $this->configManager->setLexiconPreset(Preset::MEDIUM); + $this->presetManager->setLexiconPreset(Preset::MEDIUM); $this->assertSame('club+medium', $this->appConfig->getValueString(TestLexicon_E::APPID, 'key3')); - $this->configManager->setLexiconPreset(Preset::FAMILY); + $this->presetManager->setLexiconPreset(Preset::FAMILY); $this->assertSame('family', $this->appConfig->getValueString(TestLexicon_E::APPID, 'key3')); } public function testUserConfigLexiconPreset() { - $this->configManager->setLexiconPreset(Preset::FAMILY); + $this->presetManager->setLexiconPreset(Preset::FAMILY); $this->assertSame('family', $this->userConfig->getValueString('user1', TestLexicon_E::APPID, 'key3')); } public function testUserConfigLexiconPresets() { - $this->configManager->setLexiconPreset(Preset::MEDIUM); + $this->presetManager->setLexiconPreset(Preset::MEDIUM); $this->assertSame('club+medium', $this->userConfig->getValueString('user1', TestLexicon_E::APPID, 'key3')); - $this->configManager->setLexiconPreset(Preset::FAMILY); + $this->presetManager->setLexiconPreset(Preset::FAMILY); $this->assertSame('family', $this->userConfig->getValueString('user1', TestLexicon_E::APPID, 'key3')); } } diff --git a/tests/lib/Config/UserConfigTest.php b/tests/lib/Config/UserConfigTest.php index 5666a441b93..9dd5ab10084 100644 --- a/tests/lib/Config/UserConfigTest.php +++ b/tests/lib/Config/UserConfigTest.php @@ -7,6 +7,8 @@ declare(strict_types=1); */ namespace Test\lib\Config; +use OC\Config\ConfigManager; +use OC\Config\PresetManager; use OC\Config\UserConfig; use OCP\Config\Exceptions\TypeConflictException; use OCP\Config\Exceptions\UnknownKeyException; @@ -29,6 +31,8 @@ use Test\TestCase; class UserConfigTest extends TestCase { protected IDBConnection $connection; private IConfig $config; + private ConfigManager $configManager; + private PresetManager $presetManager; private LoggerInterface $logger; private ICrypto $crypto; private array $originalPreferences; @@ -173,6 +177,8 @@ class UserConfigTest extends TestCase { $this->connection = Server::get(IDBConnection::class); $this->config = Server::get(IConfig::class); + $this->configManager = Server::get(ConfigManager::class); + $this->presetManager = Server::get(PresetManager::class); $this->logger = Server::get(LoggerInterface::class); $this->crypto = Server::get(ICrypto::class); @@ -282,6 +288,8 @@ class UserConfigTest extends TestCase { $userConfig = new UserConfig( $this->connection, $this->config, + $this->configManager, + $this->presetManager, $this->logger, $this->crypto, );