From ca06c57995ed327879e4c23b58e1330d4bd27d18 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Sun, 25 Jan 2009 18:49:30 +0000 Subject: Bug 405355: Move flatten_group_membership() from User.pm to Group.pm - Patch by arbingersys r/a=LpSolit --- Bugzilla/Group.pm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'Bugzilla/Group.pm') 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 objects representing people who are the group regular expression, or they have been actually added to the group manually. +=item C + +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 -- cgit v1.2.3-24-g4f1b