Fixed issue 34830: Product selector of the Requisition subtab appears empty
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Fri, 30 Dec 2016 00:38:50 +0100
changeset 31492 291808b5cd55
parent 31240 0c8c781e34c9
child 31493 f43dcd2fc7a5
Fixed issue 34830: 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	Tue Nov 22 10:55:46 2016 +0000
+++ b/src/org/openbravo/dal/security/EntityAccessChecker.java	Fri Dec 30 00:38:50 2016 +0100
@@ -72,6 +72,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:
@@ -234,6 +235,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