From: Sven Schöling Date: Thu, 24 Sep 2009 14:53:54 +0000 (+0200) Subject: Mehrere Sanity Checks um zu verhindern, dass $group->{members} Dublikate enthält. X-Git-Tag: release-2.6.1beta1~275^2~3 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=5c0c9e6763bc9f129cdeff5cbaa564787af0a9bc;p=kivitendo-erp.git Mehrere Sanity Checks um zu verhindern, dass $group->{members} Dublikate enthält. Hoffentlich Fix für Bug 1057. --- diff --git a/SL/Auth.pm b/SL/Auth.pm index 94f843a6d..97f1d8270 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -11,6 +11,7 @@ use constant SESSION_EXPIRED => 2; use Digest::MD5 qw(md5_hex); use IO::File; use Time::HiRes qw(gettimeofday); +use List::MoreUtils qw(uniq); use SL::Auth::DB; use SL::Auth::LDAP; @@ -704,13 +705,14 @@ sub read_groups { $sth = prepare_query($form, $dbh, $query); foreach $group (values %{$groups}) { - $group->{members} = []; + my @members; do_statement($form, $sth, $query, $group->{id}); while ($row = $sth->fetchrow_hashref()) { - push @{$group->{members}}, $row->{user_id}; + push @members, $row->{user_id}; } + $group->{members} = [ uniq @members ]; } $sth->finish(); @@ -760,7 +762,7 @@ sub save_group { $query = qq|INSERT INTO auth.user_group (user_id, group_id) VALUES (?, ?)|; $sth = prepare_query($form, $dbh, $query); - foreach my $user_id (@{ $group->{members} }) { + foreach my $user_id (uniq @{ $group->{members} }) { do_statement($form, $sth, $query, $user_id, $group->{id}); } $sth->finish(); diff --git a/bin/mozilla/admin_groups.pl b/bin/mozilla/admin_groups.pl index b75af930e..d84e2e541 100644 --- a/bin/mozilla/admin_groups.pl +++ b/bin/mozilla/admin_groups.pl @@ -32,6 +32,8 @@ # #====================================================================== +use List::MoreUtils qw(uniq); + sub edit_groups { $lxdebug->enter_sub(); @@ -114,9 +116,9 @@ sub edit_group { my %all_users = $auth->read_all_users(); my %users_by_id = map { $_->{id} => $_ } values %all_users; - my @members = sort { lc $a->{login} cmp lc $b->{login} } @users_by_id{ @{ $group->{members} } }; + my @members = uniq sort { lc $a->{login} cmp lc $b->{login} } @users_by_id{ @{ $group->{members} } }; - my %grouped = map { $_ => 1 } @{ $group->{members} }; + my %grouped = map { $_ => 1 } uniq @{ $group->{members} }; my @non_members = sort { lc $a->{login} cmp lc $b->{login} } grep { !$grouped{$_->{id}} } values %all_users; my @rights = map { @@ -173,7 +175,7 @@ sub add_to_group { } $group = $groups->{$form->{group_id}}; - push @{ $group->{members} }, $form->{user_id_not_in_group}; + $group->{members} = [ uniq @{ $group->{members} }, $form->{user_id_not_in_group} ]; $auth->save_group($group); @@ -195,7 +197,7 @@ sub remove_from_group { } $group = $groups->{$form->{group_id}}; - $group->{members} = [ grep { $_ ne $form->{user_id_in_group} } @{ $group->{members} } ]; + $group->{members} = [ uniq grep { $_ ne $form->{user_id_in_group} } @{ $group->{members} } ]; $auth->save_group($group);