IDEMPIERE-129 Restrictions on Toolbar and Menu - peer review and apply best practices
http://jira.idempiere.com/browse/IDEMPIERE-129
This commit is contained in:
parent
3852377c43
commit
a515c81c2d
|
@ -16,12 +16,8 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
|
@ -34,7 +30,11 @@ import org.compiere.util.Env;
|
||||||
*/
|
*/
|
||||||
public class MToolBarButtonRestrict extends X_AD_ToolBarButtonRestrict
|
public class MToolBarButtonRestrict extends X_AD_ToolBarButtonRestrict
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = -422120961441035731L;
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 751989571891306735L;
|
||||||
|
|
||||||
private static CLogger s_log = CLogger.getCLogger(MToolBarButtonRestrict.class);
|
private static CLogger s_log = CLogger.getCLogger(MToolBarButtonRestrict.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,34 +59,20 @@ public class MToolBarButtonRestrict extends X_AD_ToolBarButtonRestrict
|
||||||
super(ctx, rs, trxName);
|
super(ctx, rs, trxName);
|
||||||
} // MToolBarButtonRestrict
|
} // MToolBarButtonRestrict
|
||||||
|
|
||||||
/** Renvoie une liste des restrictions à appliquer en fonction du rôle, de la fenêtre, du formulaire, ... **/
|
/** Returns a list of restrictions to be applied according to the role, the window of the form ... **/
|
||||||
public static ArrayList<Integer> getOf (Properties ctx, int AD_Role_ID, String Action, int Action_ID, String trxName)
|
public static int[] getOf (Properties ctx, int AD_Role_ID, String Action, int Action_ID, String className, String trxName)
|
||||||
{
|
{
|
||||||
// Action : R-Report, W-Window, X-form
|
// Action : R-Report, W-Window, X-form
|
||||||
ArrayList<Integer> list = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
String sql = "SELECT AD_ToolBarButton_ID FROM AD_ToolBarButtonRestrict WHERE IsActive = 'Y'"
|
String sql = "SELECT AD_ToolBarButton_ID FROM AD_ToolBarButtonRestrict WHERE IsActive = 'Y'"
|
||||||
+ " AND AD_Client_ID IN (0, " + Env.getAD_Client_ID(ctx) + ")"
|
+ " AND AD_Client_ID IN (0, ?)"
|
||||||
+ " AND (AD_Role_ID IS NULL OR AD_Role_ID = " + AD_Role_ID + ")"
|
+ " AND (AD_Role_ID IS NULL OR AD_Role_ID = ?)"
|
||||||
+ " AND (Action IS NULL "
|
+ " AND (Action IS NULL OR Action=? AND (AD_Window_ID IS NULL OR (Action='W' AND AD_Window_ID=?)))"
|
||||||
+ " OR Action='" + Action + "' AND (AD_Window_ID IS NULL OR AD_Window_ID = " + Action_ID + "))";
|
+ " AND AD_ToolBarButton_ID IN (SELECT AD_ToolBarButton_ID FROM AD_ToolBarButton WHERE IsActive='Y' AND Classname=?)";
|
||||||
s_log.warning("sql="+sql);
|
s_log.info("sql="+sql);
|
||||||
|
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sql, trxName);
|
int[] ids = DB.getIDsEx(trxName, sql, Env.getAD_Client_ID(ctx), AD_Role_ID, Action, Action_ID, className);
|
||||||
ResultSet rs;
|
|
||||||
try {
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next())
|
return ids;
|
||||||
{
|
|
||||||
if (!list.contains(rs.getInt(1)))
|
|
||||||
list.add (rs.getInt(1));
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
} // getOf
|
} // getOf
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -148,7 +148,7 @@ public final class APanel extends CPanel
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 6066778919781303581L;
|
private static final long serialVersionUID = -253840959387736456L;
|
||||||
|
|
||||||
private boolean isNested = false;
|
private boolean isNested = false;
|
||||||
private boolean ToolBarMenuRestictionLoaded = false;
|
private boolean ToolBarMenuRestictionLoaded = false;
|
||||||
|
@ -2918,17 +2918,16 @@ public final class APanel extends CPanel
|
||||||
|
|
||||||
private void updateToolBarAndMenuWithRestriction()
|
private void updateToolBarAndMenuWithRestriction()
|
||||||
{
|
{
|
||||||
ArrayList<Integer> restrictionList = new ArrayList<Integer>();
|
|
||||||
int ToolBarButton_ID = 0;
|
int ToolBarButton_ID = 0;
|
||||||
|
|
||||||
restrictionList = MToolBarButtonRestrict.getOf(m_ctx, MRole.getDefault().getAD_Role_ID(), "W", m_window.getAD_Window_ID(), null);
|
int[] restrictionList = MToolBarButtonRestrict.getOf(m_ctx, MRole.getDefault().getAD_Role_ID(), "W", m_window.getAD_Window_ID(), this.getClass().getName(), null);
|
||||||
log.warning("restrictionList="+restrictionList.toString());
|
log.info("restrictionList="+restrictionList.toString());
|
||||||
|
|
||||||
for (int i = 0; i < restrictionList.size(); i++)
|
for (int i = 0; i < restrictionList.length; i++)
|
||||||
{
|
{
|
||||||
ToolBarButton_ID= restrictionList.get(i);
|
ToolBarButton_ID= restrictionList[i];
|
||||||
|
|
||||||
X_AD_ToolBarButton tbt = new X_AD_ToolBarButton(Env.getCtx(), ToolBarButton_ID, null);
|
X_AD_ToolBarButton tbt = new X_AD_ToolBarButton(m_ctx, ToolBarButton_ID, null);
|
||||||
String restrictName = tbt.getComponentName();
|
String restrictName = tbt.getComponentName();
|
||||||
log.config("tbt="+tbt.getAD_ToolBarButton_ID() + " / " + restrictName);
|
log.config("tbt="+tbt.getAD_ToolBarButton_ID() + " / " + restrictName);
|
||||||
boolean found=false;
|
boolean found=false;
|
||||||
|
|
Loading…
Reference in New Issue