details:   https://code.openbravo.com/erp/devel/pi/rev/5068c169fe15
changeset: 28866:5068c169fe15
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Fri Apr 08 14:07:14 2016 +0200
summary:   fixes issue 32626: cannot propagate privileges if a template role 
has been used
Now the client/org check is skipped when propagating changes (create, remove, 
update) privileges. This is done by using the OBContext.setAdminMode(false).
Besides, the UINAVBA_MenuRecentList preference has been included into the 
preference black list, which is a list that prevents the propagation of all the 
preferences included within it.

diffstat:

 src/org/openbravo/role/inheritance/RoleInheritanceManager.java          |  71 
++++++---
 src/org/openbravo/role/inheritance/access/PreferenceAccessInjector.java |   2 
+-
 2 files changed, 45 insertions(+), 28 deletions(-)

diffs (116 lines):

diff -r 075d80ce3160 -r 5068c169fe15 
src/org/openbravo/role/inheritance/RoleInheritanceManager.java
--- a/src/org/openbravo/role/inheritance/RoleInheritanceManager.java    Fri Apr 
08 10:40:36 2016 +0200
+++ b/src/org/openbravo/role/inheritance/RoleInheritanceManager.java    Fri Apr 
08 14:07:14 2016 +0200
@@ -37,6 +37,7 @@
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.base.structure.InheritedAccessEnabled;
 import org.openbravo.dal.core.DalUtil;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.Utility;
@@ -116,12 +117,17 @@
    */
   private void copyRoleAccess(InheritedAccessEnabled parentAccess, Role role,
       AccessTypeInjector injector) {
-    // copy the new access
-    final InheritedAccessEnabled newAccess = (InheritedAccessEnabled) 
DalUtil.copy(
-        (BaseOBObject) parentAccess, false);
-    injector.setParent(newAccess, parentAccess, role);
-    newAccess.setInheritedFrom(injector.getRole(parentAccess));
-    OBDal.getInstance().save(newAccess);
+    try {
+      OBContext.setAdminMode(false);
+      // copy the new access
+      final InheritedAccessEnabled newAccess = (InheritedAccessEnabled) 
DalUtil.copy(
+          (BaseOBObject) parentAccess, false);
+      injector.setParent(newAccess, parentAccess, role);
+      newAccess.setInheritedFrom(injector.getRole(parentAccess));
+      OBDal.getInstance().save(newAccess);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
   }
 
   void removeReferenceInParentList(InheritedAccessEnabled access, String 
className) {
@@ -143,25 +149,31 @@
    */
   private void deleteRoleAccess(Role inheritFromToDelete,
       List<? extends InheritedAccessEnabled> roleAccessList, 
AccessTypeInjector injector) {
-    String inheritFromId = (String) DalUtil.getId(inheritFromToDelete);
-    List<InheritedAccessEnabled> iaeToDelete = new 
ArrayList<InheritedAccessEnabled>();
-    for (InheritedAccessEnabled ih : roleAccessList) {
-      String inheritedFromId = ih.getInheritedFrom() != null ? (String) 
DalUtil.getId(ih
-          .getInheritedFrom()) : "";
-      if (!StringUtils.isEmpty(inheritedFromId) && 
inheritFromId.equals(inheritedFromId)) {
-        iaeToDelete.add(ih);
+    try {
+      OBContext.setAdminMode(false);
+      String inheritFromId = (String) DalUtil.getId(inheritFromToDelete);
+      List<InheritedAccessEnabled> iaeToDelete = new 
ArrayList<InheritedAccessEnabled>();
+      for (InheritedAccessEnabled ih : roleAccessList) {
+        String inheritedFromId = ih.getInheritedFrom() != null ? (String) 
DalUtil.getId(ih
+            .getInheritedFrom()) : "";
+        if (!StringUtils.isEmpty(inheritedFromId) && 
inheritFromId.equals(inheritedFromId)) {
+          iaeToDelete.add(ih);
+        }
       }
-    }
-    for (InheritedAccessEnabled iae : iaeToDelete) {
-      iae.setInheritedFrom(null);
-      roleAccessList.remove(iae);
-      Role owner = injector.getRole(iae);
-      if (!owner.isTemplate()) {
-        // Perform this operation for not template roles, because for template 
roles is already done
-        // in the event handler
-        injector.removeReferenceInParentList(iae);
+      for (InheritedAccessEnabled iae : iaeToDelete) {
+        iae.setInheritedFrom(null);
+        roleAccessList.remove(iae);
+        Role owner = injector.getRole(iae);
+        if (!owner.isTemplate()) {
+          // Perform this operation for not template roles, because for 
template roles is already
+          // done
+          // in the event handler
+          injector.removeReferenceInParentList(iae);
+        }
+        OBDal.getInstance().remove(iae);
       }
-      OBDal.getInstance().remove(iae);
+    } finally {
+      OBContext.restorePreviousMode();
     }
   }
 
@@ -178,10 +190,15 @@
    */
   private void updateRoleAccess(InheritedAccessEnabled access, 
InheritedAccessEnabled inherited,
       AccessTypeInjector injector) {
-    final InheritedAccessEnabled updatedAccess = (InheritedAccessEnabled) 
DalUtil.copyToTarget(
-        (BaseOBObject) inherited, (BaseOBObject) access, false, 
injector.getSkippedProperties());
-    // update the inherit from field, to indicate from which role we are 
inheriting now
-    updatedAccess.setInheritedFrom(injector.getRole(inherited));
+    try {
+      OBContext.setAdminMode(false);
+      final InheritedAccessEnabled updatedAccess = (InheritedAccessEnabled) 
DalUtil.copyToTarget(
+          (BaseOBObject) inherited, (BaseOBObject) access, false, 
injector.getSkippedProperties());
+      // update the inherit from field, to indicate from which role we are 
inheriting now
+      updatedAccess.setInheritedFrom(injector.getRole(inherited));
+    } finally {
+      OBContext.restorePreviousMode();
+    }
   }
 
   /**
diff -r 075d80ce3160 -r 5068c169fe15 
src/org/openbravo/role/inheritance/access/PreferenceAccessInjector.java
--- a/src/org/openbravo/role/inheritance/access/PreferenceAccessInjector.java   
Fri Apr 08 10:40:36 2016 +0200
+++ b/src/org/openbravo/role/inheritance/access/PreferenceAccessInjector.java   
Fri Apr 08 14:07:14 2016 +0200
@@ -39,7 +39,7 @@
 
   private static final Set<String> propertyBlackList = new 
HashSet<String>(Arrays.asList(
       "OBUIAPP_RecentDocumentsList", "OBUIAPP_RecentViewList", 
"OBUIAPP_GridConfiguration",
-      "OBUIAPP_DefaultSavedView", "UINAVBA_RecentLaunchList"));
+      "OBUIAPP_DefaultSavedView", "UINAVBA_MenuRecentList", 
"UINAVBA_RecentLaunchList"));
 
   @Override
   public String getSecuredElementGetter() {

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to