Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -81,6 +83,7 @@ public function __construct(
private IEventDispatcher $eventDispatcher,
private IPhoneNumberUtil $phoneNumberUtil,
private IAppManager $appManager,
private readonly IUserConfig $userConfig,
) {
parent::__construct(
$appName,
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -114,6 +117,7 @@ protected function setUp(): void {
$this->eventDispatcher,
$this->phoneNumberUtil,
$this->appManager,
$this->userConfig,
])
->onlyMethods(['fillStorageInfo'])
->getMock();
Expand Down Expand Up @@ -506,6 +510,7 @@ public function testAddUserSuccessfulWithDisplayName(): void {
$this->eventDispatcher,
$this->phoneNumberUtil,
$this->appManager,
$this->userConfig,
])
->onlyMethods(['editUser'])
->getMock();
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -3850,6 +3855,7 @@ public function testGetCurrentUserLoggedIn(): void {
$this->eventDispatcher,
$this->phoneNumberUtil,
$this->appManager,
$this->userConfig,
])
->onlyMethods(['getUserData'])
->getMock();
Expand Down Expand Up @@ -3944,6 +3950,7 @@ public function testGetUser(): void {
$this->eventDispatcher,
$this->phoneNumberUtil,
$this->appManager,
$this->userConfig,
])
->onlyMethods(['getUserData'])
->getMock();
Expand Down
6 changes: 5 additions & 1 deletion lib/private/L10N/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,6 +73,7 @@ class Factory implements IFactory {
];

private ICache $cache;
private IUserConfig $userConfig;

public function __construct(
protected IConfig $config,
Expand Down Expand Up @@ -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) {
Expand Down
Loading