Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(SetUserTimezoneCommand): only write user login timezone if not ye…
…t set

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Aug 18, 2025
commit ac545cc47872bbc79fcdb03c1e78f63fbf2d4e5f
12 changes: 6 additions & 6 deletions lib/private/Authentication/Login/SetUserTimezoneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
namespace OC\Authentication\Login;

use OC\Core\AppInfo\Application;
use OC\Core\AppInfo\ConfigLexicon;
use OCP\IConfig;
use OCP\ISession;

Expand All @@ -26,12 +28,10 @@ public function __construct(IConfig $config,

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()
Expand Down
44 changes: 40 additions & 4 deletions tests/lib/Authentication/Login/SetUserTimezoneCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
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();
Expand Down Expand Up @@ -50,6 +49,15 @@ public function testProcess(): void {
$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(
Expand All @@ -69,4 +77,32 @@ public function testProcess(): void {

$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());
}
}