IDEMPIERE-3979 Record Access Exclude problem / peer review

This commit is contained in:
Carlos Ruiz 2019-06-10 19:22:13 +02:00
parent 05da94ddf1
commit 6bdfc00408
2 changed files with 36 additions and 28 deletions

View File

@ -83,7 +83,7 @@ public class GridField
/** /**
* *
*/ */
private static final long serialVersionUID = -1871840570764036802L; private static final long serialVersionUID = -5923967271000455417L;
/** /**
* Field Constructor. * 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. * 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_lookupEditorSettingValue = false;
private boolean m_lockedrecord=false; private boolean m_lockedRecord = false;
/** /**
* Dispose * Dispose
*/ */
@ -447,7 +445,7 @@ public class GridField
{ {
if (isVirtualColumn()) if (isVirtualColumn())
return false; return false;
if (m_lockedrecord) if (m_lockedRecord)
return false; return false;
// Fields always enabled (are usually not updateable) // Fields always enabled (are usually not updateable)
if (m_vo.ColumnName.equals("Posted") 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); return m_vo.displayType == DisplayType.Button && MColumn.ISTOOLBARBUTTON_Toolbar.equals(m_vo.IsToolbarButton);
} }
public boolean islockedrecord() { public boolean isLockedRecord() {
return m_lockedrecord; return m_lockedRecord;
} }
public void setlockedrecord(boolean m_lockedrecord) { public void setLockedRecord(boolean lockedRecord) {
this.m_lockedrecord = m_lockedrecord; this.m_lockedRecord = lockedRecord;
} }
public int getPA_DashboardContent_ID() public int getPA_DashboardContent_ID()
{ {
return m_vo.PA_DashboardContent_ID; return m_vo.PA_DashboardContent_ID;

View File

@ -42,6 +42,7 @@ import org.compiere.model.GridField;
import org.compiere.model.GridTable; import org.compiere.model.GridTable;
import org.compiere.model.Lookup; import org.compiere.model.Lookup;
import org.compiere.model.MBPartnerLocation; import org.compiere.model.MBPartnerLocation;
import org.compiere.model.MColumn;
import org.compiere.model.MLocation; import org.compiere.model.MLocation;
import org.compiere.model.MLookup; import org.compiere.model.MLookup;
import org.compiere.model.MRole; import org.compiere.model.MRole;
@ -314,30 +315,38 @@ ContextMenuListener, IZoomableEditor
refreshList(); refreshList();
} }
//still not in list, reset to zero //still not in list, reset to zero
if (!getComponent().isSelected(value)) if (!getComponent().isSelected(value))
{ {
if (value instanceof Integer && gridField != null && gridField.getDisplayType() != DisplayType.ID && 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 (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); MRole role = MRole.getDefault(Env.getCtx(), false);
if (role.isRecordAccess(gridTab.getAD_Table_ID() ,(int)value,false)){ MColumn col = MColumn.get(Env.getCtx(), gridField.getAD_Column_ID());
oldValue = value; int refTableID = -1;
setReadWrite(false); if (col.get_ID() > 0) {
gridField.setlockedrecord(true); String refTable = col.getReferenceTableName();
} MTable table = MTable.get(Env.getCtx(), refTable);
else refTableID = table.getAD_Table_ID();
{ }
getComponent().setValue(null); if (refTableID > 0 && ! role.isRecordAccess(refTableID, (int)value, false))
if (curValue == null) {
curValue = value; oldValue = value;
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), curValue, null); setReadWrite(false);
super.fireValueChange(changeEvent); gridField.setLockedRecord(true);
oldValue = null; }
if (gridField!=null) else
gridField.setlockedrecord(false); {
} 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; oldValue = value;
if (gridField!=null) if (gridField!=null)
gridField.setlockedrecord(false); gridField.setLockedRecord(false);
} }
} }
else else