From: hickert Date: Thu, 19 May 2011 09:05:12 +0000 (+0000) Subject: Prepared classes to support ACLs X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3c69944fb82273bba2f483267312924203311333;p=gosa.git Prepared classes to support ACLs git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20879 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc index e41f61f1f..978fc5f61 100644 --- a/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc +++ b/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc @@ -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 "
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(); } } diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget.inc index b5e48a5a6..76635ded6 100644 --- a/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget.inc +++ b/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget.inc @@ -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. diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_string.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_string.inc index 99dc273b8..546517aa5 100644 --- a/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_string.inc +++ b/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateWidget_string.inc @@ -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(""); } } diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/class_ConfigManagement.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/class_ConfigManagement.inc index 6bb37d2a6..f8db6f33f 100644 --- a/gosa-plugins/goto-ng/admin/newConfigManagement/class_ConfigManagement.inc +++ b/gosa-plugins/goto-ng/admin/newConfigManagement/class_ConfigManagement.inc @@ -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; }