From bd9f619c6e6c2df333a64aa72f3bbc0774b0f44b Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 24 Nov 2013 12:01:54 +0000 Subject: [PATCH] allow removal of extension --- lam/lib/modules/sambaGroupMapping.inc | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lam/lib/modules/sambaGroupMapping.inc b/lam/lib/modules/sambaGroupMapping.inc index d63a8d38..4fc5628f 100644 --- a/lam/lib/modules/sambaGroupMapping.inc +++ b/lam/lib/modules/sambaGroupMapping.inc @@ -410,6 +410,12 @@ class sambaGroupMapping extends baseModule { $memberHelp = new htmlHelpLink('sambaSIDList'); $memberHelp->alignment = htmlElement::ALIGN_TOP; $return->addElement($memberHelp, true); + + $return->addElement(new htmlSpacer(null, '10px'), true); + + $remButton = new htmlButton('remObjectClass', _('Remove Samba 3 extension')); + $remButton->colspan = 3; + $return->addElement($remButton); } else { $return->addElement(new htmlButton('addObjectClass', _('Add Samba 3 extension'))); @@ -589,6 +595,7 @@ class sambaGroupMapping extends baseModule { $this->messages['sambaSID'][0] = array('ERROR', _('There can be only one group of this type.')); // third parameter must be set dynamically $this->messages['sambaSID'][1] = array('ERROR', _("Account %s:") . " (sambaGroupMapping_domain): " . _("LAM was unable to find a Samba 3 domain with this name!")); // third parameter must be set dynamically $this->messages['groupType'][0] = array('ERROR', _("Account %s:") . " (sambaGroupMapping_type): " . _("This is not a valid Samba 3 group type!"), _("Possible values") . ": %s"); + $this->messages['primaryGroup'][0] = array('ERROR', _('There are still users who have this group as their primary group.')); } @@ -629,6 +636,26 @@ class sambaGroupMapping extends baseModule { * @return array list of info/error messages */ function process_attributes() { + // remove extension + if (isset($_POST['remObjectClass'])) { + // check for users that have this group as primary group + $result = searchLDAPByAttribute('sambaPrimaryGroupSID', $this->attributes['sambaSID'][0], 'sambaSamAccount', array('dn'), array('user', 'host')); + if (sizeof($result) > 0) { + return array($this->messages['primaryGroup'][0]); + } + // remove attributes + $this->attributes['objectClass'] = array_delete(array('sambaGroupMapping'), $this->attributes['objectClass']); + $attrKeys = array_keys($this->attributes); + for ($k = 0; $k < sizeof($attrKeys); $k++) { + if (strpos($attrKeys[$k], 'samba') > -1) { + unset($this->attributes[$attrKeys[$k]]); + } + } + if (isset($this->attributes['displayName'])) { + unset($this->attributes['displayName']); + } + return array(); + } if (!in_array('sambaGroupMapping', $this->attributes['objectClass'])) { return array(); } @@ -699,7 +726,7 @@ class sambaGroupMapping extends baseModule { *
"info" are values with informational value (e.g. to be used later by pre/postModify actions) */ function save_attributes() { - if (!in_array('sambaGroupMapping', $this->attributes['objectClass'])) { + if (!in_array('sambaGroupMapping', $this->attributes['objectClass']) && !in_array('sambaGroupMapping', $this->orig['objectClass'])) { return array(); } return $this->getAccountContainer()->save_module_attributes($this->attributes, $this->orig);