Code

Prepared classes to support ACLs
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 19 May 2011 09:05:12 +0000 (09:05 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 19 May 2011 09:05:12 +0000 (09:05 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20879 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget.inc
gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_string.inc
gosa-plugins/goto-ng/admin/newConfigManagement/class_ConfigManagement.inc

index e41f61f1f21176d31370d5f5561a2d9b70b8119d..978fc5f611bc7a467f4b0c904ccd91d3c5f35dbb 100644 (file)
@@ -58,18 +58,26 @@ class TemplateEngine
     }
    
     
-    function editItem($type, $values)
+    function editItem($type, $values, $acls = array())
     {
         $this->is_new = FALSE;
+        $this->setAcls($acls);
         $this->setValues($type, $values);
     }
  
 
-    function createItem($type, $values)
+    function createItem($type, $values, $acls = array())
     {
         $this->is_new = TRUE;
+        $this->setAcls($acls);
         $this->setValues($type, $values);
     }
+
+    
+    function setAcls($acls)
+    {
+        $this->acls = $acls;
+    }
  
 
     /*! \brief  Sets the current item type we want to render
@@ -109,6 +117,14 @@ class TemplateEngine
                 $syntax = (isset($item['syntax']))? $item['syntax']: "";
                 $providedValues = (isset($item['values']))? $item['values']: array();
    
+                // Get acl definition
+                if(isset($this->acls[$name])) {
+                    $acl = $this->acls[$name];
+                }else{
+                    print "<br> No ACL definition for '{$name}'.";
+                    $acl = "";
+                }
+
                 // Create the new widget.
                 $this->widgets[$name] = new $widgetClassName($this->config, $name, 
                         $value,
@@ -117,13 +133,21 @@ class TemplateEngine
                         $item['required'],
                         $item['type'],
                         $item['display'],
-                        $providedValues);
+                        $providedValues); 
                
+                // Get Permissions 
+                $writeable = preg_match("/w/", $acl);            
+                $readable = preg_match("/w/", $acl);            
+
                 // Check if we've to disable this item.
                 if(isset($item['disable']) && $item['disable'] || 
                         (isset($item['initiallyEditableOnly']) && $item['initiallyEditableOnly'] && !$this->is_new)){
-                    $this->widgets[$name]->setEnabled(FALSE);
+                    $writeable = FALSE;
                 }
+
+                // Set ACls 
+                $this->widgets[$name]->setWriteable($writeable);
+                $this->widgets[$name]->setReadable($readable);
             }
         }
     }
@@ -161,7 +185,7 @@ class TemplateEngine
     function save_object()
     {
         foreach($this->widgets as $widget){
-            if($widget->isEnabled()){
+            if($widget->isEnabled() && $widget->isWriteable()){
                 $widget->save_object();
             }
         }
index b5e48a5a6c1b6e99c97e0c54b018496ac1f5e488..76635ded6a60fefcfcc973620688bca96261a06e 100644 (file)
@@ -48,6 +48,22 @@ class TemplateWidget
         $this->enabled = $bool;
     }
 
+
+    /*! \brief  Sets the writeable status for a widget
+     */    
+    function setWriteable($bool = TRUE)
+    {
+        $this->writeable = $bool;
+    }
+    
+
+    /*! \brief  Sets the readable status for a widget
+     */    
+    function setReadable($bool = TRUE)
+    {
+        $this->readable = $bool;
+    }
+
     
     /*! \brief  Returns the enable status.
      */
@@ -57,6 +73,22 @@ class TemplateWidget
     }
 
 
+    /*! \brief  Returns the writeable status.
+     */
+    function isWriteable()
+    {
+        return($this->writeable);
+    }
+
+
+    /*! \brief  Returns the readable status.
+     */
+    function isReadable()
+    {
+        return($this->readable);
+    }
+
+
     /*! \brief  Returns the display-name for the current widget.
      *  @return  String     The display-name for the widget, this 
      *                       name will usually be rendered infront of input fields.
index 99dc273b83f1350b7f4c1f2eb2cf020bcad6eb16..546517aa5262d6fb2f269f67b66acf43e6af5d9e 100644 (file)
@@ -6,12 +6,13 @@ class TemplateWidget_string extends TemplateWidget
     {
         $desc = set_post($this->description);
         $value = set_post($this->value);
-        
+
         $name = " name=\"{$this->postName}\" ";
         $value = " value=\"{$value}\" ";
         $title = (empty($this->description))?"": " title=\"{$desc}\"";
         
-        $disabled = (!$this->enabled)? "disabled" : "";
+        $disabled = (!$this->enabled || !$this->writeable)? "disabled" : "";
+        $name = (!$this->enabled || !$this->writeable)? "dummy".rand(0,10000) : $name;
         return("<input type='text' {$title} {$name} {$value} {$disabled}>");
     }
 }
index 6bb37d2a6619838587a08541fedffd76636fe165..f8db6f33f4260ce64213a31850a916367741937c 100644 (file)
@@ -674,10 +674,20 @@ class ConfigManagement extends plugin
                 }
             }
         }
+        
+        // Collect property acls. The is only one ACL defined which controls all widgets.
+        $ui = get_userinfo();
+        $acls = array();
+        $acl = $ui->get_permissions($item['dn'], "ConfigManagement/ConfigManagement","cfgItem");
+        foreach(array_keys($this->itemConfig[$item['type']]['options']) as $attr){
+            $acls[$attr] = $acl;
+        }
 
+        // Update the template engine and set the item-config, values and the acls to use.
         $this->TemplateEngine->load($this->itemConfig);
         $this->TemplateEngine->setTemplate($method.".tpl");
-        $this->TemplateEngine->editItem($item['type'],$item['values']);
+        $this->TemplateEngine->editItem($item['type'],$item['values'], $acls);
+
         $this->listing->setDialogObject($this->TemplateEngine);
         $this->currentObject = $item;
     }
@@ -687,17 +697,27 @@ class ConfigManagement extends plugin
      */
     function newEntry($type)
     {
+        $item = $this->dataModel->getItemByPath($this->selectedContainer);
+            
+        // Collect property acls. The is only one ACL defined which controls all widgets.
+        $ui = get_userinfo();
+        $acls = array();
+        $acl = $ui->get_permissions($item['dn'], "ConfigManagement/ConfigManagement","cfgItem");
+        foreach(array_keys($this->itemConfig[$type]['options']) as $attr){
+            $acls[$attr] = $acl;
+        }
+
         // We've to add a config item
         $this->TemplateEngine->load($this->itemConfig);
         if($this->cfgItemMap[$type] != 'root'){
             $method = $this->cfgItemMap[$type];
             $this->TemplateEngine->setTemplate($method.".tpl");
-            $this->TemplateEngine->createItem($type,array());
+            $this->TemplateEngine->createItem($type, array(), $acls);
             $this->listing->setDialogObject($this->TemplateEngine);
             $this->currentObject = NULL;
         }else{
             $this->TemplateEngine->setTemplate("root.tpl");
-            $this->TemplateEngine->createItem($type,array());
+            $this->TemplateEngine->createItem($type, array(), $acls);
             $this->listing->setDialogObject($this->TemplateEngine);
             $this->currentObject = NULL;
         }