diff --git a/migration/i7.1/oracle/202004051844_IDEMPIERE-2869.sql b/migration/i7.1/oracle/202004051844_IDEMPIERE-2869.sql new file mode 100644 index 0000000000..d113b7d789 --- /dev/null +++ b/migration/i7.1/oracle/202004051844_IDEMPIERE-2869.sql @@ -0,0 +1,15 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-2869 +-- Apr 5, 2020, 6:40:35 PM CEST +UPDATE AD_Field SET IsActive='N', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2020-04-05 18:40:35','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=6429 +; + +-- Apr 5, 2020, 6:42:56 PM CEST +UPDATE AD_Field SET IsActive='N', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2020-04-05 18:42:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=2291 +; + +SELECT register_migration_script('202004051844_IDEMPIERE-2869.sql') FROM dual +; + diff --git a/migration/i7.1/postgresql/202004051844_IDEMPIERE-2869.sql b/migration/i7.1/postgresql/202004051844_IDEMPIERE-2869.sql new file mode 100644 index 0000000000..d52096f097 --- /dev/null +++ b/migration/i7.1/postgresql/202004051844_IDEMPIERE-2869.sql @@ -0,0 +1,12 @@ +-- IDEMPIERE-2869 +-- Apr 5, 2020, 6:40:35 PM CEST +UPDATE AD_Field SET IsActive='N', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2020-04-05 18:40:35','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=6429 +; + +-- Apr 5, 2020, 6:42:56 PM CEST +UPDATE AD_Field SET IsActive='N', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2020-04-05 18:42:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=2291 +; + +SELECT register_migration_script('202004051844_IDEMPIERE-2869.sql') FROM dual +; + diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java index f5b7039bf2..c467bf5855 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java @@ -18,9 +18,8 @@ package org.adempiere.webui; import java.lang.ref.WeakReference; -import java.util.HashMap; +import java.util.Enumeration; import java.util.Locale; -import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -61,6 +60,7 @@ import org.zkoss.web.servlet.Servlets; import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.Page; import org.zkoss.zk.ui.Session; import org.zkoss.zk.ui.event.ClientInfoEvent; import org.zkoss.zk.ui.event.Event; @@ -86,8 +86,6 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb */ private static final long serialVersionUID = -6725805283410008847L; - private static final String SAVED_CONTEXT = "saved.context"; - public static final String APPLICATION_DESKTOP_KEY = "application.desktop"; public static String APP_NAME = null; @@ -139,13 +137,6 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb SessionManager.setSessionApplication(this); Session session = Executions.getCurrent().getDesktop().getSession(); - @SuppressWarnings("unchecked") - Mapmap = (Map) session.removeAttribute(SAVED_CONTEXT); - if (map != null && !map.isEmpty()) - { - onChangeRole(map); - return; - } Properties ctx = Env.getCtx(); langSession = Env.getContext(ctx, Env.LANGUAGE); @@ -493,14 +484,11 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb } - private void onChangeRole(Map map) { - Locale locale = (Locale) map.get("locale"); - Properties properties = (Properties) map.get("context"); - + private void onChangeRole(Locale locale, Properties context) { SessionManager.setSessionApplication(this); loginDesktop = new WLogin(this); loginDesktop.createPart(this.getPage()); - loginDesktop.changeRole(locale, properties); + loginDesktop.changeRole(locale, context); loginDesktop.getComponent().getRoot().addEventListener(Events.ON_CLIENT_INFO, this); } @@ -541,28 +529,44 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb Desktop desktop = Executions.getCurrent().getDesktop(); Locale locale = (Locale) desktop.getSession().getAttribute(Attributes.PREFERRED_LOCALE); HttpServletRequest httpRequest = (HttpServletRequest) Executions.getCurrent().getNativeRequest(); + Env.setContext(properties, SessionContextListener.SERVLET_SESSION_ID, httpRequest.getSession().getId()); - if (desktop.isServerPushEnabled()) - desktop.enableServerPush(false); - logout0(); + //stop key listener + if (keyListener != null) { + keyListener.detach(); + keyListener = null; + } - //clear context - Env.getCtx().clear(); - - //invalidate session - httpRequest.getSession(false).invalidate(); - desktop.setAttribute(DESKTOP_SESSION_INVALIDATED_ATTR, Boolean.TRUE); + //desktop cleanup + IDesktop appDesktop = getAppDeskop(); + if (appDesktop != null) + appDesktop.logout(); + + //remove all children component + getChildren().clear(); - //put saved context into new session - Map map = new HashMap(); - map.put("context", properties); - map.put("locale", locale); + //remove all root components except this + Page page = getPage(); + page.removeComponents(); + this.setPage(page); + + //clear session attributes + Enumeration attributes = httpRequest.getSession().getAttributeNames(); + while(attributes.hasMoreElements()) { + String attribute = attributes.nextElement(); + + //need to keep zk's session attributes + if (attribute.contains("zkoss.")) + continue; + + httpRequest.getSession().removeAttribute(attribute); + } + + //logout ad_session + AEnv.logout(); - HttpSession newSession = httpRequest.getSession(true); - newSession.setAttribute(SAVED_CONTEXT, map); - properties.setProperty(SessionContextListener.SERVLET_SESSION_ID, newSession.getId()); - - Executions.getCurrent().sendRedirect("index.zul"); + //show change role window and set new context for env and session + onChangeRole(locale, properties); } @Override diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/WLogin.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/WLogin.java index a6d6aa9fce..2980055356 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/WLogin.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/WLogin.java @@ -135,6 +135,11 @@ public class WLogin extends AbstractUIPart return layout; } + /** + * Show change role window + * @param locale + * @param properties env context + */ public void changeRole(Locale locale, Properties properties) { loginWindow.changeRole(locale, properties); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java index 1ea8f20ad0..0f3f5083f3 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java @@ -583,8 +583,13 @@ public class RolePanel extends Window implements EventListener, Deferrabl } } + /** + * show UI for change role + * @param ctx env context + */ public void changeRole(Properties ctx) { - ctxBeforeChangeRole = ctx; + ctxBeforeChangeRole = new Properties(); + ctxBeforeChangeRole.putAll(ctx); int AD_Client_ID = Env.getAD_Client_ID(ctx); lstClient.setValue(AD_Client_ID); updateRoleList(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/UserPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/UserPanel.java index 2093fc4e48..5926392ab2 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/UserPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/UserPanel.java @@ -224,12 +224,12 @@ public class UserPanel implements EventListener, Composer { if (result) { - Events.echoEvent(ON_DEFER_CHANGE_ROLE, component, null); + Events.postEvent(ON_DEFER_CHANGE_ROLE, component, null); } } }); } else { - Events.echoEvent(ON_DEFER_CHANGE_ROLE, component, null); + Events.postEvent(ON_DEFER_CHANGE_ROLE, component, null); } } else if (preference == event.getTarget()) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/LoginWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/LoginWindow.java index fd89c8c463..969ef43472 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/LoginWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/LoginWindow.java @@ -32,6 +32,7 @@ import org.adempiere.webui.panel.ChangePasswordPanel; import org.adempiere.webui.panel.LoginPanel; import org.adempiere.webui.panel.ResetPasswordPanel; import org.adempiere.webui.panel.RolePanel; +import org.adempiere.webui.session.SessionContextListener; import org.adempiere.webui.theme.ThemeManager; import org.compiere.model.MSysConfig; import org.compiere.model.MUser; @@ -180,9 +181,15 @@ public class LoginWindow extends FWindow implements EventListener } } + /** + * Show change role window + * @param locale + * @param ctx + */ public void changeRole(Locale locale, Properties ctx) { Env.setCtx(ctx); + getDesktop().getSession().setAttribute(SessionContextListener.SESSION_CTX, ctx); //reload theme preference PageDefinition pageDefintion = Executions.getCurrent().getPageDefinition(ThemeManager.getThemeResource("preference.zul")); diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java index 00d62745b2..f49b979afa 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java @@ -345,8 +345,10 @@ public class Process { try { processOK = process.processIt(pi, trx, false); - if (trxName == null) - trx.commit(); + if (trxName == null && processOK) + trx.commit(); + else if (trxName == null && !processOK) + trx.rollback(); } catch (Throwable t) {