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

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


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

commit 16526428f2ed9f4b2ded8763e7586a1055af7c38
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 9e5dc3d..f1be9b0 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
@@ -36,13 +36,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