Applied patch by Sven Geuer for the bugs he reported

* Fixes #23, #24, #25, #26
This commit is contained in:
Jan Dittberner 2008-11-16 16:54:08 +00:00
parent 120577d003
commit d2bd1b0ef0
3 changed files with 18 additions and 9 deletions

View file

@ -169,5 +169,7 @@ function cmp_by_usernames(&$user1, &$user2) {
$namemapdata = file_get_contents($davconfig['namemap.file']); $namemapdata = file_get_contents($davconfig['namemap.file']);
$namemap = json_decode($namemapdata, true); $namemap = json_decode($namemapdata, true);
if (is_array($namemap)) {
uasort($namemap, "cmp_by_usernames"); uasort($namemap, "cmp_by_usernames");
}
?> ?>

View file

@ -102,7 +102,7 @@ function displayusereditor(title, userid, username, firstname, lastname, groups)
return false; return false;
} }
} }
if (!this.groups.value.match(/^([0-9a-zA-z]+[,\s]*)+$/)) { if (!this.groups.value.match(/^[0-9a-zA-z]+(\s*,\s*[0-9a-zA-z]+)*$/)) {
alert(intl.translate("The groups field has to be a comma separated list of group names which must consist of letters or digits!")); alert(intl.translate("The groups field has to be a comma separated list of group names which must consist of letters or digits!"));
this.groups.focus(); this.groups.focus();
return false; return false;

View file

@ -123,7 +123,7 @@ function validateUserData(&$userdata, $forinsert) {
if (empty($userdata['lastname'])) { if (empty($userdata['lastname'])) {
$userdata['lastname'] = null; $userdata['lastname'] = null;
} }
if (!preg_match('/^([0-9a-zA-z]+[,\s]*)+$/', $userdata['groups'])) { if (!preg_match('/^[0-9a-zA-z]+(\s*,\s*[0-9a-zA-z]+)*$/', $userdata['groups'])) {
array_push($errormsgs, _('Groups must be a list of group names separated by commas. Group names must consist of letters and digits.')); array_push($errormsgs, _('Groups must be a list of group names separated by commas. Group names must consist of letters and digits.'));
} }
return $errormsgs; return $errormsgs;
@ -209,7 +209,12 @@ function updateGroups(&$userdata) {
fprintf($fh, "%s: %s\n", $group, implode(" ", $users)); fprintf($fh, "%s: %s\n", $group, implode(" ", $users));
$written[$group] = true; $written[$group] = true;
} else { } else {
fwrite($fh, $groupline); if (in_array($userdata['username'], $users)) {
array_splice($users, array_search($userdata['username'], $users),1);
}
if (count($users) > 0 ) {
fprintf($fh, "%s: %s\n", $group, implode(" ", $users));
}
} }
} }
foreach ($written as $group => $done) { foreach ($written as $group => $done) {
@ -286,8 +291,8 @@ function removeDigest($username) {
$digests = file($GLOBALS['davconfig']['digest.file']); $digests = file($GLOBALS['davconfig']['digest.file']);
$fh = fopen($GLOBALS['davconfig']['digest.file'], 'w'); $fh = fopen($GLOBALS['davconfig']['digest.file'], 'w');
foreach ($digests as $digest) { foreach ($digests as $digest) {
list($username, $realm, $data) = explode(":", $digest); list($user, $realm, $data) = explode(":", $digest);
if (!($username == $userdata['username'] if (!($user == $username
&& $realm == $GLOBALS['davconfig']['dav.realm'])) { && $realm == $GLOBALS['davconfig']['dav.realm'])) {
fwrite($fh, $digest); fwrite($fh, $digest);
} }
@ -311,10 +316,12 @@ function removeFromGroups($username) {
$users[$key] = trim($user); $users[$key] = trim($user);
} }
if (in_array($username, $users)) { if (in_array($username, $users)) {
$users = array_splice($users, array_search($username, $users)); array_splice($users, array_search($username, $users),1);
} }
if (count($users) > 0 ) {
fprintf($fh, "%s: %s\n", $group, implode(" ", $users)); fprintf($fh, "%s: %s\n", $group, implode(" ", $users));
} }
}
fclose($fh); fclose($fh);
} }