fixes issue 11387: Enable isInAdministratorMode() also in case of user \"0\" independent of its role
authorMartin Taal <martin.taal@openbravo.com>
Wed, 18 Nov 2009 14:17:21 +0100
changeset 5455 d6e8a0f9dc7f
parent 5454 652e31de84ca
child 5456 fe2193a308d1
fixes issue 11387: Enable isInAdministratorMode() also in case of user \"0\" independent of its role
build.xml
src-db/database/build.xml
src/build.xml
src/org/openbravo/dal/core/DalInitializingTask.java
src/org/openbravo/dal/core/OBContext.java
--- a/build.xml	Wed Nov 18 14:14:12 2009 +0100
+++ b/build.xml	Wed Nov 18 14:17:21 2009 +0100
@@ -405,7 +405,7 @@
                   stableDBdir="${stableDBdir}"
                   testDBdir="${base.src.db}/database"
                   verbosity="${bbdd.verbosity}"
-                  userId="0" 
+                  userId="0" adminMode="true" 
                   propertiesFile="${base.config}/Openbravo.properties"/>    
   </target>
 
@@ -599,7 +599,7 @@
     <taskdef name="applyModule" classname="org.openbravo.erpCommon.modules.ApplyModuleTask">
       <classpath refid="project.class.path" />
     </taskdef>
-    <applyModule userId="0" propertiesFile="${base.config}/Openbravo.properties"/>
+    <applyModule userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties"/>
   </target>
 
   <target name="apply.module">
@@ -730,12 +730,12 @@
     </taskdef>
 
     <echo message="Validating Module..." />
-    <validateModules moduleJavaPackage="${module}" failOnError="false" userId="0" propertiesFile="${base.config}/Openbravo.properties" type="module" />
+    <validateModules moduleJavaPackage="${module}" failOnError="false" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" type="module" />
 
     <antcall target="obx.export.database" />
     <antcall target="obx.export.config.script" />
 
-    <extractModule moduleName="${module}" userId="0" propertiesFile="${base.config}/Openbravo.properties" exportRD="${obx.export.RD}" />
+    <extractModule moduleName="${module}" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" exportRD="${obx.export.RD}" />
   </target>
 
   <target name="diagnostic">
--- a/src-db/database/build.xml	Wed Nov 18 14:14:12 2009 +0100
+++ b/src-db/database/build.xml	Wed Nov 18 14:17:21 2009 +0100
@@ -64,11 +64,11 @@
   </taskdef>
 
   <target name="export.config.script">
-    <exportconfigscript driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" filter="com.openbravo.db.OpenbravoMetadataFilter" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter" moduledir="${base.modules}" model="model" coreData="${base.db}/sourcedata" verbosity="${bbdd.verbosity}" industryTemplate="${industryTemplate}" userId="0" propertiesFile="${base.config}/Openbravo.properties" />
+    <exportconfigscript driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" filter="com.openbravo.db.OpenbravoMetadataFilter" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter" moduledir="${base.modules}" model="model" coreData="${base.db}/sourcedata" verbosity="${bbdd.verbosity}" industryTemplate="${industryTemplate}" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" />
   </target>
 
   <target name="update.database">
-    <alterdatabasedataall driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter" model="model" filter="com.openbravo.db.OpenbravoMetadataFilter" input="sourcedata" object="${bbdd.object}" failonerror="false" verbosity="${bbdd.verbosity}" basedir="${base.modules}/" dirFilter="*/src-db/database/model" datadir="${base.modules}/" dataFilter="*/src-db/database/sourcedata" userId="0" propertiesFile="${base.config}/Openbravo.properties" force="${force}" onlyIfModified="${onlyIfModified}"/>
+    <alterdatabasedataall driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter" model="model" filter="com.openbravo.db.OpenbravoMetadataFilter" input="sourcedata" object="${bbdd.object}" failonerror="false" verbosity="${bbdd.verbosity}" basedir="${base.modules}/" dirFilter="*/src-db/database/model" datadir="${base.modules}/" dataFilter="*/src-db/database/sourcedata" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" force="${force}" onlyIfModified="${onlyIfModified}"/>
     <antcall target="database.postupdate.${bbdd.rdbms}" />
     <antcall target="update.dbupdate.timestamp" />
   </target>
@@ -101,7 +101,7 @@
   </target>
 
   <target name="update.database.mod">
-    <alterdatabasedatamod driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter" model="model" filter="com.openbravo.db.OpenbravoMetadataFilter" input="sourcedata" object="${bbdd.object}" failonerror="false" verbosity="DEBUG" basedir="${base.modules}/" baseConfig="${base.config}" dirFilter="*/src-db/database/model" datadir="${base.modules}/" dataFilter="*/src-db/database/sourcedata" module="${module}" userId="0" propertiesFile="${base.config}/Openbravo.properties" force="${force}" />
+    <alterdatabasedatamod driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter" model="model" filter="com.openbravo.db.OpenbravoMetadataFilter" input="sourcedata" object="${bbdd.object}" failonerror="false" verbosity="DEBUG" basedir="${base.modules}/" baseConfig="${base.config}" dirFilter="*/src-db/database/model" datadir="${base.modules}/" dataFilter="*/src-db/database/sourcedata" module="${module}" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" force="${force}" />
     <antcall target="database.postupdate.${bbdd.rdbms}" />
     <antcall target="update.dbupdate.timestamp" />
   </target>
@@ -111,11 +111,11 @@
   </target>
 
   <target name="update.database.script">
-    <alterscript driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter"  model="model/" filter="com.openbravo.db.OpenbravoMetadataFilter"  input="sourcedata" object="${bbdd.object}" failonerror="false" verbosity="${bbdd.verbosity}"  basedir="${base.modules}/" dirFilter="*/src-db/database/model/" datadir="${base.modules}/" dataFilter="*/src-db/database/sourcedata" userId="0" propertiesFile="${base.config}/Openbravo.properties" force="${force}" onlyIfModified="${onlyIfModified}" output="${bbdd.outputscript}" />
+    <alterscript driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter"  model="model/" filter="com.openbravo.db.OpenbravoMetadataFilter"  input="sourcedata" object="${bbdd.object}" failonerror="false" verbosity="${bbdd.verbosity}"  basedir="${base.modules}/" dirFilter="*/src-db/database/model/" datadir="${base.modules}/" dataFilter="*/src-db/database/sourcedata" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" force="${force}" onlyIfModified="${onlyIfModified}" output="${bbdd.outputscript}" />
   </target>
 
   <target name="export.database.structure">
-    <exportdatabase driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter" model="model" moduledir="${base.modules}" verbosity="${bbdd.verbosity}" output="sourcedata" codeRevision="${code.revision}" userId="0" propertiesFile="${base.config}/Openbravo.properties" force="${force}" validateModel="${validate.model}" testAPI="${isMinorVersion}" datasetList="AD,ADRD" rd="${rd}" />
+      <exportdatabase driver="${bbdd.driver}" url="${bbdd.owner.url}" user="${bbdd.user}" password="${bbdd.password}" excludeobjects="com.openbravo.db.OpenbravoExcludeFilter" model="model" moduledir="${base.modules}" verbosity="${bbdd.verbosity}" output="sourcedata" codeRevision="${code.revision}" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" force="${force}" validateModel="${validate.model}" testAPI="${isMinorVersion}" datasetList="AD,ADRD" rd="${rd}" />
   </target>
 
   <target name="database.postupdate.ORACLE">
--- a/src/build.xml	Wed Nov 18 14:14:12 2009 +0100
+++ b/src/build.xml	Wed Nov 18 14:17:21 2009 +0100
@@ -100,21 +100,21 @@
     <taskdef name="validateDatabase" classname="org.openbravo.service.system.SystemValidationTask">
       <classpath refid="project.class.path" />
     </taskdef>
-    <validateDatabase userId="0" propertiesFile="${base.config}/Openbravo.properties" type="database" />
+    <validateDatabase userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" type="database" />
   </target>
 
   <target name="validate.modules">
     <taskdef name="validateModules" classname="org.openbravo.service.system.SystemValidationTask">
       <classpath refid="project.class.path" />
     </taskdef>
-    <validateModules userId="0" propertiesFile="${base.config}/Openbravo.properties" type="module" />
+    <validateModules userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" type="module" />
   </target>
   
   <target name="load.logoimages">
     <taskdef name="imageloading" classname="org.openbravo.erpCommon.utility.ImageToDatabaseLoader">
       <classpath refid="project.class.path" />
     </taskdef>
-    <imageloading userId="0" propertiesFile="${base.config}/Openbravo.properties" basePath="${basedir}/../"
+    <imageloading userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" basePath="${basedir}/../"
       imagePaths="web/images/CompanyLogo_big.png,web/images/SupportLogo_big.png,web/images/CompanyLogo_small.png,web/skins/Default/Login/initialOpenbravoLogo.png,web/images/CompanyLogo_big.png"
       propertyNames="yourCompanyLoginImage,yourItServiceLoginImage,yourCompanyMenuImage,yourCompanyBigImage,yourCompanyDocumentImage"/>
   </target>
@@ -179,8 +179,8 @@
       <classpath refid="project.class.path" />
     </taskdef>
     <echo message="Exporting sample reference data" />
-    <exportsampledata userId="0" propertiesFile="${base.config}/Openbravo.properties" clients="SmallBazaar" />
-    <exportsampledata userId="0" propertiesFile="${base.config}/Openbravo.properties" clients="Accounting Test" />
+    <exportsampledata userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" clients="SmallBazaar" />
+    <exportsampledata userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" clients="Accounting Test" />
   </target>
 
   <target name="import.sample.data" description="Import Sample Data" depends="generate.entities">
@@ -188,7 +188,7 @@
       <classpath refid="project.class.path" />
     </taskdef>
     <echo message="Importing sample reference data" />
-    <importsampledata userId="0" propertiesFile="${base.config}/Openbravo.properties" />
+    <importsampledata userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" />
     <ant dir="${base.db}" target="database.postupdate.${bbdd.rdbms}" inheritAll="true" inheritRefs="true" />
   </target>
 
--- a/src/org/openbravo/dal/core/DalInitializingTask.java	Wed Nov 18 14:14:12 2009 +0100
+++ b/src/org/openbravo/dal/core/DalInitializingTask.java	Wed Nov 18 14:17:21 2009 +0100
@@ -47,6 +47,7 @@
   protected String userId;
   private String providerConfigDirectory;
   private boolean reInitializeModel;
+  private boolean adminMode = false;
 
   public String getPropertiesFile() {
     return propertiesFile;
@@ -113,6 +114,9 @@
     try {
       log.debug("Setting user context to user " + getUserId());
       OBContext.setOBContext(getUserId());
+      if (isAdminMode()) {
+        OBContext.enableAsAdminContext();
+      }
       doExecute();
       errorOccured = false;
     } finally {
@@ -121,6 +125,9 @@
       } else {
         OBDal.getInstance().commitAndClose();
       }
+      if (isAdminMode()) {
+        OBContext.resetAsAdminContext();
+      }
     }
   }
 
@@ -166,4 +173,12 @@
     PropertyConfigurator.configure(props);
   }
 
+  public boolean isAdminMode() {
+    return adminMode;
+  }
+
+  public void setAdminMode(boolean adminMode) {
+    this.adminMode = adminMode;
+  }
+
 }
--- a/src/org/openbravo/dal/core/OBContext.java	Wed Nov 18 14:14:12 2009 +0100
+++ b/src/org/openbravo/dal/core/OBContext.java	Wed Nov 18 14:17:21 2009 +0100
@@ -95,7 +95,7 @@
    */
   public static void setAdminContext() {
     if (adminContext == null) {
-      setOBContext("0");
+      setOBContext("0", "0", "0", "0");
       adminContext = getOBContext();
     } else {
       setOBContext(adminContext);