IDEMPIERE-1064 Control dashboard access by role. Fixed maintenance of dashboard preference.

This commit is contained in:
Heng Sin Low 2013-09-17 21:40:29 +08:00
parent 8cc6b3b69d
commit a784103b35
2 changed files with 32 additions and 26 deletions

View File

@ -43,20 +43,15 @@ public class MDashboardContentAccess extends X_PA_DashboardContent_Access {
super(ctx, rs, trxName);
}
public static MDashboardContent[] get (Properties ctx,int AD_Role, int AD_User, String trxname, boolean isShowinDashboard)
public static MDashboardContent[] get (Properties ctx,int AD_Role, int AD_User, String trxname)
{
int AD_Client_ID = Env.getAD_Client_ID(ctx);
ArrayList<MDashboardContent> content =new ArrayList<MDashboardContent>() ;
List<Object> parameters = new ArrayList<Object>();
if(isShowinDashboard){
parameters.add("Y");
parameters.add("Y");
}else{
parameters.add("N");
parameters.add("N");
}
parameters.add(AD_Client_ID);
parameters.add(AD_Client_ID);
StringBuffer sql= new StringBuffer();
sql.append("SELECT PA_DashboardContent_ID,ColumnNo ")
@ -64,32 +59,31 @@ public class MDashboardContentAccess extends X_PA_DashboardContent_Access {
.append(" WHERE PA_DashboardContent_ID NOT IN (")
.append(" SELECT PA_DashboardContent_ID ")
.append(" FROM PA_DashboardContent_Access" )
.append(" WHERE IsActive='Y' )")
.append(" WHERE IsActive='Y' AND AD_Client_ID IN (0, ?))")
.append(" AND IsShowInLogin='Y'")
.append(" AND IsActive='Y'")
.append(" AND IsShowInDashboard=?")
.append(" AND IsActive='Y' AND AD_Client_ID IN (0, ?)")
.append(" UNION ALL")
.append(" SELECT ct.PA_DashboardContent_ID,ct.ColumnNo")
.append(" FROM PA_DashboardContent ct")
.append(" INNER JOIN PA_DashboardContent_Access cta on (ct.PA_DashboardContent_ID = cta.PA_DashboardContent_ID)")
.append(" WHERE cta.IsActive='Y'")
.append(" AND ct.IsActive='Y'")
.append(" AND ct.IsShowInDashboard=?");
.append(" AND ct.IsActive='Y'");
if(AD_Role > 0){
sql.append(" AND cta.AD_Role_ID = ?");
if(AD_Role >= 0){
sql.append(" AND coalesce(cta.AD_Role_ID, ?) = ?");
parameters.add(AD_Role);
parameters.add(AD_Role);
}
if (AD_User > 0){
sql.append(" OR cta.AD_User_ID = ?");
if (AD_User >= 0){
sql.append(" AND coalesce(cta.AD_User_ID, ?) = ?");
parameters.add(AD_User);
parameters.add(AD_User);
}
if (AD_Client_ID > 0){
sql.append(" AND cta.AD_Client_ID in (0,?)");
parameters.add(AD_Client_ID);
}
sql.append(" AND cta.AD_Client_ID in (0,?)");
parameters.add(AD_Client_ID);
sql.append(" ORDER BY ColumnNo");
PreparedStatement pstmt=null;

View File

@ -128,11 +128,10 @@ public class DashboardController implements EventListener<Event> {
int AD_Role_ID = Env.getAD_Role_ID(Env.getCtx());
MDashboardPreference[] dps = MDashboardPreference.getForSession(AD_User_ID, AD_Role_ID);
MDashboardContent [] dcs = MDashboardContentAccess.get(Env.getCtx(), AD_Role_ID, AD_User_ID, null,isShowInDashboard);
MDashboardContent [] dcs = MDashboardContentAccess.get(Env.getCtx(), AD_Role_ID, AD_User_ID, null);
if(dps.length == 0){
createDashboardPreference(AD_User_ID, AD_Role_ID,true);
createDashboardPreference(AD_User_ID, AD_Role_ID,false);
createDashboardPreference(AD_User_ID, AD_Role_ID);
dps = MDashboardPreference.getForSession(AD_User_ID, AD_Role_ID);
}else{
if(updatePreferences(dps, dcs,Env.getCtx())){
@ -518,9 +517,9 @@ public class DashboardController implements EventListener<Event> {
}
}
private void createDashboardPreference(int AD_User_ID, int AD_Role_ID,boolean isshow)
private void createDashboardPreference(int AD_User_ID, int AD_Role_ID)
{
MDashboardContent[] dcs = MDashboardContentAccess.get(Env.getCtx(),AD_Role_ID, AD_User_ID, null,isshow);
MDashboardContent[] dcs = MDashboardContentAccess.get(Env.getCtx(),AD_Role_ID, AD_User_ID, null);
for (MDashboardContent dc : dcs)
{
MDashboardPreference preference = new MDashboardPreference(Env.getCtx(), 0, null);
@ -542,6 +541,7 @@ public class DashboardController implements EventListener<Event> {
private boolean updatePreferences(MDashboardPreference[] dps,MDashboardContent[] dcs, Properties ctx) {
boolean change = false;
for (int i = 0; i < dcs.length; i++) {
boolean isNew = true;
for (int j = 0; j < dps.length; j++) {
if (dps[j].getPA_DashboardContent_ID() == dcs[i].getPA_DashboardContent_ID()) {
@ -563,6 +563,18 @@ public class DashboardController implements EventListener<Event> {
if (!change) change = true;
}
}
for (int i = 0; i < dps.length; i++) {
boolean found = false;
for (int j = 0; j < dcs.length; j++) {
if (dcs[j].getPA_DashboardContent_ID() == dps[i].getPA_DashboardContent_ID()) {
found = true;
}
}
if (!found) {
dps[i].deleteEx(true);
if (!change) change = true;
}
}
return change;
}