mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added support for user timezones and user browser timezone by default (incomplete) (#13626)
* Added support for user timezones and user browser timezone byt default * Formatting fixes * Use the timezone for alert log display also added validation for the timezone because it's being used in SQL. * Formatting fixes * Added return type * Formatting" * Update the latency graphs to use the user timezone * Simplify the web routes config * Update phpstan to ignore type error * Fixed up the phpstan config * Reverse phpstan change * Re-apply phpstan override * Remove the option to unset the session timezone * Formatting fix * Update outge and event logs to use session timezone * Fix route for the timezone control * Made the timezone more dynamic * Fix a logic error that was stopping the timezone from being set automatically on login * Prevent getPref from being called twice * again prevent getPref double call * getPref double call * Fixed typo made during merge * Fixed merge error in phpstan-baseline.neon * Change spaces to tabs in phpstan-baseline.neon * Update error count --------- Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
@@ -80,6 +80,7 @@ class UserController extends Controller
|
||||
'user' => $tmp_user,
|
||||
'dashboard' => null,
|
||||
'dashboards' => Dashboard::allAvailable($tmp_user)->get(),
|
||||
'timezone' => 'default',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -100,6 +101,7 @@ class UserController extends Controller
|
||||
$user->setPassword($request->new_password);
|
||||
$user->auth_id = (string) LegacyAuth::get()->getUserid($user->username) ?: $user->user_id;
|
||||
$this->updateDashboard($user, $request->get('dashboard'));
|
||||
$this->updateTimezone($user, $request->get('timezone'));
|
||||
|
||||
if ($user->save()) {
|
||||
$flasher->addSuccess(__('User :username created', ['username' => $user->username]));
|
||||
@@ -143,6 +145,7 @@ class UserController extends Controller
|
||||
'user' => $user,
|
||||
'dashboard' => UserPref::getPref($user, 'dashboard'),
|
||||
'dashboards' => Dashboard::allAvailable($user)->get(),
|
||||
'timezone' => UserPref::getPref($user, 'timezone') ?: 'default',
|
||||
];
|
||||
|
||||
if (Config::get('twofactor')) {
|
||||
@@ -186,6 +189,14 @@ class UserController extends Controller
|
||||
$flasher->addSuccess(__('Updated dashboard for :username', ['username' => $user->username]));
|
||||
}
|
||||
|
||||
if ($request->has('timezone') && $this->updateTimezone($user, $request->get('timezone'))) {
|
||||
if ($request->get('timezone') != 'default') {
|
||||
$flasher->addSuccess(__('Updated timezone for :username', ['username' => $user->username]));
|
||||
} else {
|
||||
$flasher->addSuccess(__('Cleared timezone for :username', ['username' => $user->username]));
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->save()) {
|
||||
$flasher->addSuccess(__('User :username updated', ['username' => $user->username]));
|
||||
|
||||
@@ -233,6 +244,35 @@ class UserController extends Controller
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $timezone
|
||||
* @return bool
|
||||
*/
|
||||
protected function updateTimezone(User $user, $timezone)
|
||||
{
|
||||
$existing = UserPref::getPref($user, 'timezone');
|
||||
if ($timezone != 'default') {
|
||||
if (! in_array($timezone, timezone_identifiers_list())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($timezone != $existing) {
|
||||
UserPref::setPref($user, 'timezone', $timezone);
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if ($existing != '') {
|
||||
UserPref::forgetPref($user, 'timezone');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function authlog()
|
||||
{
|
||||
$this->authorize('manage', User::class);
|
||||
|
||||
Reference in New Issue
Block a user