IDEMPIERE-5802 - Includes access validation for ASI Dialog (#1945)

* IDEMPIERE-5802 - Includes access validation for ASI Dialog

* IDEMPIERE-5802 - Implements use of MRole.getWindowAccess instead of Query

* IDEMPIERE-5802 - Fix name and access for 'isAllowedToCreate' variable
This commit is contained in:
Marcos Gabriel de Oliveira Favaretto 2023-07-31 23:57:52 -03:00 committed by GitHub
parent 6e0645f90c
commit f919931eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 9 deletions

View File

@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.apps.AEnv;
@ -67,6 +68,7 @@ import org.compiere.model.MLotCtl;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.MSerNoCtl;
import org.compiere.model.SystemIDs;
import org.compiere.model.MSysConfig;
import org.compiere.model.X_M_MovementLine;
import org.compiere.util.CLogger;
@ -127,7 +129,9 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
this.setShadow(true);
this.setSizable(true);
this.setMaximizable(true);
validadeRoleAccess();
if (log.isLoggable(Level.CONFIG)) log.config("M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID
+ ", M_Product_ID=" + M_Product_ID
+ ", C_BPartner_ID=" + C_BPartner_ID
@ -215,6 +219,8 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
/* SysConfig USE_ESC_FOR_TAB_CLOSING */
private boolean isUseEscForTabClosing = MSysConfig.getBooleanValue(MSysConfig.USE_ESC_FOR_TAB_CLOSING, false, Env.getAD_Client_ID(Env.getCtx()));
protected boolean isAllowedToCreateAndUpdate = false;
/**
* Layout
* @throws Exception
@ -521,22 +527,24 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
return false;
}
cbNewEdit.setEnabled(isAllowedToCreateAndUpdate);
// New/Edit Window
if (!m_productWindow)
{
cbNewEdit.setChecked(m_M_AttributeSetInstance_ID == 0);
cbNewEdit.setChecked(m_M_AttributeSetInstance_ID == 0 && isAllowedToCreateAndUpdate);
cmd_newEdit();
}
else
{
cbNewEdit.setSelected(false);
cbNewEdit.setEnabled(m_M_AttributeSetInstance_ID > 0);
bNewRecord.setEnabled(m_M_AttributeSetInstance_ID > 0);
cbNewEdit.setEnabled(m_M_AttributeSetInstance_ID > 0 && isAllowedToCreateAndUpdate);
bNewRecord.setEnabled(m_M_AttributeSetInstance_ID > 0 && isAllowedToCreateAndUpdate);
boolean rw = m_M_AttributeSetInstance_ID == 0;
for (int i = 0; i < m_editors.size(); i++)
{
WEditor editor = m_editors.get(i);
editor.setReadWrite(rw);
editor.setReadWrite(rw && isAllowedToCreateAndUpdate);
}
}
@ -824,7 +832,7 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
// OK
else if (e.getTarget().getId().equals("Ok"))
{
if (saveSelection())
if (isAllowedToCreateAndUpdate && saveSelection())
dispose();
}
// Cancel
@ -865,9 +873,9 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
for (int i = 0; i < attributes.length; i++)
updateAttributeEditor(attributes[i], i);
cbNewEdit.setEnabled(true);
cbNewEdit.setEnabled(true && isAllowedToCreateAndUpdate);
cbNewEdit.setSelected(false);
bNewRecord.setEnabled(true);
bNewRecord.setEnabled(true && isAllowedToCreateAndUpdate);
cmd_edit();
}
}
@ -974,7 +982,7 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
*/
protected void cmd_newEdit()
{
boolean rw = cbNewEdit.isChecked();
boolean rw = cbNewEdit.isChecked() && isAllowedToCreateAndUpdate;
if (log.isLoggable(Level.CONFIG)) log.config("R/W=" + rw + " " + m_masi);
//
fieldLotString.setReadonly(!(rw && m_masi.getM_Lot_ID()==0));
@ -1253,4 +1261,18 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
return m_changed;
} // isChanged
/**
* This method searches for User's Window Access to determinate if it is
* possible to create new ASI records (when IsReadWrite = true), only read
* existing ASI records (when IsReadWrite = false) or open the ASI dialog (when
* there is no Window Access for Attribute Set Instance window).
*/
private void validadeRoleAccess() {
Boolean hasAccess = MRole.getDefault().getWindowAccess(SystemIDs.WINDOW_ATTRIBUTESETINSTANCE);
if (hasAccess == null)
throw new AdempiereException(Msg.translate(Env.getCtx(), "AccessTableNoView"));
isAllowedToCreateAndUpdate = hasAccess;
}
} // WPAttributeDialog