mirror of
https://github.com/nextcloud/server.git
synced 2026-02-11 14:54:02 -05:00
fix(SetUserTimezoneCommand): only write user login timezone if not yet set
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
0dd8e5e32e
commit
ac545cc478
2 changed files with 46 additions and 10 deletions
|
|
@ -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…
Reference in a new issue