fix(SetUserTimezoneCommand): only write user login timezone if not yet set

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/54470/head
Ferdinand Thiessen 5 months ago
parent 0dd8e5e32e
commit ac545cc478
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
  1. 12
      lib/private/Authentication/Login/SetUserTimezoneCommand.php
  2. 44
      tests/lib/Authentication/Login/SetUserTimezoneCommandTest.php

@ -8,6 +8,8 @@ declare(strict_types=1);
*/
namespace OC\Authentication\Login;
use OC\Core\AppInfo\Application;
use OC\Core\AppInfo\ConfigLexicon;
use OCP\IConfig;
use OCP\ISession;
@ -26,12 +28,10 @@ class SetUserTimezoneCommand extends ALoginCommand {
public function process(LoginData $loginData): LoginResult {
if ($loginData->getTimeZoneOffset() !== '' && $this->isValidTimezone($loginData->getTimeZone())) {
$this->config->setUserValue(
$loginData->getUser()->getUID(),
'core',
'timezone',
$loginData->getTimeZone()
);
$userId = $loginData->getUser()->getUID();
if ($this->config->getUserValue($userId, Application::APP_ID, ConfigLexicon::USER_TIMEZONE, '') === '') {
$this->config->setUserValue($userId, Application::APP_ID, ConfigLexicon::USER_TIMEZONE, $loginData->getTimeZone());
}
$this->session->set(
'timezone',
$loginData->getTimeZoneOffset()

@ -15,11 +15,10 @@ use OCP\ISession;
use PHPUnit\Framework\MockObject\MockObject;
class SetUserTimezoneCommandTest extends ALoginTestCommand {
/** @var IConfig|MockObject */
private $config;
/** @var ISession|MockObject */
private $session;
private IConfig&MockObject $config;
private ISession&MockObject $session;
protected function setUp(): void {
parent::setUp();
@ -50,6 +49,15 @@ class SetUserTimezoneCommandTest extends ALoginTestCommand {
$this->user->expects($this->once())
->method('getUID')
->willReturn($this->username);
$this->config->expects($this->once())
->method('getUserValue')
->with(
$this->username,
'core',
'timezone',
''
)
->willReturn('');
$this->config->expects($this->once())
->method('setUserValue')
->with(
@ -69,4 +77,32 @@ class SetUserTimezoneCommandTest extends ALoginTestCommand {
$this->assertTrue($result->isSuccess());
}
public function testProcessAlreadySet(): void {
$data = $this->getLoggedInLoginDataWithTimezone();
$this->user->expects($this->once())
->method('getUID')
->willReturn($this->username);
$this->config->expects($this->once())
->method('getUserValue')
->with(
$this->username,
'core',
'timezone',
'',
)
->willReturn('Europe/Berlin');
$this->config->expects($this->never())
->method('setUserValue');
$this->session->expects($this->once())
->method('set')
->with(
'timezone',
$this->timeZoneOffset
);
$result = $this->cmd->process($data);
$this->assertTrue($result->isSuccess());
}
}

Loading…
Cancel
Save