IDEMPIERE-2113 Enable import button for end users / discover also permissions on included roles
This commit is contained in:
parent
388c9f76f0
commit
07eb7d4540
|
@ -85,12 +85,22 @@ public class MImportTemplate extends X_AD_ImportTemplate
|
|||
return retValue;
|
||||
|
||||
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 "
|
||||
+ " 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'))";
|
||||
+ " FROM AD_ImportTemplateAccess ita "
|
||||
+ " 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)
|
||||
.setParameters(Env.getAD_Client_ID(Env.getCtx()), tabid, roleid)
|
||||
.setParameters(Env.getAD_Client_ID(Env.getCtx()), tabid, roleid, roleid)
|
||||
.setOrderBy("Name")
|
||||
.list();
|
||||
s_cacheRoleTab.put(key, retValue);
|
||||
|
@ -98,8 +108,17 @@ public class MImportTemplate extends X_AD_ImportTemplate
|
|||
}
|
||||
|
||||
public boolean isAllowed(String importMode, int roleID) {
|
||||
StringBuilder sql= new StringBuilder(
|
||||
"SELECT COUNT(*) FROM AD_ImportTemplateAccess WHERE IsActive='Y' AND AD_ImportTemplate_ID=? AND AD_Role_ID=? AND IsAllow");
|
||||
StringBuilder sql= new StringBuilder(""
|
||||
+ "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))
|
||||
sql.append("Insert");
|
||||
else if ("U".equals(importMode))
|
||||
|
@ -110,7 +129,7 @@ public class MImportTemplate extends X_AD_ImportTemplate
|
|||
return false;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -247,18 +247,30 @@ public class CSVImportAction implements EventListener<Event>
|
|||
|
||||
private void fillImportMode() {
|
||||
final String sql= ""
|
||||
+ "SELECT IsAllowInsert, IsAllowUpdate, IsAllowMerge "
|
||||
+ "FROM AD_ImportTemplateAccess "
|
||||
+ "WHERE IsActive='Y' AND AD_ImportTemplate_ID=? AND AD_Role_ID=? 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()));
|
||||
+ "SELECT MAX(IsAllowInsert), "
|
||||
+ " MAX(IsAllowUpdate), "
|
||||
+ " MAX(IsAllowMerge) "
|
||||
+ "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();
|
||||
if (flags.get(0) != null && "Y".equals(flags.get(0).toString()))
|
||||
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");
|
||||
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.setSelectedIndex(0);
|
||||
if (fImportMode.getItemCount() == 1)
|
||||
fImportMode.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
private void processUploadMedia(Media media) {
|
||||
|
|
Loading…
Reference in New Issue