This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 32cca8a  Fixed: Groovy DSL failed to use 'run service' from an event 
call (OFBIZ-12322)
32cca8a is described below

commit 32cca8a81b7f3cf6b3d58956aa783ce777dfdd32
Author: Nicolas Malin <[email protected]>
AuthorDate: Fri Sep 17 15:02:20 2021 +0200

    Fixed: Groovy DSL failed to use 'run service' from an event call 
(OFBIZ-12322)
    
    When you call a groovy script from an event controller, some information 
are present note on the same place on the binding context.
    
    Example if you call a groovy script as service you found the userLogin with 
parameters.userLogin or when you call it as event, the userLogin is on the 
binding context root.
    
    The problem appear with the DSL method 'run service' who search the missing 
value need by a service (userLogin, locale and timezone) on the map parameters 
on the binding context, so failed to populate correctly the information for an 
event.
    
    Call from event
        Map serviceResult = run service: 'createInvoice', with: [partyId: 
partyId, invoiceDate: nowTimestamp]
    
    Failed due to security issue : missing userLogin on the service context.
---
 .../org/apache/ofbiz/service/engine/GroovyBaseScript.groovy  | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git 
a/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
 
b/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
index 08b4cd9..319faf4 100644
--- 
a/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
+++ 
b/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
@@ -39,13 +39,19 @@ abstract class GroovyBaseScript extends Script {
         LocalDispatcher dispatcher = binding.getVariable('dispatcher')
         DispatchContext dctx = dispatcher.getDispatchContext()
         if (!inputMap.userLogin) {
-            inputMap.userLogin = 
this.binding.getVariable('parameters').userLogin
+            inputMap.userLogin = this.binding.hasVariable('userLogin')
+                    ? this.binding.getVariable('userLogin')
+                    : this.binding.getVariable('parameters').userLogin
         }
         if (!inputMap.timeZone) {
-            inputMap.timeZone = this.binding.getVariable('parameters').timeZone
+            inputMap.timeZone = this.binding.hasVariable('timeZone')
+                    ? this.binding.getVariable('timeZone')
+                    : this.binding.getVariable('parameters').timeZone
         }
         if (!inputMap.locale) {
-            inputMap.locale = this.binding.getVariable('parameters').locale
+            inputMap.locale = this.binding.hasVariable('locale')
+                    ? this.binding.getVariable('locale')
+                    : this.binding.getVariable('parameters').locale
         }
         Map serviceContext = dctx.makeValidContext(serviceName, 
ModelService.IN_PARAM, inputMap)
         Map result = dispatcher.runSync(serviceName, serviceContext)

Reply via email to