diff --git a/include/class_CopyPasteHandler.inc b/include/class_CopyPasteHandler.inc index f410e19402a023677efe263dacc537de24c799dd..bcceb4086b1246a3cb2bcef9dcc62605a2799b6e 100644 --- a/include/class_CopyPasteHandler.inc +++ b/include/class_CopyPasteHandler.inc @@ -98,11 +98,12 @@ class CopyPasteHandler $tmp['dn'] = $dn; if (func_num_args() == 3) { - $type = func_get_arg(2); - $tmp['type'] = $type; - $infos = objects::infos($type); - $tmp['tab_acl_category'] = $infos['aclCategory']; - $tmp['parent'] = NULL; + $type = func_get_arg(2); + $tmp['type'] = $type; + $infos = objects::infos($type); + $tmp['aclCategory'] = $infos['aclCategory']; + $tmp['mainTab'] = $infos['mainTab']; + $tmp['parent'] = NULL; } else { // Deprecated $tab_class = func_get_arg(2); @@ -122,10 +123,11 @@ class CopyPasteHandler trigger_error(sprintf("Specified tab object '%s' does not exists.", $tab_object)); return FALSE; } - $tmp['tab_class'] = $tab_class; - $tmp['tab_object'] = $tab_object; - $tmp['tab_acl_category'] = $tab_acl_category; - $tmp['parent'] = $parent; + $tmp['tab_class'] = $tab_class; + $tmp['tab_object'] = $tab_object; + $tmp['aclCategory'] = $tab_acl_category; + $tmp['mainTab'] = reset($config->data['TABS'][$tab_object]); + $tmp['parent'] = $parent; } $this->queue[] = $tmp; @@ -174,7 +176,7 @@ class CopyPasteHandler // old way $tab_c = $entry['tab_class']; $tab_o = $entry['tab_object']; - $tab_a = $entry['tab_acl_category']; + $tab_a = $entry['aclCategory']; // Deprecated $entry['object'] = new $tab_c(NULL, $config->data['TABS'][$tab_o], $entry['dn'], $tab_a); @@ -220,12 +222,9 @@ class CopyPasteHandler } $msgs = $entry['object']->check(); - /* To copy an object we require full read access to the object category */ - $copy_acl = preg_match("/r/", $ui->get_complete_category_acls($entry['dn'], $entry['tab_acl_category'])); - - /* In order to copy an object we require read an delete acls */ - $cut_acl = preg_match("/d/", $ui->get_complete_category_acls($entry['dn'], $entry['tab_acl_category'])); - $cut_acl &= preg_match("/r/", $ui->get_complete_category_acls($entry['dn'], $entry['tab_acl_category'])); + /* Retrieve ACL infos */ + $copy_acl = $ui->is_copyable($entry['dn'], $entry['aclCategory']); + $cut_acl = $ui->is_cutable($entry['dn'], $entry['aclCategory'], $entry['mainTab']); /* Check permissions */ if ($entry['method'] == "copy" && !$copy_acl) { @@ -243,7 +242,7 @@ class CopyPasteHandler foreach ($this->disallowed_objects as $entry) { $dns[] = $entry['dn']; } - msg_dialog::display(_("Permission"), msgPool::permCreate($dns), INFO_DIALOG); + msg_dialog::display(_('Permission'), msgPool::permCreate($dns), INFO_DIALOG); } $this->require_update = FALSE; } diff --git a/include/class_userinfo.inc b/include/class_userinfo.inc index 81a981416da718a447f4857a36af55bf7018ced1..91105bbb45c10313f11fc03f8b73a9356783f59b 100644 --- a/include/class_userinfo.inc +++ b/include/class_userinfo.inc @@ -328,8 +328,8 @@ class userinfo */ function is_cutable($dn, $object, $class) { - $remove = preg_match("/d/", $this->get_permissions($dn, $object."/".$class)); - $read = preg_match("/r/", $this->get_complete_category_acls($dn, $object)); + $remove = preg_match('/d/', $this->get_permissions($dn, $object.'/'.$class)); + $read = preg_match('/r/', $this->get_complete_category_acls($dn, $object)); return ($remove && $read); } @@ -769,7 +769,6 @@ class userinfo /*! * \brief Return combined acls for a given category * - * #FIXME This could be logical wrong or could be optimized in the future * Return combined acls for a given category. * All acls will be combined like boolean AND * As example ('rwcdm' + 'rcd' + 'wrm'= 'r') @@ -786,34 +785,35 @@ class userinfo function get_complete_category_acls($dn, $category) { global $config; - $acl = "rwcdm"; - $types = "rwcdm"; + $acl = 'rwcdm'; if (!is_string($category)) { - trigger_error("category must be string"); - $acl = ""; + trigger_error('category must be string'); + return ''; } else { - if (!isset($this->result_cache['get_complete_category_acls'][$dn][$category])) { - if (isset($config->data['CATEGORIES'][$category])) { - foreach ($config->data['CATEGORIES'][$category]['classes'] as $oc) { - /* Skip objectClass '0' (e.g. user/0) get_permissions will ever return '' ?? */ - if ($oc == "0") continue; - $tmp = $this->get_permissions($dn, $category."/".$oc); - for ($i = 0, $l = strlen($types); $i < $l; $i++) { - if (!preg_match("/".$types[$i]."/", $tmp)) { - $acl = preg_replace("/".$types[$i]."/", "", $acl); - } + if (isset($this->result_cache['get_complete_category_acls'][$dn][$category])) { + return $this->result_cache['get_complete_category_acls'][$dn][$category]; + } + if (isset($config->data['CATEGORIES'][$category])) { + foreach ($config->data['CATEGORIES'][$category]['classes'] as $oc) { + if ($oc == '0') { + /* Skip objectClass '0' (e.g. user/0) */ + continue; + } + $tmp = $this->get_permissions($dn, $category.'/'.$oc); + $types = $acl; + for ($i = 0, $l = strlen($types); $i < $l; $i++) { + if (!preg_match('/'.$types[$i].'/', $tmp)) { + $acl = preg_replace('/'.$types[$i].'/', '', $acl); } } - } else { - $acl = ""; } - $this->result_cache['get_complete_category_acls'][$dn][$category] = $acl; } else { - $acl = $this->result_cache['get_complete_category_acls'][$dn][$category]; + $acl = ''; } + $this->result_cache['get_complete_category_acls'][$dn][$category] = $acl; + return $acl; } - return $acl; } diff --git a/include/simpleplugin/class_simpleManagement.inc b/include/simpleplugin/class_simpleManagement.inc index 0153bf6bce3f09749667dbca04718d3d9a8686f4..5daa5c549f15a7fd3aa9af11539baf4f9f358738 100644 --- a/include/simpleplugin/class_simpleManagement.inc +++ b/include/simpleplugin/class_simpleManagement.inc @@ -826,7 +826,7 @@ class simpleManagement extends management $this->cpHandler->save_object(); // Add entries to queue - if ($action == "copy" || $action == "cut") { + if (($action == 'copy') || ($action == 'cut')) { $this->cpHandler->cleanup_queue(); foreach ($target as $dn) { $type = $this->getType($dn); @@ -835,13 +835,13 @@ class simpleManagement extends management } $infos = objects::infos($type); - if ($action == "copy" && $ui->is_copyable($dn, $infos['aclCategory'], $infos['mainTab'])) { - $this->cpHandler->add_to_queue($dn, "copy", $type); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, "Entry copied!"); + if (($action == 'copy') && $ui->is_copyable($dn, $infos['aclCategory'], $infos['mainTab'])) { + $this->cpHandler->add_to_queue($dn, 'copy', $type); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Entry copied!'); } - if ($action == "cut" && $ui->is_cutable($dn, $infos['aclCategory'], $infos['mainTab'])) { - $this->cpHandler->add_to_queue($dn, "cut", $type); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, "Entry cutted!"); + if (($action == 'cut') && $ui->is_cutable($dn, $infos['aclCategory'], $infos['mainTab'])) { + $this->cpHandler->add_to_queue($dn, 'cut', $type); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Entry cut!'); } } }