From: hickert Date: Wed, 12 Dec 2007 14:03:47 +0000 (+0000) Subject: Updated posix plugin X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8af5f87fa6ebbd4fde4b5b449471d99ad4c54ed8;p=gosa.git Updated posix plugin - Group membership is now editable for multiple users git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8105 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_multi_plug.inc b/gosa-core/include/class_multi_plug.inc index 06a3ccd7a..f9a02ba3e 100644 --- a/gosa-core/include/class_multi_plug.inc +++ b/gosa-core/include/class_multi_plug.inc @@ -279,15 +279,12 @@ class multi_plug */ public function populate_values() { - if($this->multiple_available() && is_array($this->a_handles)){ foreach($this->o_tab->by_object as $name => $obj){ $values = $this->o_tab->by_object[$name]->get_multi_edit_values(); foreach($this->a_handles as $i_id => $o_handle){ - foreach($values as $a_name => $a_value){ - $this->a_handles[$i_id]->by_object[$name]->$a_name = $a_value; - } + $this->a_handles[$i_id]->by_object[$name]->set_multi_edit_values($values); } } } diff --git a/gosa-core/include/class_plugin.inc b/gosa-core/include/class_plugin.inc index da0a6c4d1..9d4434090 100644 --- a/gosa-core/include/class_plugin.inc +++ b/gosa-core/include/class_plugin.inc @@ -1726,6 +1726,16 @@ class plugin return($ret); } + + /*! \brief Update class variables with values collected by multiple edit. + */ + function set_multi_edit_values($attrs) + { + foreach($attrs as $name => $value){ + $this->$name = $value; + } + } + /*! \brief execute plugin diff --git a/gosa-core/plugins/personal/posix/class_posixAccount.inc b/gosa-core/plugins/personal/posix/class_posixAccount.inc index e1a5412c9..e2430559e 100644 --- a/gosa-core/plugins/personal/posix/class_posixAccount.inc +++ b/gosa-core/plugins/personal/posix/class_posixAccount.inc @@ -80,6 +80,7 @@ class posixAccount extends plugin var $uid= ""; var $multiple_support = TRUE; + var $groupMembership_some = array(); /* constructor, if 'dn' is set, the node loads the given 'dn' from LDAP */ @@ -509,10 +510,15 @@ class posixAccount extends plugin $smarty->assign("shells", $this->loginShellList); $smarty->assign("secondaryGroups", $this->secondaryGroups); $smarty->assign("primaryGroup", $this->primaryGroup); - if (!count($this->groupMembership)){ - $smarty->assign("groupMembership", array(" ")); - } else { + if(!$this->multiple_support_active){ + if (!count($this->groupMembership)){ + $smarty->assign("groupMembership", array(" ")); + } else { + $smarty->assign("groupMembership", $this->groupMembership); + } + }else{ $smarty->assign("groupMembership", $this->groupMembership); + $smarty->assign("groupMembership_some", $this->groupMembership_some); } if (count($this->groupMembership) > 16){ $smarty->assign("groups", "too_many_for_nfs"); @@ -1038,6 +1044,7 @@ class posixAccount extends plugin /* Walk through groups and add the descriptive entry if not exists */ foreach ($groups as $value){ + if (!array_key_exists($value, $this->groupMembership)){ $ldap->cat($value, array('cn', 'description', 'dn')); $attrs= $ldap->fetch(); @@ -1052,6 +1059,9 @@ class posixAccount extends plugin if(obj_is_writable($attrs['dn'],"groups/group","memberUid")){ $this->groupMembership[$attrs['dn']]= $entry; + if($this->multiple_support_active && isset($this->groupMembership_some[$attrs['dn']])){ + unset($this->groupMembership_some[$attrs['dn']]); + } } } } @@ -1070,6 +1080,11 @@ class posixAccount extends plugin if(isset($this->groupMembership[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){ unset($this->groupMembership[$dn_to_del]); } + if($this->multiple_support_active){ + if(isset($this->groupMembership_some[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){ + unset($this->groupMembership_some[$dn_to_del]); + } + } } } @@ -1403,6 +1418,8 @@ class posixAccount extends plugin function get_multi_edit_values() { $ret = plugin::get_multi_edit_values(); + $ret['groupMembership'] = $this->groupMembership; + $ret['groupMembership_some']= $this->groupMembership_some; return($ret); } @@ -1427,6 +1444,73 @@ class posixAccount extends plugin } } } + + function init_multiple_support($attrs,$all) + { + plugin::init_multiple_support($attrs,$all); + + restore_error_handler(); + + $groups_some = array(); + $groups_all = array(); + $groups_uid = array(); + $uids = array(); + $first = TRUE; + + $uid_filter=""; + for($i =0; $i < $this->multi_attrs_all['uid']['count'] ; $i ++){ + $uid = $this->multi_attrs_all['uid'][$i]; + $uids[] = $uid; + $uid_filter.= "(memberUid=".$uid.")"; + } + $uid_filter = "(&(objectClass=posixGroup)(|".$uid_filter."))"; + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search($uid_filter,array("dn","cn","memberUid")); + while($group = $ldap->fetch()){ + $groups_some[$group['dn']] = $group['cn'][0]; + for($i = 0 ; $i < $group['memberUid']['count'] ; $i++){ + $groups_uid[$group['dn']][] = $group['memberUid'][$i]; + } + } + + $groups_all = $groups_some; + foreach($groups_all as $id => $group){ + foreach($uids as $uid){ + if(!in_array($uid,$groups_uid[$id])){ + unset($groups_all[$id]); + break; + } + } + } + + $this->groupMembership = $groups_all; + foreach( $groups_all as $dn => $cn){ + if(isset($groups_some[$dn])){ + unset($groups_some[$dn]); + } + } + $this->groupMembership_some = $groups_some; + } + + + function set_multi_edit_values($attrs) + { + $groups = array(); + + /* Update groupMembership, keep optinal group */ + foreach($attrs['groupMembership_some'] as $dn => $cn){ + if(isset($this->groupMembership[$dn])){ + $groups[$dn] = $cn; + } + } + /* Update groupMembership, add forced groups */ + foreach($attrs['groupMembership'] as $dn => $cn){ + $groups[$dn] = $cn; + } + plugin::set_multi_edit_values($attrs); + $this->groupMembership = $groups; + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-core/plugins/personal/posix/generic.tpl b/gosa-core/plugins/personal/posix/generic.tpl index c9dc98d47..5371c53b7 100644 --- a/gosa-core/plugins/personal/posix/generic.tpl +++ b/gosa-core/plugins/personal/posix/generic.tpl @@ -89,8 +89,13 @@ {if !$multiple_support} {html_options options=$groupMembership} {else} - - + {foreach from=$groupMembership item=group key=key} + + {/foreach} + {foreach from=$groupMembership_some item=group key=key} + + {/foreach} {/if} {/render}