diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 12ada1c0213bf..ed266ecb653e3 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -12,6 +12,7 @@ use InvalidArgumentException; use OC\Authentication\Token\RemoteWipe; +use OC\Core\AppInfo\ConfigLexicon; use OC\Group\Group; use OC\KnownUser\KnownUserService; use OC\User\Backend; @@ -32,6 +33,7 @@ use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; +use OCP\Config\IUserConfig; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; use OCP\Group\ISubAdmin; @@ -81,6 +83,7 @@ public function __construct( private IEventDispatcher $eventDispatcher, private IPhoneNumberUtil $phoneNumberUtil, private IAppManager $appManager, + private readonly IUserConfig $userConfig, ) { parent::__construct( $appName, @@ -1116,19 +1119,19 @@ public function editUser(string $userId, string $key, string $value): DataRespon if (!in_array($value, $languagesCodes, true) && $value !== 'en') { throw new OCSException($this->l10n->t('Invalid language'), 101); } - $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); + $this->userConfig->setValueString($targetUser->getUID(), 'core', ConfigLexicon::USER_LANGUAGE, $value); break; case self::USER_FIELD_LOCALE: if (!$this->l10nFactory->localeExists($value)) { throw new OCSException($this->l10n->t('Invalid locale'), 101); } - $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value); + $this->userConfig->setValueString($targetUser->getUID(), 'core', ConfigLexicon::USER_LOCALE, $value); break; case self::USER_FIELD_TIMEZONE: if (!in_array($value, \DateTimeZone::listIdentifiers())) { throw new OCSException($this->l10n->t('Invalid timezone'), 101); } - $this->config->setUserValue($targetUser->getUID(), 'core', 'timezone', $value); + $this->userConfig->setValueString($targetUser->getUID(), 'core', ConfigLexicon::USER_TIMEZONE, $value); break; case self::USER_FIELD_FIRST_DAY_OF_WEEK: $intValue = (int)$value; diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 1a1c7c80fae09..098ffa07eb77c 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -23,6 +23,7 @@ use OCP\App\IAppManager; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSException; +use OCP\Config\IUserConfig; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; use OCP\Group\ISubAdmin; @@ -66,6 +67,7 @@ class UsersControllerTest extends TestCase { private IRootFolder $rootFolder; private IPhoneNumberUtil $phoneNumberUtil; private IAppManager $appManager; + private IUserConfig $userConfig; protected function setUp(): void { parent::setUp(); @@ -88,6 +90,7 @@ protected function setUp(): void { $this->phoneNumberUtil = new PhoneNumberUtil(); $this->appManager = $this->createMock(IAppManager::class); $this->rootFolder = $this->createMock(IRootFolder::class); + $this->userConfig = $this->createMock(IUserConfig::class); $l10n = $this->createMock(IL10N::class); $l10n->method('t')->willReturnCallback(fn (string $txt, array $replacement = []) => sprintf($txt, ...$replacement)); @@ -114,6 +117,7 @@ protected function setUp(): void { $this->eventDispatcher, $this->phoneNumberUtil, $this->appManager, + $this->userConfig, ]) ->onlyMethods(['fillStorageInfo']) ->getMock(); @@ -506,6 +510,7 @@ public function testAddUserSuccessfulWithDisplayName(): void { $this->eventDispatcher, $this->phoneNumberUtil, $this->appManager, + $this->userConfig, ]) ->onlyMethods(['editUser']) ->getMock(); @@ -2291,8 +2296,8 @@ public function testEditUserSelfEditChangeLanguage(): void { ->method('getUID') ->willReturn('UserToEdit'); $targetUser = $this->createMock(IUser::class); - $this->config->expects($this->once()) - ->method('setUserValue') + $this->userConfig->expects($this->once()) + ->method('setValueString') ->with('UserToEdit', 'core', 'lang', 'de'); $this->userSession ->expects($this->once()) @@ -2346,8 +2351,8 @@ public function testEditUserSelfEditChangeLanguageButForced($forced): void { ->method('getUID') ->willReturn('UserToEdit'); $targetUser = $this->createMock(IUser::class); - $this->config->expects($this->never()) - ->method('setUserValue'); + $this->userConfig->expects($this->never()) + ->method('setValueString'); $this->userSession ->expects($this->once()) ->method('getUser') @@ -2387,8 +2392,8 @@ public function testEditUserAdminEditChangeLanguage(): void { ->method('getUID') ->willReturn('admin'); $targetUser = $this->createMock(IUser::class); - $this->config->expects($this->once()) - ->method('setUserValue') + $this->userConfig->expects($this->once()) + ->method('setValueString') ->with('UserToEdit', 'core', 'lang', 'de'); $this->userSession ->expects($this->once()) @@ -3850,6 +3855,7 @@ public function testGetCurrentUserLoggedIn(): void { $this->eventDispatcher, $this->phoneNumberUtil, $this->appManager, + $this->userConfig, ]) ->onlyMethods(['getUserData']) ->getMock(); @@ -3944,6 +3950,7 @@ public function testGetUser(): void { $this->eventDispatcher, $this->phoneNumberUtil, $this->appManager, + $this->userConfig, ]) ->onlyMethods(['getUserData']) ->getMock(); diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 27d29eb3b356e..0fa7b0d05e142 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -8,8 +8,10 @@ */ namespace OC\L10N; +use OC\Core\AppInfo\ConfigLexicon; use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; +use OCP\Config\IUserConfig; use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; @@ -71,6 +73,7 @@ class Factory implements IFactory { ]; private ICache $cache; + private IUserConfig $userConfig; public function __construct( protected IConfig $config, @@ -200,7 +203,8 @@ public function findLanguage(?string $appId = null): string { // Try to get the language from the Request $lang = $this->getLanguageFromRequest($appId); if ($userId !== null && $appId === null && !$userLang) { - $this->config->setUserValue($userId, 'core', 'lang', $lang); + $userConfig = \OCP\Server::get(IUserConfig::class); + $userConfig->setValueString($userId, 'core', ConfigLexicon::USER_LANGUAGE, $lang); } return $lang; } catch (LanguageNotFoundException $e) {