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

- Fix cross tenant issues in login because of preferences
This commit is contained in:
Carlos Ruiz 2023-11-20 06:39:20 +01:00 committed by GitHub
parent 0f6ac9e6d7
commit 83abb13877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -153,11 +153,13 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
m_isClientDefined = isClientDefined;
m_clientKNPairs = clientsKNPairs;
m_userpreference = SessionManager.getSessionApplication().getUserPreference();
if( m_clientKNPairs.length == 1 && !m_showRolePanel ){
Env.setContext(m_ctx, Env.AD_CLIENT_ID, (String) m_clientKNPairs[0].getID());
MUser user = MUser.get (m_ctx, Login.getAppUser(m_userName));
m_userpreference=new UserPreference();
m_userpreference.loadPreference(user.get_ID());
} else {
m_userpreference.loadPreference(-1);
}
initComponents();

View File

@ -38,7 +38,7 @@ public final class UserPreference implements Serializable {
/**
* generated serial id
*/
private static final long serialVersionUID = -2619860653017483658L;
private static final long serialVersionUID = -5225476997340598606L;
/** Language */
public static final String P_LANGUAGE = "Language";
@ -96,7 +96,9 @@ public final class UserPreference implements Serializable {
/** Container for Properties */
private Properties props = new Properties();
private int m_AD_User_ID;
private int m_AD_User_ID = -1;
final String whereClause = "AD_User_ID=? AND Attribute=? AND AD_Window_ID IS NULL AND AD_Process_ID IS NULL AND PreferenceFor='W' AND AD_Client_ID=(SELECT AD_Client_ID FROM AD_User WHERE AD_User_ID=?)";
/** Logger */
@SuppressWarnings("unused")
@ -107,13 +109,13 @@ public final class UserPreference implements Serializable {
*/
public void savePreference() {
if (m_AD_User_ID > 0) {
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "NVL(AD_User_ID,0) = ? AND Attribute = ? AND AD_Window_ID Is NULL AND AD_Process_ID IS NULL AND PreferenceFor = 'W'", null);
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, whereClause, null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];
String value = props.getProperty(attribute);
if (!Util.isEmpty(value)) {
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute}).firstOnly();
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute, m_AD_User_ID}).firstOnly();
if (preference == null) {
preference = new MPreference(Env.getCtx(), 0, null);
MUser user = MUser.get(m_AD_User_ID);
@ -140,17 +142,17 @@ public final class UserPreference implements Serializable {
* @param AD_User_ID
*/
public void loadPreference(int AD_User_ID) {
m_AD_User_ID = AD_User_ID;
if (AD_User_ID >= 0) {
m_AD_User_ID = AD_User_ID;
props = new Properties();
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "NVL(AD_User_ID,0) = ? AND Attribute = ? AND AD_Window_ID Is NULL AND AD_Process_ID IS NULL AND PreferenceFor = 'W'", null);
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, whereClause, null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];
String value = VALUES[i];
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute}).firstOnly();
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute, m_AD_User_ID}).firstOnly();
if (preference != null && preference.getValue() != null) {
value = preference.getValue();
}
@ -166,11 +168,11 @@ public final class UserPreference implements Serializable {
if (m_AD_User_ID > 0) {
props = new Properties();
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "AD_User_ID = ? AND Attribute = ? AND AD_Window_ID Is NULL AND AD_Process_ID IS NULL AND PreferenceFor = 'W'", null);
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, whereClause, null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute}).firstOnly();
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute, m_AD_User_ID}).firstOnly();
if (preference != null) {
preference.deleteEx(true);
}