Skip to content

Commit f932df2

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

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
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: 6 additions & 0 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;
@@ -88,6 +89,7 @@ protected function setUp(): void {
8889
$this->phoneNumberUtil = new PhoneNumberUtil();
8990
$this->appManager = $this->createMock(IAppManager::class);
9091
$this->rootFolder = $this->createMock(IRootFolder::class);
92+
$this->userConfig = $this->createMock(IUserConfig::class);
9193

9294
$l10n = $this->createMock(IL10N::class);
9395
$l10n->method('t')->willReturnCallback(fn (string $txt, array $replacement = []) => sprintf($txt, ...$replacement));
@@ -114,6 +116,7 @@ protected function setUp(): void {
114116
$this->eventDispatcher,
115117
$this->phoneNumberUtil,
116118
$this->appManager,
119+
$this->userConfig,
117120
])
118121
->onlyMethods(['fillStorageInfo'])
119122
->getMock();
@@ -506,6 +509,7 @@ public function testAddUserSuccessfulWithDisplayName(): void {
506509
$this->eventDispatcher,
507510
$this->phoneNumberUtil,
508511
$this->appManager,
512+
$this->userConfig,
509513
])
510514
->onlyMethods(['editUser'])
511515
->getMock();
@@ -3850,6 +3854,7 @@ public function testGetCurrentUserLoggedIn(): void {
38503854
$this->eventDispatcher,
38513855
$this->phoneNumberUtil,
38523856
$this->appManager,
3857+
$this->userConfig,
38533858
])
38543859
->onlyMethods(['getUserData'])
38553860
->getMock();
@@ -3944,6 +3949,7 @@ public function testGetUser(): void {
39443949
$this->eventDispatcher,
39453950
$this->phoneNumberUtil,
39463951
$this->appManager,
3952+
$this->userConfig,
39473953
])
39483954
->onlyMethods(['getUserData'])
39493955
->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)