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;
$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();
$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();
#
#======================================================================
+use List::MoreUtils qw(uniq);
+
sub edit_groups {
$lxdebug->enter_sub();
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 {
}
$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);
}
$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);