diff options
Diffstat (limited to 'Bugzilla')
-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 |
4 files changed, 40 insertions, 36 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 |