details:   https://code.openbravo.com/erp/devel/pi/rev/576e33b667aa
changeset: 32721:576e33b667aa
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Wed Sep 20 08:57:10 2017 +0200
summary:   fixes bug 36863: wrong info in custom query org selector after 
selecting values

Custom query selectors filter their records by organization using the natural 
tree of the organization received in the ORG_PARAMETER (it contains the 
selected organization). This logic can not be applied on custom query selectors 
based on the AD_Org table because in that case the records displayed by the 
selector change depending on the selected organization.

To fix this issue, we handle custom query organization selectors as a special 
adding a filter with the organizations that are direct accessible by the role, 
without taking into account the selected organization.

diffstat:

 
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
 |  17 ++++++++-
 1 files changed, 14 insertions(+), 3 deletions(-)

diffs (37 lines):

diff -r 27a01d1d9bee -r 576e33b667aa 
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
--- 
a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
  Tue Sep 19 10:28:14 2017 +0200
+++ 
b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
  Wed Sep 20 08:57:10 2017 +0200
@@ -40,6 +40,7 @@
 import org.hibernate.Hibernate;
 import org.hibernate.Query;
 import org.hibernate.criterion.Restrictions;
+import org.openbravo.base.model.AccessLevel;
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.domaintype.BigDecimalDomainType;
 import org.openbravo.base.model.domaintype.BooleanDomainType;
@@ -202,12 +203,22 @@
 
     if (includeOrgFilter(parameters)) {
       // Organization filter
-      final String orgs = 
DataSourceUtils.getOrgs(parameters.get(JsonConstants.ORG_PARAMETER));
+      boolean isOrgSelector = sel.getTable().getName().equals("Organization");
+      String orgs;
+      if (isOrgSelector) {
+        // Just retrieve the list of readable organizations in the current 
context
+        orgs = 
RequestContext.get().getVariablesSecureApp().getSessionValue("#User_Org");
+        int accessLevel = 
Integer.parseInt(sel.getTable().getDataAccessLevel());
+        if (AccessLevel.ORGANIZATION.getDbValue() != accessLevel && 
!orgs.contains("'0'")) {
+          orgs += "".equals(orgs) ? "0" : ",'0'";
+        }
+      } else {
+        orgs = 
DataSourceUtils.getOrgs(parameters.get(JsonConstants.ORG_PARAMETER));
+      }
       if (StringUtils.isNotEmpty(orgs)) {
         additionalFilter.append(NEW_FILTER_CLAUSE);
         additionalFilter.append(entityAlias
-            + (sel.getTable().getName().equals("Organization") ? ".id in (" + 
orgs + ")"
-                : ".organization in (" + orgs + ")"));
+            + (isOrgSelector ? ".id in (" + orgs + ")" : ".organization in (" 
+ orgs + ")"));
       }
     }
     additionalFilter.append(getDefaultFilterExpression(sel, parameters));

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to