IDEMPIERE-2113 Enable import button for end users / discover also permissions on included roles

This commit is contained in:
Carlos Ruiz 2015-03-14 16:03:45 -05:00
parent 388c9f76f0
commit 07eb7d4540
2 changed files with 45 additions and 14 deletions

View File

@ -85,12 +85,22 @@ public class MImportTemplate extends X_AD_ImportTemplate
return retValue; return retValue;
final String where = "" final String where = ""
+ "IsActive='Y' AND AD_Client_ID IN (0, ?) AND AD_Tab_ID=? " + "IsActive = 'Y' "
+ "AND AD_Client_ID IN ( 0, ? ) "
+ "AND AD_Tab_ID = ? "
+ "AND EXISTS (SELECT 1 " + "AND EXISTS (SELECT 1 "
+ " FROM AD_ImportTemplateAccess ita " + " FROM AD_ImportTemplateAccess ita "
+ " WHERE ita.AD_ImportTemplate_ID=AD_ImportTemplate.AD_ImportTemplate_ID AND ita.IsActive='Y' AND ita.AD_Role_ID=? AND (IsAllowInsert='Y' OR IsAllowMerge='Y' OR IsAllowUpdate='Y'))"; + " WHERE ita.AD_ImportTemplate_ID = AD_ImportTemplate.AD_ImportTemplate_ID "
+ " AND ita.IsActive = 'Y' "
+ " AND ( ita.AD_Role_ID = ? "
+ " OR ita.AD_Role_ID IN (SELECT Included_Role_ID "
+ " FROM AD_Role_Included "
+ " WHERE AD_Role_ID = ? AND IsActive = 'Y') ) "
+ " AND ( IsAllowInsert = 'Y' "
+ " OR IsAllowMerge = 'Y' "
+ " OR IsAllowUpdate = 'Y' ))";
retValue = new Query(Env.getCtx(), MImportTemplate.Table_Name, where, null) retValue = new Query(Env.getCtx(), MImportTemplate.Table_Name, where, null)
.setParameters(Env.getAD_Client_ID(Env.getCtx()), tabid, roleid) .setParameters(Env.getAD_Client_ID(Env.getCtx()), tabid, roleid, roleid)
.setOrderBy("Name") .setOrderBy("Name")
.list(); .list();
s_cacheRoleTab.put(key, retValue); s_cacheRoleTab.put(key, retValue);
@ -98,8 +108,17 @@ public class MImportTemplate extends X_AD_ImportTemplate
} }
public boolean isAllowed(String importMode, int roleID) { public boolean isAllowed(String importMode, int roleID) {
StringBuilder sql= new StringBuilder( StringBuilder sql= new StringBuilder(""
"SELECT COUNT(*) FROM AD_ImportTemplateAccess WHERE IsActive='Y' AND AD_ImportTemplate_ID=? AND AD_Role_ID=? AND IsAllow"); + "SELECT COUNT(*) "
+ "FROM AD_ImportTemplateaccess "
+ "WHERE IsActive = 'Y' "
+ " AND AD_ImportTemplate_ID = ? "
+ " AND ( AD_Role_ID = ? "
+ " OR AD_Role_ID IN (SELECT Included_Role_ID "
+ " FROM AD_Role_Included "
+ " WHERE AD_Role_id = ? "
+ " AND IsActive = 'Y') ) "
+ " AND IsAllow");
if ("I".equals(importMode)) if ("I".equals(importMode))
sql.append("Insert"); sql.append("Insert");
else if ("U".equals(importMode)) else if ("U".equals(importMode))
@ -110,7 +129,7 @@ public class MImportTemplate extends X_AD_ImportTemplate
return false; return false;
sql.append("='Y'"); sql.append("='Y'");
int cnt = DB.getSQLValueEx(get_TrxName(), sql.toString(), getAD_ImportTemplate_ID(), roleID); int cnt = DB.getSQLValueEx(get_TrxName(), sql.toString(), getAD_ImportTemplate_ID(), roleID, roleID);
return cnt > 0; return cnt > 0;
} }

View File

@ -247,18 +247,30 @@ public class CSVImportAction implements EventListener<Event>
private void fillImportMode() { private void fillImportMode() {
final String sql= "" final String sql= ""
+ "SELECT IsAllowInsert, IsAllowUpdate, IsAllowMerge " + "SELECT MAX(IsAllowInsert), "
+ "FROM AD_ImportTemplateAccess " + " MAX(IsAllowUpdate), "
+ "WHERE IsActive='Y' AND AD_ImportTemplate_ID=? AND AD_Role_ID=? AND (IsAllowInsert='Y' OR IsAllowMerge='Y' OR IsAllowUpdate='Y')"; + " MAX(IsAllowMerge) "
List<Object> flags = DB.getSQLValueObjectsEx(null, sql, theTemplate.getAD_ImportTemplate_ID(), Env.getAD_Role_ID(Env.getCtx())); + "FROM AD_ImportTemplateAccess "
+ "WHERE IsActive = 'Y' "
+ " AND AD_ImportTemplate_ID = ? "
+ " AND ( AD_Role_ID = ? "
+ " OR AD_Role_ID IN (SELECT Included_Role_ID "
+ " FROM AD_Role_Included "
+ " WHERE AD_Role_ID = ? "
+ " AND IsActive = 'Y') ) "
+ " AND ( IsAllowInsert = 'Y' "
+ " OR IsAllowMerge = 'Y' "
+ " OR IsAllowUpdate = 'Y' )";
List<Object> flags = DB.getSQLValueObjectsEx(null, sql, theTemplate.getAD_ImportTemplate_ID(), Env.getAD_Role_ID(Env.getCtx()), Env.getAD_Role_ID(Env.getCtx()));
fImportMode.removeAllItems(); fImportMode.removeAllItems();
if (flags.get(0) != null && "Y".equals(flags.get(0).toString())) if (flags.get(0) != null && "Y".equals(flags.get(0).toString()))
fImportMode.appendItem("Insert","I"); fImportMode.appendItem("Insert","I");
if (flags.get(1) != null && "Y".equals(flags.get(0).toString())) if (flags.get(1) != null && "Y".equals(flags.get(1).toString()))
fImportMode.appendItem("Update","U"); fImportMode.appendItem("Update","U");
if (flags.get(2) != null && "Y".equals(flags.get(0).toString())) if (flags.get(2) != null && "Y".equals(flags.get(2).toString()))
fImportMode.appendItem("Merge","M"); fImportMode.appendItem("Merge","M");
fImportMode.setSelectedIndex(0); if (fImportMode.getItemCount() == 1)
fImportMode.setSelectedIndex(0);
} }
private void processUploadMedia(Media media) { private void processUploadMedia(Media media) {