IDEMPIERE-5888 Login Preferences are created on System tenant (#2140)

- Fix an issue causing that SuperUser (or users with several tenants) are not saving correctly preferences
This commit is contained in:
Carlos Ruiz 2023-12-14 09:21:31 +01:00 committed by GitHub
parent 4358d228e6
commit bbb5aa8562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 11 deletions

View File

@ -493,11 +493,15 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
{
lstRole.getItems().clear();
lstRole.setText("");
setUserID();
UserPreference userPreference = SessionManager.getSessionApplication().getUserPreference();
Comboitem lstItemClient = lstClient.getSelectedItem();
if (lstItemClient != null)
{
if (lstClient.getChildren().size() > 1) // load the preference was postponed until client selected
userPreference.loadPreference(Env.getContextAsInt(m_ctx, Env.AD_USER_ID));
// initial role
UserPreference userPreference = SessionManager.getSessionApplication().getUserPreference();
String initDefault = userPreference.getProperty(UserPreference.P_ROLE);
if( initDefault.length() == 0 && !m_showRolePanel && m_userpreference != null )
{
@ -536,9 +540,28 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
lstRole.setEnabled(true);
}
}
setUserID();
updateOrganisationList();
updateLanguage();
if (lstClient.getChildren().size() > 1) {
userPreference.loadPreference(Env.getContextAsInt(m_ctx, Env.AD_USER_ID));
// saving the preferences was postponed until the user selects the client
Comboitem lstItemRole = lstRole.getSelectedItem();
Comboitem lstItemOrg = lstOrganisation.getSelectedItem();
Comboitem lstItemWarehouse = lstWarehouse.getSelectedItem();
Comboitem lstItemLanguage = lstLanguage.getSelectedItem();
if (lstItemLanguage != null && lstItemLanguage.getValue() != null)
userPreference.setProperty(UserPreference.P_LANGUAGE, (String) lstItemLanguage.getValue());
else
userPreference.setProperty(UserPreference.P_LANGUAGE, Env.getContext(m_ctx, UserPreference.LANGUAGE_NAME));
if (lstItemRole != null && lstItemRole.getValue() != null)
userPreference.setProperty(UserPreference.P_ROLE, (String) lstItemRole.getValue());
userPreference.setProperty(UserPreference.P_CLIENT, (String) lstItemClient.getValue());
if (lstItemOrg != null && lstItemOrg.getValue() != null)
userPreference.setProperty(UserPreference.P_ORG, (String) lstItemOrg.getValue());
if (lstItemWarehouse != null && lstItemWarehouse.getValue() != null)
userPreference.setProperty(UserPreference.P_WAREHOUSE, (String) lstItemWarehouse.getValue());
userPreference.savePreference();
}
}
private void updateLanguage()
@ -692,7 +715,6 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
lstWarehouse.setSelectedItem(ci);
}
if (lstWarehouse.getSelectedIndex() == -1 && lstWarehouse.getItemCount() > 0) {
m_showRolePanel = true; // didn't find default warehouse
lstWarehouse.setSelectedIndex(0);
}
}
@ -868,7 +890,7 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
if (lstItemLanguage != null && lstItemLanguage.getValue() != null)
userPreference.setProperty(UserPreference.P_LANGUAGE, (String) lstItemLanguage.getValue());
else
userPreference.setProperty(UserPreference.P_LANGUAGE, Env.getContext(m_ctx, UserPreference.LANGUAGE_NAME));
userPreference.setProperty(UserPreference.P_LANGUAGE, Env.getContext(m_ctx, UserPreference.LANGUAGE_NAME));
userPreference.setProperty(UserPreference.P_ROLE, (String) lstItemRole.getValue());
userPreference.setProperty(UserPreference.P_CLIENT, (String) lstItemClient.getValue());
userPreference.setProperty(UserPreference.P_ORG, (String) lstItemOrg.getValue());

View File

@ -124,13 +124,15 @@ public final class UserPreference implements Serializable {
preference.setAD_User_ID(m_AD_User_ID);
preference.setAttribute(attribute);
}
try {
PO.setCrossTenantSafe();
preference.setValue(value);
preference.saveEx();
} finally {
PO.clearCrossTenantSafe();
String oldValue = preference.getValue();
if (! oldValue.equals(value)) {
try {
PO.setCrossTenantSafe();
preference.setValue(value);
preference.saveEx();
} finally {
PO.clearCrossTenantSafe();
}
}
}
}