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 /Bugzilla/Group.pm | |
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
Diffstat (limited to 'Bugzilla/Group.pm')
-rw-r--r-- | Bugzilla/Group.pm | 35 |
1 files changed, 35 insertions, 0 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 |