You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/02/15 20:19:20 UTC

svn commit: r508090 - in /ofbiz/trunk/framework/widget: dtd/widget-screen.xsd src/org/ofbiz/widget/screen/ModelScreenCondition.java

Author: jaz
Date: Thu Feb 15 11:19:19 2007
New Revision: 508090

URL: http://svn.apache.org/viewvc?view=rev&rev=508090
Log:
added special context-map to allow pre-filling fields in actions to pass to the security serivice; using this will help prevent overriding fields when not intending to

Modified:
    ofbiz/trunk/framework/widget/dtd/widget-screen.xsd
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java

Modified: ofbiz/trunk/framework/widget/dtd/widget-screen.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-screen.xsd?view=diff&rev=508090&r1=508089&r2=508090
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-screen.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-screen.xsd Thu Feb 15 11:19:19 2007
@@ -97,6 +97,7 @@
     <xs:attributeGroup name="attlist.if-service-permission">
         <xs:attribute type="xs:string" name="service-name" use="required"/>
         <xs:attribute type="xs:string" name="resource-description" use="optional"/>
+        <xs:attribute type="xs:string" name="context-map" use="optional"/>
         <xs:attribute name="main-action" use="optional">
             <xs:simpleType>
                 <xs:restriction base="xs:token">

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java?view=diff&rev=508090&r1=508089&r2=508090
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java Thu Feb 15 11:19:19 2007
@@ -205,13 +205,15 @@
     public static class IfServicePermission extends ScreenCondition {
         protected FlexibleStringExpander serviceExdr;
         protected FlexibleStringExpander actionExdr;
+        protected FlexibleStringExpander ctxMapExdr;
         protected FlexibleStringExpander resExdr;
 
         public IfServicePermission(ModelScreen modelScreen, Element condElement) {
             super(modelScreen, condElement);
             this.serviceExdr = new FlexibleStringExpander(condElement.getAttribute("service-name"));
             this.actionExdr = new FlexibleStringExpander(condElement.getAttribute("main-action"));
-            this.resExdr = new FlexibleStringExpander(condElement.getAttribute("resource-description"));            
+            this.ctxMapExdr = new FlexibleStringExpander(condElement.getAttribute("context-map"));
+            this.resExdr = new FlexibleStringExpander(condElement.getAttribute("resource-description"));
         }
 
         public boolean eval(Map context) {
@@ -220,16 +222,29 @@
             if (userLogin != null) {
                 String serviceName = serviceExdr.expandString(context);
                 String mainAction = actionExdr.expandString(context);
+                String contextMap = ctxMapExdr.expandString(context);
                 String resource = resExdr.expandString(context);
-                if (resource == null) {
+                if (UtilValidate.isEmpty(resource)) {
                     resource = serviceName;
                 }
                 
-                if (serviceName == null) {
+                if (UtilValidate.isEmpty(serviceName)) {
                     Debug.logWarning("No permission service-name specified!", module);
                     return false;
                 }
 
+                Map serviceContext;
+                Object internalSvcMap = context.get(contextMap);
+                if (internalSvcMap != null && (internalSvcMap instanceof Map)) {
+                    serviceContext = (Map) internalSvcMap;
+
+                    // copy the required internal fields
+                    serviceContext.put("userLogin", context.get("userLogin"));
+                    serviceContext.put("locale", context.get("locale"));
+                } else {
+                    serviceContext = context;
+                }
+
                 // get the service objects
                 LocalDispatcher dispatcher = this.modelScreen.getDispatcher(context);
                 DispatchContext dctx = dispatcher.getDispatchContext();
@@ -245,7 +260,7 @@
 
                 if (permService != null) {
                     // build the context
-                    Map svcCtx = permService.makeValid(context, ModelService.IN_PARAM);
+                    Map svcCtx = permService.makeValid(serviceContext, ModelService.IN_PARAM);
                     svcCtx.put("resourceDescription", resource);
                     if (UtilValidate.isNotEmpty(mainAction)) {
                         svcCtx.put("mainAction", mainAction);