From 6bdfc00408bc8e6a7e0d6750d7f64af1917fa78f Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 10 Jun 2019 19:22:13 +0200 Subject: [PATCH] IDEMPIERE-3979 Record Access Exclude problem / peer review --- .../src/org/compiere/model/GridField.java | 17 ++++--- .../webui/editor/WTableDirEditor.java | 47 +++++++++++-------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/GridField.java b/org.adempiere.base/src/org/compiere/model/GridField.java index 6b370054e4..fe9f8a6160 100644 --- a/org.adempiere.base/src/org/compiere/model/GridField.java +++ b/org.adempiere.base/src/org/compiere/model/GridField.java @@ -83,7 +83,7 @@ public class GridField /** * */ - private static final long serialVersionUID = -1871840570764036802L; + private static final long serialVersionUID = -5923967271000455417L; /** * Field Constructor. @@ -110,10 +110,8 @@ public class GridField * GridTab.processDependentFields will check this flag to avoid clearing of lookup field value that just have been set. **/ private boolean m_lookupEditorSettingValue = false; - private boolean m_lockedrecord=false; + private boolean m_lockedRecord = false; - - /** * Dispose */ @@ -447,7 +445,7 @@ public class GridField { if (isVirtualColumn()) return false; - if (m_lockedrecord) + if (m_lockedRecord) return false; // Fields always enabled (are usually not updateable) if (m_vo.ColumnName.equals("Posted") @@ -2512,13 +2510,14 @@ public class GridField return m_vo.displayType == DisplayType.Button && MColumn.ISTOOLBARBUTTON_Toolbar.equals(m_vo.IsToolbarButton); } - public boolean islockedrecord() { - return m_lockedrecord; + public boolean isLockedRecord() { + return m_lockedRecord; } - public void setlockedrecord(boolean m_lockedrecord) { - this.m_lockedrecord = m_lockedrecord; + public void setLockedRecord(boolean lockedRecord) { + this.m_lockedRecord = lockedRecord; } + public int getPA_DashboardContent_ID() { return m_vo.PA_DashboardContent_ID; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java index 0bbf789378..338e798d75 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java @@ -42,6 +42,7 @@ import org.compiere.model.GridField; import org.compiere.model.GridTable; import org.compiere.model.Lookup; import org.compiere.model.MBPartnerLocation; +import org.compiere.model.MColumn; import org.compiere.model.MLocation; import org.compiere.model.MLookup; import org.compiere.model.MRole; @@ -314,30 +315,38 @@ ContextMenuListener, IZoomableEditor refreshList(); } - //still not in list, reset to zero + //still not in list, reset to zero if (!getComponent().isSelected(value)) { if (value instanceof Integer && gridField != null && gridField.getDisplayType() != DisplayType.ID && (gridTab==null || !gridTab.getTableModel().isImporting())) // for IDs is ok to be out of the list { - //if it is problem with record lock, just keep value (no trigger change) and set field readonly + //if it is problem with record lock, just keep value (no trigger change) and set field readonly MRole role = MRole.getDefault(Env.getCtx(), false); - if (role.isRecordAccess(gridTab.getAD_Table_ID() ,(int)value,false)){ - oldValue = value; - setReadWrite(false); - gridField.setlockedrecord(true); - } - else - { - getComponent().setValue(null); - if (curValue == null) - curValue = value; - ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), curValue, null); - super.fireValueChange(changeEvent); - oldValue = null; - if (gridField!=null) - gridField.setlockedrecord(false); - } + MColumn col = MColumn.get(Env.getCtx(), gridField.getAD_Column_ID()); + int refTableID = -1; + if (col.get_ID() > 0) { + String refTable = col.getReferenceTableName(); + MTable table = MTable.get(Env.getCtx(), refTable); + refTableID = table.getAD_Table_ID(); + } + if (refTableID > 0 && ! role.isRecordAccess(refTableID, (int)value, false)) + { + oldValue = value; + setReadWrite(false); + gridField.setLockedRecord(true); + } + else + { + getComponent().setValue(null); + if (curValue == null) + curValue = value; + ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), curValue, null); + super.fireValueChange(changeEvent); + oldValue = null; + if (gridField!=null) + gridField.setLockedRecord(false); + } } } } @@ -345,7 +354,7 @@ ContextMenuListener, IZoomableEditor { oldValue = value; if (gridField!=null) - gridField.setlockedrecord(false); + gridField.setLockedRecord(false); } } else