diff options
author | lpsolit%gmail.com <> | 2009-01-25 19:49:30 +0100 |
---|---|---|
committer | lpsolit%gmail.com <> | 2009-01-25 19:49:30 +0100 |
commit | ca06c57995ed327879e4c23b58e1330d4bd27d18 (patch) | |
tree | 55551daf4341fed6cac00eda8c68ae7932786f5c | |
parent | d3f1b1a3ecc5f068179d5fba70e86b345c1aec63 (diff) | |
download | bugzilla-ca06c57995ed327879e4c23b58e1330d4bd27d18.tar.gz bugzilla-ca06c57995ed327879e4c23b58e1330d4bd27d18.tar.xz |
Bug 405355: Move flatten_group_membership() from User.pm to Group.pm - Patch by arbingersys <arbingersys@gmail.com> r/a=LpSolit
-rw-r--r-- | Bugzilla/Group.pm | 35 | ||||
-rw-r--r-- | Bugzilla/Install.pm | 2 | ||||
-rw-r--r-- | Bugzilla/Search.pm | 4 | ||||
-rw-r--r-- | Bugzilla/User.pm | 35 | ||||
-rwxr-xr-x | editgroups.cgi | 4 | ||||
-rwxr-xr-x | editusers.cgi | 2 | ||||
-rwxr-xr-x | whine.pl | 3 |
7 files changed, 45 insertions, 40 deletions
diff --git a/Bugzilla/Group.pm b/Bugzilla/Group.pm index 455276c99..e33ce6347 100644 --- a/Bugzilla/Group.pm +++ b/Bugzilla/Group.pm @@ -238,6 +238,33 @@ sub members_non_inherited { return $self->{members_non_inherited}; } +sub flatten_group_membership { + my ($self, @groups) = @_; + + my $dbh = Bugzilla->dbh; + my $sth; + my @groupidstocheck = @groups; + my %groupidschecked = (); + $sth = $dbh->prepare("SELECT member_id FROM group_group_map + WHERE grantor_id = ? + AND grant_type = " . GROUP_MEMBERSHIP); + while (my $node = shift @groupidstocheck) { + $sth->execute($node); + my $member; + while (($member) = $sth->fetchrow_array) { + if (!$groupidschecked{$member}) { + $groupidschecked{$member} = 1; + push @groupidstocheck, $member; + push @groups, $member unless grep $_ == $member, @groups; + } + } + } + return \@groups; +} + + + + ################################ ##### Module Subroutines ### ################################ @@ -394,4 +421,12 @@ Returns an arrayref of L<Bugzilla::User> objects representing people who are the group regular expression, or they have been actually added to the group manually. +=item C<flatten_group_membership> + +Accepts a list of groups and returns a list of all the groups whose members +inherit membership in any group on the list. So, we can determine if a user +is in any of the groups input to flatten_group_membership by querying the +user_group_map for any user with DIRECT or REGEXP membership IN() the list +of groups returned. + =back diff --git a/Bugzilla/Install.pm b/Bugzilla/Install.pm index 3d382add8..0a1f0e955 100644 --- a/Bugzilla/Install.pm +++ b/Bugzilla/Install.pm @@ -274,7 +274,7 @@ sub create_admin { my $admin_group = new Bugzilla::Group({ name => 'admin' }); my $admin_inheritors = - Bugzilla::User->flatten_group_membership($admin_group->id); + Bugzilla::Group->flatten_group_membership($admin_group->id); my $admin_group_ids = join(',', @$admin_inheritors); my ($admin_count) = $dbh->selectrow_array( diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index de02115fe..2b3b23044 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -1067,7 +1067,7 @@ sub _contact_exact_group { my $group = $1; my $groupid = Bugzilla::Group::ValidateGroupName( $group, ($user)); $groupid || ThrowUserError('invalid_group_name',{name => $group}); - my @childgroups = @{$user->flatten_group_membership($groupid)}; + my @childgroups = @{Bugzilla::Group->flatten_group_membership($groupid)}; my $table = "user_group_map_$$chartid"; push (@$supptables, "LEFT JOIN user_group_map AS $table " . "ON $table.user_id = bugs.$$f " . @@ -1139,7 +1139,7 @@ sub _cc_exact_group { my $group = $1; my $groupid = Bugzilla::Group::ValidateGroupName( $group, ($user)); $groupid || ThrowUserError('invalid_group_name',{name => $group}); - my @childgroups = @{$user->flatten_group_membership($groupid)}; + my @childgroups = @{Bugzilla::Group->flatten_group_membership($groupid)}; my $chartseq = $$chartid; if ($$chartid eq "") { $chartseq = "CC$$sequence"; diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 0c0f45bc0..fe04856aa 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -48,6 +48,7 @@ use Bugzilla::User::Setting; use Bugzilla::Product; use Bugzilla::Classification; use Bugzilla::Field; +use Bugzilla::Group; use Scalar::Util qw(blessed); use DateTime::TimeZone; @@ -830,7 +831,7 @@ sub visible_groups_inherited { return $self->{visible_groups_inherited} if defined $self->{visible_groups_inherited}; return [] unless $self->id; my @visgroups = @{$self->visible_groups_direct}; - @visgroups = @{$self->flatten_group_membership(@visgroups)}; + @visgroups = @{Bugzilla::Group->flatten_group_membership(@visgroups)}; $self->{visible_groups_inherited} = \@visgroups; return $self->{visible_groups_inherited}; } @@ -992,30 +993,6 @@ sub can_bless { return grep($_->id == $group_id, @{ $self->bless_groups }) ? 1 : 0; } -sub flatten_group_membership { - my ($self, @groups) = @_; - - my $dbh = Bugzilla->dbh; - my $sth; - my @groupidstocheck = @groups; - my %groupidschecked = (); - $sth = $dbh->prepare("SELECT member_id FROM group_group_map - WHERE grantor_id = ? - AND grant_type = " . GROUP_MEMBERSHIP); - while (my $node = shift @groupidstocheck) { - $sth->execute($node); - my $member; - while (($member) = $sth->fetchrow_array) { - if (!$groupidschecked{$member}) { - $groupidschecked{$member} = 1; - push @groupidstocheck, $member; - push @groups, $member unless grep $_ == $member, @groups; - } - } - } - return \@groups; -} - sub match { # Generates a list of users whose login name (email address) or real name # matches a substring or wildcard. @@ -2049,14 +2026,6 @@ Returns a reference to an array of users. The array is populated with hashrefs containing the login, identity and visibility. Users that are not visible to this user will have 'visible' set to zero. -=item C<flatten_group_membership> - -Accepts a list of groups and returns a list of all the groups whose members -inherit membership in any group on the list. So, we can determine if a user -is in any of the groups input to flatten_group_membership by querying the -user_group_map for any user with DIRECT or REGEXP membership IN() the list -of groups returned. - =item C<direct_group_membership> Returns a reference to an array of group objects. Groups the user belong to diff --git a/editgroups.cgi b/editgroups.cgi index 7dd8a7b63..475b805cc 100755 --- a/editgroups.cgi +++ b/editgroups.cgi @@ -262,7 +262,7 @@ if ($action eq 'del') { } # Group inheritance no longer appears in user_group_map. - my $grouplist = join(',', @{Bugzilla::User->flatten_group_membership($gid)}); + my $grouplist = join(',', @{Bugzilla::Group->flatten_group_membership($gid)}); my $hasusers = $dbh->selectrow_array("SELECT 1 FROM user_group_map WHERE group_id IN ($grouplist) AND isbless = 0 " . @@ -337,7 +337,7 @@ if ($action eq 'delete') { my $cantdelete = 0; # Group inheritance no longer appears in user_group_map. - my $grouplist = join(',', @{Bugzilla::User->flatten_group_membership($gid)}); + my $grouplist = join(',', @{Bugzilla::Group->flatten_group_membership($gid)}); my $hasusers = $dbh->selectrow_array("SELECT 1 FROM user_group_map WHERE group_id IN ($grouplist) AND isbless = 0 " . diff --git a/editusers.cgi b/editusers.cgi index 6dac96788..3d8b66184 100755 --- a/editusers.cgi +++ b/editusers.cgi @@ -164,7 +164,7 @@ if ($action eq 'search') { # Handle selection by group. if ($grouprestrict eq '1') { my $grouplist = join(',', - @{Bugzilla::User->flatten_group_membership($group->id)}); + @{Bugzilla::Group->flatten_group_membership($group->id)}); $query .= " $nextCondition ugm.group_id IN($grouplist) "; } $query .= ' ORDER BY profiles.login_name'; @@ -34,6 +34,7 @@ use Bugzilla::Search; use Bugzilla::User; use Bugzilla::Mailer; use Bugzilla::Util; +use Bugzilla::Group; # create some handles that we'll need my $template = Bugzilla->template; @@ -250,7 +251,7 @@ sub get_next_event { $groupname, $owner); if ($group_id) { my $glist = join(',', - @{Bugzilla::User->flatten_group_membership( + @{Bugzilla::Group->flatten_group_membership( $group_id)}); $sth = $dbh->prepare("SELECT user_id FROM " . "user_group_map " . |