IDEMPIERE-4386 setAD_User_ID() breaks when logged in as System user (#188)

* IDEMPIERE-4386 setAD_User_ID() breaks when logged in as System user

Allow saving Tab Customization for System user

* IDEMPIERE-4386 setAD_User_ID() breaks when logged in as System user

Fix copy/paste error

* IDEMPIERE-4386 setAD_User_ID() breaks when logged in as System user

Implement same suggestion on all the classes where setAD_User_ID must be allowed to explicitly set to System
There were already two classes with the Override approach: MUserPreference and MUserRoles, so this commit is to apply the same approach to all the classes with same approach
This commit is contained in:
Carlos Ruiz 2020-08-13 12:20:59 +02:00 committed by GitHub
parent 24e9fe8402
commit 7892c54aa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 112 additions and 32 deletions

View File

@ -11,7 +11,7 @@ public class MTabCustomization extends X_AD_Tab_Customization {
/**
*
*/
private static final long serialVersionUID = 786885789239156678L;
private static final long serialVersionUID = -4986336833193761507L;
public MTabCustomization(Properties ctx, int AD_Tab_Customization_ID, String trxName) {
super(ctx, AD_Tab_Customization_ID, trxName);
@ -85,4 +85,18 @@ public class MTabCustomization extends X_AD_Tab_Customization {
return tabCust.save();
} // saveTabCustomization
/** Set User/Contact.
@param AD_User_ID
User within the system - Internal or Business Partner Contact
Overridden to allow saving System record (zero ID)
*/
@Override
public void setAD_User_ID (int AD_User_ID)
{
if (AD_User_ID == 0)
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
else
super.setAD_User_ID(AD_User_ID);
} //setAD_User_ID
}

View File

@ -31,7 +31,7 @@ public class MDashboardPreference extends X_PA_DashboardPreference
/**
*
*/
private static final long serialVersionUID = 7568476952229922042L;
private static final long serialVersionUID = -3887344231734476767L;
public static int getForSessionColumnCount(boolean isShowInDashboard, int AD_User_ID, int AD_Role_ID)
{
@ -104,4 +104,19 @@ public class MDashboardPreference extends X_PA_DashboardPreference
{
super (ctx, rs, trxName);
}
/** Set User/Contact.
@param AD_User_ID
User within the system - Internal or Business Partner Contact
Overridden to allow saving System record (zero ID)
*/
@Override
public void setAD_User_ID (int AD_User_ID)
{
if (AD_User_ID == 0)
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
else
super.setAD_User_ID(AD_User_ID);
} //setAD_User_ID
}

View File

@ -11,7 +11,7 @@ public class MPasswordHistory extends X_AD_Password_History {
/**
*
*/
private static final long serialVersionUID = 8602148028134601856L;
private static final long serialVersionUID = -571685945938727000L;
public MPasswordHistory(Properties ctx, int AD_Password_History_ID,
String trxName) {
@ -49,4 +49,20 @@ public class MPasswordHistory extends X_AD_Password_History {
return query.list();
}
/** Set User/Contact.
@param AD_User_ID
User within the system - Internal or Business Partner Contact
Overridden to allow saving System record (zero ID)
http://wiki.idempiere.org/en/System_user
*/
@Override
public void setAD_User_ID (int AD_User_ID)
{
if (AD_User_ID == 0)
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
else
super.setAD_User_ID(AD_User_ID);
} //setAD_User_ID
}

View File

@ -30,7 +30,8 @@ public class MPreference extends X_AD_Preference
/**
*
*/
private static final long serialVersionUID = -5098559160325123593L;
private static final long serialVersionUID = -8935876328996934527L;
/** Null Indicator */
public static String NULL = "null";
@ -103,5 +104,19 @@ public class MPreference extends X_AD_Preference
.append ("]");
return sb.toString ();
} // toString
/** Set User/Contact.
@param AD_User_ID
User within the system - Internal or Business Partner Contact
Overridden to allow saving System record (zero ID)
*/
@Override
public void setAD_User_ID (int AD_User_ID)
{
if (AD_User_ID == 0)
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
else
super.setAD_User_ID(AD_User_ID);
} //setAD_User_ID
} // MPreference

View File

@ -1092,12 +1092,7 @@ public class MUser extends X_AD_User
MPasswordHistory passwordHistory = new MPasswordHistory(this.getCtx(), 0, this.get_TrxName());
passwordHistory.setSalt(this.getSalt());
passwordHistory.setPassword(this.getPassword());
// http://wiki.idempiere.org/en/System_user
if (!this.is_new() && this.getAD_User_ID() == 0){
passwordHistory.set_Value(MPasswordHistory.COLUMNNAME_AD_User_ID, 0);
}else{
passwordHistory.setAD_User_ID(this.getAD_User_ID());
}
passwordHistory.setAD_User_ID(this.getAD_User_ID());
passwordHistory.setDatePasswordChanged(this.getUpdated());
passwordHistory.saveEx();
}

View File

@ -46,7 +46,13 @@ public class MUserPreference extends X_AD_UserPreference{
{
super(ctx, rs, trxName);
} //MUserPreference
/** Set User/Contact.
@param AD_User_ID
User within the system - Internal or Business Partner Contact
Overridden to allow saving System record (zero ID)
*/
@Override
public void setAD_User_ID (int AD_User_ID)
{
if (AD_User_ID == 0)
@ -54,7 +60,7 @@ public class MUserPreference extends X_AD_UserPreference{
else
super.setAD_User_ID(AD_User_ID);
} //setAD_User_ID
private static MUserPreference createUserPreferences(int AD_User_ID, int AD_Client_ID, String trxName){
MUserPreference preferences = new MUserPreference(Env.getCtx(), 0, trxName);
preferences.setAD_User_ID(AD_User_ID);

View File

@ -38,7 +38,7 @@ public class MUserQuery extends X_AD_UserQuery
/**
*
*/
private static final long serialVersionUID = -5640578235804864422L;
private static final long serialVersionUID = 488522350853249825L;
/**
* Get all active queries of client for Tab
@ -336,4 +336,18 @@ public class MUserQuery extends X_AD_UserQuery
return true;
}
/** Set User/Contact.
@param AD_User_ID
User within the system - Internal or Business Partner Contact
Overridden to allow saving System record (zero ID)
*/
@Override
public void setAD_User_ID (int AD_User_ID)
{
if (AD_User_ID == 0)
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
else
super.setAD_User_ID(AD_User_ID);
} //setAD_User_ID
} // MUserQuery

View File

@ -112,22 +112,27 @@ public class MUserRoles extends X_AD_User_Roles
setAD_User_ID(AD_User_ID);
setAD_Role_ID(AD_Role_ID);
} // MUserRoles
/**
* Set User/Contact.
* User within the system - Internal or Business Partner Contact
* @param AD_User_ID user
/** Set User/Contact.
@param AD_User_ID
User within the system - Internal or Business Partner Contact
Overridden to allow saving System record (zero ID)
*/
@Override
public void setAD_User_ID (int AD_User_ID)
{
set_ValueNoCheck ("AD_User_ID", Integer.valueOf(AD_User_ID));
} // setAD_User_ID
if (AD_User_ID == 0)
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
else
super.setAD_User_ID(AD_User_ID);
} //setAD_User_ID
/**
* Set Role.
* Responsibility Role
* @param AD_Role_ID role
**/
@Override
public void setAD_Role_ID (int AD_Role_ID)
{
set_ValueNoCheck ("AD_Role_ID", Integer.valueOf(AD_Role_ID));

View File

@ -1276,7 +1276,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
if (preference == null || preference.getAD_Preference_ID() <= 0) {
preference = new MPreference(Env.getCtx(), 0, null);
preference.setAD_Window_ID(windowId);
preference.set_ValueOfColumn("AD_User_ID", userId); // required set_Value for System=0 user
preference.setAD_User_ID(userId); // allow System
preference.setAttribute(adTabId+"|DetailPane.IsOpen");
}
preference.setValue(value ? "Y" : "N");
@ -1971,7 +1971,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
if (preference == null || preference.getAD_Preference_ID() <= 0) {
preference = new MPreference(Env.getCtx(), 0, null);
preference.setAD_Window_ID(windowId);
preference.set_ValueOfColumn("AD_User_ID", userId); // required set_Value for System=0 user
preference.setAD_User_ID(userId);
preference.setAttribute(adTabId+"|"+attribute);
}
preference.setValue(value);

View File

@ -655,7 +655,7 @@ public class DashboardController implements EventListener<Event> {
MDashboardPreference preference = new MDashboardPreference(Env.getCtx(), 0, null);
preference.setAD_Org_ID(0);
preference.setAD_Role_ID(AD_Role_ID);
preference.set_ValueNoCheck("AD_User_ID", AD_User_ID);
preference.setAD_User_ID(AD_User_ID); // allow System
preference.setColumnNo(dc.getColumnNo());
preference.setIsCollapsedByDefault(dc.isCollapsedByDefault());
preference.setIsShowInDashboard(dc.isShowInDashboard());
@ -682,7 +682,7 @@ public class DashboardController implements EventListener<Event> {
MDashboardPreference preference = new MDashboardPreference(ctx,0, null);
preference.setAD_Org_ID(0);
preference.setAD_Role_ID(Env.getAD_Role_ID(ctx));
preference.set_ValueNoCheck("AD_User_ID",Env.getAD_User_ID(ctx));
preference.setAD_User_ID(Env.getAD_User_ID(ctx)); // allow System
preference.setColumnNo(dcs[i].getColumnNo());
preference.setIsCollapsedByDefault(dcs[i].isCollapsedByDefault());
preference.setIsShowInDashboard(dcs[i].isShowInDashboard());

View File

@ -469,7 +469,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
if ( preference == null || preference.getAD_Preference_ID() <= 0 ) {
preference = new MPreference(Env.getCtx(), 0, null);
preference.set_ValueOfColumn("AD_User_ID", userId); // required set_Value for System=0 user
preference.setAD_User_ID(userId); // allow System
preference.setAttribute("SideController.Width");
}
preference.setValue(width);
@ -512,7 +512,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
if ( preference == null || preference.getAD_Preference_ID() <= 0 ) {
preference = new MPreference(Env.getCtx(), 0, null);
preference.set_ValueOfColumn("AD_User_ID", userId); // required set_Value for System=0 user
preference.setAD_User_ID(userId); // allow System
preference.setAttribute("HelpController.Width");
}
preference.setValue(width);

View File

@ -1832,10 +1832,10 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
uq = new MUserQuery (Env.getCtx(), 0, null);
uq.setName (name);
uq.setAD_Tab_ID(m_AD_Tab_ID); //red1 UserQuery [ 1798539 ] taking in new field from Compiere
uq.set_ValueOfColumn("AD_User_ID", Env.getAD_User_ID(Env.getCtx())); // required set_Value for System=0 user
uq.setAD_User_ID(Env.getAD_User_ID(Env.getCtx())); // allow System
}
if (shareAllUsers)
uq.set_ValueOfColumn("AD_User_ID", null);
uq.setAD_User_ID(-1); // set to null
} else if (code.length() <= 0){ // Delete the query
if (uq == null)

View File

@ -395,7 +395,7 @@ public class WGadgets extends Window implements EventListener<Event>{
pre = new MDashboardPreference(Env.getCtx(), 0, null);
pre.setAD_Org_ID(0);
pre.setAD_Role_ID(AD_Role_ID);
pre.set_ValueNoCheck("AD_User_ID",AD_User_ID);
pre.setAD_User_ID(AD_User_ID); // allow System
pre.setColumnNo(content.getColumnNo());
pre.setIsCollapsedByDefault(content.isCollapsedByDefault());
pre.setIsShowInDashboard(content.isShowInDashboard());
@ -410,7 +410,7 @@ public class WGadgets extends Window implements EventListener<Event>{
pre = new MDashboardPreference(Env.getCtx(), 0, null);
pre.setAD_Org_ID(0);
pre.setAD_Role_ID(AD_Role_ID);
pre.set_ValueNoCheck("AD_User_ID",AD_User_ID);
pre.setAD_User_ID(AD_User_ID); // allow System
pre.setColumnNo(content.getColumnNo());
pre.setIsCollapsedByDefault(content.isCollapsedByDefault());
pre.setIsShowInDashboard(content.isShowInDashboard());