Fixed issue 34823: Product selector of the Requisition subtab appears empty
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Fri, 30 Dec 2016 00:31:59 +0100
changeset 31051 68aee6dfac93
parent 31050 30a6b330b633
child 31052 c1b4f96c8378
child 31053 c951f095b5d3
Fixed issue 34823: Product selector of the Requisition subtab appears empty

The problem was introduced in a refactor of checkFetchDatasourceAccess() method of
BaseDataSourceService class. This refactor change the way in wich entities of
selectors were calculated. It is important to note that the refactor is not bad in
itself. The problem was appeared because it was forgotten to do an additional thing.

Before this refactor in some cases entities were not calculated properly. For example
in the subtab of Requisition window there are a complex selector of product. (Reference:
Product Complete - Parent Reference: Search). In this example, checkFetchDatasourceAccess
method was checked Product entity instead of ProductStockView. The refactor fixed this
problem.

Otherwise, the refactor missed to take into account entities of complex defined selectors
as derivedReadableEntities. To solve the problem now, when initialize() method of
EntityAccessChecker class calculates permissions, it will take into account this entities.
src/org/openbravo/dal/security/EntityAccessChecker.java
--- a/src/org/openbravo/dal/security/EntityAccessChecker.java	Thu Dec 29 19:36:32 2016 +0000
+++ b/src/org/openbravo/dal/security/EntityAccessChecker.java	Fri Dec 30 00:31:59 2016 +0100
@@ -71,6 +71,7 @@
 
   private static final String SELECTOR_REFERENCE = "95E2A8B50A254B2AAE6774B8C2F28120";
   private static final String MULTI_SELECTOR_REFERENCE = "87E6CFF8F71548AFA33F181C317970B5";
+  private static final String SEARCH_REFERENCE = "30";
   private static final String WINDOW_REFERENCE = "FF80818132D8F0F30132D9BC395D0038";
 
   // Table Access Level:
@@ -233,6 +234,22 @@
             processes.add(processSelector);
           }
         }
+
+        // and take into account entities of complex defined selectors
+        final String selectorsOfSearchReference = "select distinct(s.table.id) from OBUISEL_Selector s "
+            + "left join s.reference r left join r.aDColumnReferenceSearchKeyList c "
+            + "where r.parentReference='" + SEARCH_REFERENCE + "' and c.table.id in " + inTables;
+        @SuppressWarnings("unchecked")
+        final List<String> targetTablesIds = SessionHandler.getInstance()
+            .createQuery(selectorsOfSearchReference).list();
+        for (String tableId : targetTablesIds) {
+          Entity targetSelectorEntity = ModelProvider.getInstance().getEntityByTableId(tableId);
+          if (!writableEntities.contains(targetSelectorEntity)
+              && !readableEntities.contains(targetSelectorEntity)
+              && !nonReadableEntities.contains(targetSelectorEntity)) {
+            derivedReadableEntities.add(targetSelectorEntity);
+          }
+        }
       }
 
       // and take into account explicit process access