From e83bb49935b66cf77df4e549182449f68c72a658 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sun, 22 Oct 2023 11:33:19 +0200 Subject: [PATCH] IDEMPIERE-5888 Login Preferences are created on System tenant (#2067) * IDEMPIERE-5888 Login Preferences are created on System tenant * - migration script to fix the current data --- migration/iD10/oracle/202310191513_IDEMPIERE-5888.sql | 11 +++++++++++ .../iD10/postgresql/202310191513_IDEMPIERE-5888.sql | 11 +++++++++++ .../src/org/adempiere/webui/util/MUserPreference.java | 2 ++ .../src/org/adempiere/webui/util/UserPreference.java | 10 +++++----- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 migration/iD10/oracle/202310191513_IDEMPIERE-5888.sql create mode 100644 migration/iD10/postgresql/202310191513_IDEMPIERE-5888.sql diff --git a/migration/iD10/oracle/202310191513_IDEMPIERE-5888.sql b/migration/iD10/oracle/202310191513_IDEMPIERE-5888.sql new file mode 100644 index 0000000000..d3e86fbcfc --- /dev/null +++ b/migration/iD10/oracle/202310191513_IDEMPIERE-5888.sql @@ -0,0 +1,11 @@ +-- IDEMPIERE-5888 Login Preferences are created on System tenant +SELECT register_migration_script('202310191513_IDEMPIERE-5888.sql') FROM dual; + +-- 19/10/2023, 3:13:51 p. m. GMT+02:00 +UPDATE AD_Preference +SET AD_Client_ID=(SELECT AD_Client_ID FROM AD_User WHERE AD_User_ID=AD_Preference.AD_User_ID), + AD_Org_ID=0 +WHERE AD_Client_ID!=(SELECT AD_Client_ID FROM AD_User WHERE AD_User_ID=AD_Preference.AD_User_ID) + AND Attribute IN ('Language','Role','Client','Organization','Warehouse') +; + diff --git a/migration/iD10/postgresql/202310191513_IDEMPIERE-5888.sql b/migration/iD10/postgresql/202310191513_IDEMPIERE-5888.sql new file mode 100644 index 0000000000..d3e86fbcfc --- /dev/null +++ b/migration/iD10/postgresql/202310191513_IDEMPIERE-5888.sql @@ -0,0 +1,11 @@ +-- IDEMPIERE-5888 Login Preferences are created on System tenant +SELECT register_migration_script('202310191513_IDEMPIERE-5888.sql') FROM dual; + +-- 19/10/2023, 3:13:51 p. m. GMT+02:00 +UPDATE AD_Preference +SET AD_Client_ID=(SELECT AD_Client_ID FROM AD_User WHERE AD_User_ID=AD_Preference.AD_User_ID), + AD_Org_ID=0 +WHERE AD_Client_ID!=(SELECT AD_Client_ID FROM AD_User WHERE AD_User_ID=AD_Preference.AD_User_ID) + AND Attribute IN ('Language','Role','Client','Organization','Warehouse') +; + diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/MUserPreference.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/MUserPreference.java index ed1259629e..5248147f8f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/MUserPreference.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/MUserPreference.java @@ -21,7 +21,9 @@ import org.compiere.model.MPreference; * * @author hengsin * + * @deprecated - is not required anymore, for login preferences the client is being set now as the user client */ +@Deprecated public class MUserPreference extends MPreference { private static final long serialVersionUID = -3424015890197944847L; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/UserPreference.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/UserPreference.java index c155b76ad1..14d8b5d19f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/UserPreference.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/UserPreference.java @@ -18,6 +18,7 @@ import java.util.Properties; import org.compiere.model.I_AD_Preference; import org.compiere.model.MPreference; +import org.compiere.model.MUser; import org.compiere.model.PO; import org.compiere.model.Query; import org.compiere.util.CLogger; @@ -114,13 +115,12 @@ public final class UserPreference implements Serializable { if (!Util.isEmpty(value)) { MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute}).firstOnly(); if (preference == null) { - preference = new MUserPreference(Env.getCtx(), 0, null); + preference = new MPreference(Env.getCtx(), 0, null); + MUser user = MUser.get(m_AD_User_ID); + preference.set_ValueNoCheck("AD_Client_ID", user.getAD_Client_ID()); + preference.setAD_Org_ID(0); preference.setAD_User_ID(m_AD_User_ID); preference.setAttribute(attribute); - } else { - if (preference.getAD_Client_ID() > 0 || preference.getAD_Org_ID() > 0) { - preference = new MUserPreference(Env.getCtx(), preference.getAD_Preference_ID(), null); - } } try {