Skip to content

Commit 6e90f21

Browse files
committed
fix(lexicon): using userconfig on value set in lexicon
Signed-off-by: Maxence Lange <[email protected]>
1 parent 8679fd1 commit 6e90f21

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use InvalidArgumentException;
1414
use OC\Authentication\Token\RemoteWipe;
15+
use OC\Core\AppInfo\ConfigLexicon;
1516
use OC\Group\Group;
1617
use OC\KnownUser\KnownUserService;
1718
use OC\User\Backend;
@@ -32,6 +33,7 @@
3233
use OCP\AppFramework\OCS\OCSForbiddenException;
3334
use OCP\AppFramework\OCS\OCSNotFoundException;
3435
use OCP\AppFramework\OCSController;
36+
use OCP\Config\IUserConfig;
3537
use OCP\EventDispatcher\IEventDispatcher;
3638
use OCP\Files\IRootFolder;
3739
use OCP\Group\ISubAdmin;
@@ -81,6 +83,7 @@ public function __construct(
8183
private IEventDispatcher $eventDispatcher,
8284
private IPhoneNumberUtil $phoneNumberUtil,
8385
private IAppManager $appManager,
86+
private readonly IUserConfig $userConfig,
8487
) {
8588
parent::__construct(
8689
$appName,
@@ -1116,19 +1119,19 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11161119
if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
11171120
throw new OCSException($this->l10n->t('Invalid language'), 101);
11181121
}
1119-
$this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
1122+
$this->userConfig->setValueString($targetUser->getUID(), 'core', ConfigLexicon::USER_LANGUAGE, $value);
11201123
break;
11211124
case self::USER_FIELD_LOCALE:
11221125
if (!$this->l10nFactory->localeExists($value)) {
11231126
throw new OCSException($this->l10n->t('Invalid locale'), 101);
11241127
}
1125-
$this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
1128+
$this->userConfig->setValueString($targetUser->getUID(), 'core', ConfigLexicon::USER_LOCALE, $value);
11261129
break;
11271130
case self::USER_FIELD_TIMEZONE:
11281131
if (!in_array($value, \DateTimeZone::listIdentifiers())) {
11291132
throw new OCSException($this->l10n->t('Invalid timezone'), 101);
11301133
}
1131-
$this->config->setUserValue($targetUser->getUID(), 'core', 'timezone', $value);
1134+
$this->userConfig->setValueString($targetUser->getUID(), 'core', ConfigLexicon::USER_TIMEZONE, $value);
11321135
break;
11331136
case self::USER_FIELD_FIRST_DAY_OF_WEEK:
11341137
$intValue = (int)$value;

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use OCP\App\IAppManager;
2424
use OCP\AppFramework\Http\DataResponse;
2525
use OCP\AppFramework\OCS\OCSException;
26+
use OCP\Config\IUserConfig;
2627
use OCP\EventDispatcher\IEventDispatcher;
2728
use OCP\Files\IRootFolder;
2829
use OCP\Group\ISubAdmin;
@@ -66,6 +67,7 @@ class UsersControllerTest extends TestCase {
6667
private IRootFolder $rootFolder;
6768
private IPhoneNumberUtil $phoneNumberUtil;
6869
private IAppManager $appManager;
70+
private IUserConfig $userConfig;
6971

7072
protected function setUp(): void {
7173
parent::setUp();
@@ -88,6 +90,7 @@ protected function setUp(): void {
8890
$this->phoneNumberUtil = new PhoneNumberUtil();
8991
$this->appManager = $this->createMock(IAppManager::class);
9092
$this->rootFolder = $this->createMock(IRootFolder::class);
93+
$this->userConfig = $this->createMock(IUserConfig::class);
9194

9295
$l10n = $this->createMock(IL10N::class);
9396
$l10n->method('t')->willReturnCallback(fn (string $txt, array $replacement = []) => sprintf($txt, ...$replacement));
@@ -114,6 +117,7 @@ protected function setUp(): void {
114117
$this->eventDispatcher,
115118
$this->phoneNumberUtil,
116119
$this->appManager,
120+
$this->userConfig,
117121
])
118122
->onlyMethods(['fillStorageInfo'])
119123
->getMock();
@@ -506,6 +510,7 @@ public function testAddUserSuccessfulWithDisplayName(): void {
506510
$this->eventDispatcher,
507511
$this->phoneNumberUtil,
508512
$this->appManager,
513+
$this->userConfig,
509514
])
510515
->onlyMethods(['editUser'])
511516
->getMock();
@@ -2291,8 +2296,8 @@ public function testEditUserSelfEditChangeLanguage(): void {
22912296
->method('getUID')
22922297
->willReturn('UserToEdit');
22932298
$targetUser = $this->createMock(IUser::class);
2294-
$this->config->expects($this->once())
2295-
->method('setUserValue')
2299+
$this->userConfig->expects($this->once())
2300+
->method('setValueString')
22962301
->with('UserToEdit', 'core', 'lang', 'de');
22972302
$this->userSession
22982303
->expects($this->once())
@@ -2346,8 +2351,8 @@ public function testEditUserSelfEditChangeLanguageButForced($forced): void {
23462351
->method('getUID')
23472352
->willReturn('UserToEdit');
23482353
$targetUser = $this->createMock(IUser::class);
2349-
$this->config->expects($this->never())
2350-
->method('setUserValue');
2354+
$this->userConfig->expects($this->never())
2355+
->method('setValueString');
23512356
$this->userSession
23522357
->expects($this->once())
23532358
->method('getUser')
@@ -2387,8 +2392,8 @@ public function testEditUserAdminEditChangeLanguage(): void {
23872392
->method('getUID')
23882393
->willReturn('admin');
23892394
$targetUser = $this->createMock(IUser::class);
2390-
$this->config->expects($this->once())
2391-
->method('setUserValue')
2395+
$this->userConfig->expects($this->once())
2396+
->method('setValueString')
23922397
->with('UserToEdit', 'core', 'lang', 'de');
23932398
$this->userSession
23942399
->expects($this->once())
@@ -3850,6 +3855,7 @@ public function testGetCurrentUserLoggedIn(): void {
38503855
$this->eventDispatcher,
38513856
$this->phoneNumberUtil,
38523857
$this->appManager,
3858+
$this->userConfig,
38533859
])
38543860
->onlyMethods(['getUserData'])
38553861
->getMock();
@@ -3944,6 +3950,7 @@ public function testGetUser(): void {
39443950
$this->eventDispatcher,
39453951
$this->phoneNumberUtil,
39463952
$this->appManager,
3953+
$this->userConfig,
39473954
])
39483955
->onlyMethods(['getUserData'])
39493956
->getMock();

lib/private/L10N/Factory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99
namespace OC\L10N;
1010

11+
use OC\Core\AppInfo\ConfigLexicon;
1112
use OCP\App\AppPathNotFoundException;
1213
use OCP\App\IAppManager;
14+
use OCP\Config\IUserConfig;
1315
use OCP\ICache;
1416
use OCP\ICacheFactory;
1517
use OCP\IConfig;
@@ -71,6 +73,7 @@ class Factory implements IFactory {
7173
];
7274

7375
private ICache $cache;
76+
private IUserConfig $userConfig;
7477

7578
public function __construct(
7679
protected IConfig $config,
@@ -200,7 +203,8 @@ public function findLanguage(?string $appId = null): string {
200203
// Try to get the language from the Request
201204
$lang = $this->getLanguageFromRequest($appId);
202205
if ($userId !== null && $appId === null && !$userLang) {
203-
$this->config->setUserValue($userId, 'core', 'lang', $lang);
206+
$userConfig = \OCP\Server::get(IUserConfig::class);
207+
$userConfig->setValueString($userId, 'core', ConfigLexicon::USER_LANGUAGE, $lang);
204208
}
205209
return $lang;
206210
} catch (LanguageNotFoundException $e) {

0 commit comments

Comments
 (0)