allow to add a user as memberuid in his primary group

This commit is contained in:
Roland Gruber 2008-03-15 19:12:19 +00:00
parent c6c9947dc6
commit 6c40ab33d7
2 changed files with 79 additions and 40 deletions

View File

@ -178,7 +178,14 @@ class posixAccount extends baseModule {
array('kind' => 'text', 'value' => ' '),
array('kind' => 'text', 'value' => ' '),
array('kind' => 'text', 'value' => ' '),
array('kind' => 'help', 'value' => 'pwdHash'))
array('kind' => 'help', 'value' => 'pwdHash')),
array(
array('kind' => 'text', 'text' => '<b>' . _('Set primary group as memberUid') . ":</b> "),
array('kind' => 'input', 'name' => 'posixAccount_primaryGroupAsSecondary', 'type' => 'checkbox'),
array('kind' => 'text', 'value' => '&nbsp;'),
array('kind' => 'text', 'value' => '&nbsp;'),
array('kind' => 'text', 'value' => '&nbsp;'),
array('kind' => 'help', 'value' => 'primaryGroupAsSecondary'))
);
// upload
$return['upload_preDepends'] = array('inetOrgPerson');
@ -320,6 +327,10 @@ class posixAccount extends baseModule {
);
// help Entries
$return['help'] = array(
'primaryGroupAsSecondary' => array(
'Headline' => _('Set primary group as memberUid'),
'Text' => _('Usually, users are not added to groups as memberUid if they have this group as primary group. If your application ignores primary groups then you can select this option to override this behaviour.')
),
'minMaxUser' => array(
'Headline' => _('UID number'),
'Text' => _('These are the minimum and maximum numbers to use for user IDs when creating new user accounts. The range should be different from that of machines. New user accounts will always get the highest number in use plus one.')
@ -488,9 +499,18 @@ class posixAccount extends baseModule {
function save_attributes() {
$return = $this->getAccountContainer()->save_module_attributes($this->attributes, $this->orig);
// Remove primary group from additional groups
if (!isset($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0])
|| ($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0] != 'true')) {
for ($i=0; $i<count($this->groups); $i++) {
if ($this->groups[$i]==$_SESSION['cache']->getgrnam($this->attributes['gidNumber'][0])) unset($this->groups[$i]);
}
}
else {
// add user as memberuid in primary group
if (!in_array($_SESSION['cache']->getgrnam($this->attributes['gidNumber'][0]), $this->groups)) {
$this->groups[] = $_SESSION['cache']->getgrnam($this->attributes['gidNumber'][0]);
}
}
// Set additional group memberships
if ($this->orig['uid'][0]!='' && $this->attributes['uid'][0]!=$this->orig['uid'][0]) {
@ -1540,6 +1560,19 @@ class posixAccount extends baseModule {
if (in_array($i, $failed)) continue; // ignore failed accounts
if ($data[$i][$col] != "") {
$groups = explode(",", $data[$i][$col]);
if (isset($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0])
&& ($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0] == 'true')) {
if (get_preg($data[$i][$ids['posixAccount_group']], 'digit')) {
if (!in_array(getgrnam($data[$i][$ids['posixAccount_group']]), $groups)) {
$groups[] = getgrnam($data[$i][$ids['posixAccount_group']]);
}
}
else {
if (!in_array(getgrnam($data[$i][$ids['posixAccount_group']]), $groups)) {
$groups[] = $data[$i][$ids['posixAccount_group']];
}
}
}
for ($g = 0; $g < sizeof($groups); $g++) {
if (!in_array($groups[$g], $temp['groups'])) $temp['groups'][] = $groups[$g];
$temp['members'][$groups[$g]][] = $data[$i][$ids['posixAccount_userName']];

View File

@ -217,35 +217,41 @@ class posixGroup extends baseModule {
// users who can be added have a uid and gidNumber
if (isset($dn_users[$DNs[$i]]['uid'][0]) && isset($dn_users[$DNs[$i]]['gidNumber'][0]) &&
// are not already member
(!isset($this->attributes['memberUid']) || !in_array($dn_users[$DNs[$i]]['uid'][0], $this->attributes['memberUid'])) &&
// and do not have this group as their primary group
!($this->attributes['gidNumber'][0] == $dn_users[$DNs[$i]]['gidNumber'][0])) {
(!isset($this->attributes['memberUid']) || !in_array($dn_users[$DNs[$i]]['uid'][0], $this->attributes['memberUid']))) {
if ($this->attributes['gidNumber'][0] == $dn_users[$DNs[$i]]['gidNumber'][0]) {
if (isset($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0])
&& ($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0] == 'true')) {
$users[] = $dn_users[$DNs[$i]]['uid'][0];
}
}
else {
$users[] = $dn_users[$DNs[$i]]['uid'][0];
}
}
}
}
$return[] = array(
0 => array('kind' => 'fieldset', 'legend' => _("Group members"), 'value' => array (
0 => array(
0 => array('kind' => 'fieldset', 'td' => array ('valign' => 'top'), 'legend' => _("Selected users"), 'value' => array (
0 => array(
0 => array ( 'kind' => 'select', 'name' => 'removeusers', 'size' => '15', 'multiple' => true, 'options' => $this->attributes['memberUid'])))),
1 => array('kind' => 'table', 'value' => array(
0 => array(
0 => array('kind' => 'input', 'type' => 'submit', 'name' => 'addusers_button', 'value' => '<=', 'td' => array('align' => 'center'))),
1 => array(
0 => array('kind' => 'input', 'type' => 'submit', 'name' => 'removeusers_button', 'value' => '=>', 'td' => array('align' => 'center'))),
2 => array(
0 => array('kind' => 'help', 'value' => 'members', 'td' => array('align' => 'center'))))),
2 => array('kind' => 'fieldset', 'td' => array('valign' => 'top'), 'legend' => _("Available users"), 'value' => array(
0 => array(
0 => array('kind' => 'select', 'name' => 'addusers', 'size' => '15', 'multiple' => true, 'options' => $users))))
array('kind' => 'fieldset', 'legend' => _("Group members"), 'value' => array (
array(
array('kind' => 'fieldset', 'td' => array ('valign' => 'top'), 'legend' => _("Selected users"), 'value' => array (
array(
array ( 'kind' => 'select', 'name' => 'removeusers', 'size' => '15', 'multiple' => true, 'options' => $this->attributes['memberUid'])))),
array('kind' => 'table', 'value' => array(
array(
array('kind' => 'input', 'type' => 'submit', 'name' => 'addusers_button', 'value' => '<=', 'td' => array('align' => 'center'))),
array(
array('kind' => 'input', 'type' => 'submit', 'name' => 'removeusers_button', 'value' => '=>', 'td' => array('align' => 'center'))),
array(
array('kind' => 'help', 'value' => 'members', 'td' => array('align' => 'center'))))),
array('kind' => 'fieldset', 'td' => array('valign' => 'top'), 'legend' => _("Available users"), 'value' => array(
array(
array('kind' => 'select', 'name' => 'addusers', 'size' => '15', 'multiple' => true, 'options' => $users))))
))));
$return[] = array(
0 => array('kind' => 'input', 'name' => 'form_subpage_posixGroup_attributes_back' ,'type' => 'submit', 'value' => _('Back') ),
1 => array('kind' => 'text'),
2 => array('kind' => 'text'));
array('kind' => 'input', 'name' => 'form_subpage_posixGroup_attributes_back' ,'type' => 'submit', 'value' => _('Back') ),
array('kind' => 'text'),
array('kind' => 'text'));
return $return;
}