[Legacy] Load new preferences if not same user

This commit is contained in:
Jack Anderson 2024-08-21 15:31:35 +01:00
parent 70b442a613
commit 1de29d158d

View file

@ -98,10 +98,15 @@ class UserPreference extends SugarBean
$name, $name,
$category = 'global' $category = 'global'
) { ) {
global $sugar_config; global $sugar_config, $current_user;
$user = $this->_userFocus; $user = $this->_userFocus;
if ($user->user_name !== $current_user->user_name){
$this->loadPreferences($category);
return $user->user_preferences[$category][$name] ?? $this->getDefaultPreference($name, $category);
}
// if the unique key in session doesn't match the app or prefereces are empty // if the unique key in session doesn't match the app or prefereces are empty
if (!isset($_SESSION[$user->user_name.'_PREFERENCES'][$category]) || (!empty($_SESSION['unique_key']) && $_SESSION['unique_key'] != $sugar_config['unique_key'])) { if (!isset($_SESSION[$user->user_name.'_PREFERENCES'][$category]) || (!empty($_SESSION['unique_key']) && $_SESSION['unique_key'] != $sugar_config['unique_key'])) {
$this->loadPreferences($category); $this->loadPreferences($category);
@ -203,13 +208,18 @@ class UserPreference extends SugarBean
public function loadPreferences( public function loadPreferences(
$category = 'global' $category = 'global'
) { ) {
global $sugar_config; global $sugar_config, $current_user;
$user = $this->_userFocus; $user = $this->_userFocus;
if ($user->object_name != 'User') { if ($user->object_name != 'User') {
return; return;
} }
if ($user->user_name !== $current_user->user_name) {
return $this->reloadPreferences($category);
}
if (!empty($user->id) && (!isset($_SESSION[$user->user_name . '_PREFERENCES'][$category]) || (!empty($_SESSION['unique_key']) && $_SESSION['unique_key'] != $sugar_config['unique_key']))) { if (!empty($user->id) && (!isset($_SESSION[$user->user_name . '_PREFERENCES'][$category]) || (!empty($_SESSION['unique_key']) && $_SESSION['unique_key'] != $sugar_config['unique_key']))) {
// cn: moving this to only log when valid - throwing errors on install // cn: moving this to only log when valid - throwing errors on install
return $this->reloadPreferences($category); return $this->reloadPreferences($category);