Commit ca06c579 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 405355: Move flatten_group_membership() from User.pm to Group.pm - Patch by…

Bug 405355: Move flatten_group_membership() from User.pm to Group.pm - Patch by arbingersys <arbingersys@gmail.com> r/a=LpSolit
parent d3f1b1a3
...@@ -238,6 +238,33 @@ sub members_non_inherited { ...@@ -238,6 +238,33 @@ sub members_non_inherited {
return $self->{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 ### ##### Module Subroutines ###
################################ ################################
...@@ -394,4 +421,12 @@ Returns an arrayref of L<Bugzilla::User> objects representing people who are ...@@ -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 the group regular expression, or they have been actually added to the
group manually. 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 =back
...@@ -274,7 +274,7 @@ sub create_admin { ...@@ -274,7 +274,7 @@ sub create_admin {
my $admin_group = new Bugzilla::Group({ name => 'admin' }); my $admin_group = new Bugzilla::Group({ name => 'admin' });
my $admin_inheritors = 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_group_ids = join(',', @$admin_inheritors);
my ($admin_count) = $dbh->selectrow_array( my ($admin_count) = $dbh->selectrow_array(
......
...@@ -1067,7 +1067,7 @@ sub _contact_exact_group { ...@@ -1067,7 +1067,7 @@ sub _contact_exact_group {
my $group = $1; my $group = $1;
my $groupid = Bugzilla::Group::ValidateGroupName( $group, ($user)); my $groupid = Bugzilla::Group::ValidateGroupName( $group, ($user));
$groupid || ThrowUserError('invalid_group_name',{name => $group}); $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"; my $table = "user_group_map_$$chartid";
push (@$supptables, "LEFT JOIN user_group_map AS $table " . push (@$supptables, "LEFT JOIN user_group_map AS $table " .
"ON $table.user_id = bugs.$$f " . "ON $table.user_id = bugs.$$f " .
...@@ -1139,7 +1139,7 @@ sub _cc_exact_group { ...@@ -1139,7 +1139,7 @@ sub _cc_exact_group {
my $group = $1; my $group = $1;
my $groupid = Bugzilla::Group::ValidateGroupName( $group, ($user)); my $groupid = Bugzilla::Group::ValidateGroupName( $group, ($user));
$groupid || ThrowUserError('invalid_group_name',{name => $group}); $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; my $chartseq = $$chartid;
if ($$chartid eq "") { if ($$chartid eq "") {
$chartseq = "CC$$sequence"; $chartseq = "CC$$sequence";
......
...@@ -48,6 +48,7 @@ use Bugzilla::User::Setting; ...@@ -48,6 +48,7 @@ use Bugzilla::User::Setting;
use Bugzilla::Product; use Bugzilla::Product;
use Bugzilla::Classification; use Bugzilla::Classification;
use Bugzilla::Field; use Bugzilla::Field;
use Bugzilla::Group;
use Scalar::Util qw(blessed); use Scalar::Util qw(blessed);
use DateTime::TimeZone; use DateTime::TimeZone;
...@@ -830,7 +831,7 @@ sub visible_groups_inherited { ...@@ -830,7 +831,7 @@ sub visible_groups_inherited {
return $self->{visible_groups_inherited} if defined $self->{visible_groups_inherited}; return $self->{visible_groups_inherited} if defined $self->{visible_groups_inherited};
return [] unless $self->id; return [] unless $self->id;
my @visgroups = @{$self->visible_groups_direct}; my @visgroups = @{$self->visible_groups_direct};
@visgroups = @{$self->flatten_group_membership(@visgroups)}; @visgroups = @{Bugzilla::Group->flatten_group_membership(@visgroups)};
$self->{visible_groups_inherited} = \@visgroups; $self->{visible_groups_inherited} = \@visgroups;
return $self->{visible_groups_inherited}; return $self->{visible_groups_inherited};
} }
...@@ -992,30 +993,6 @@ sub can_bless { ...@@ -992,30 +993,6 @@ sub can_bless {
return grep($_->id == $group_id, @{ $self->bless_groups }) ? 1 : 0; 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 { sub match {
# Generates a list of users whose login name (email address) or real name # Generates a list of users whose login name (email address) or real name
# matches a substring or wildcard. # matches a substring or wildcard.
...@@ -2049,14 +2026,6 @@ Returns a reference to an array of users. The array is populated with hashrefs ...@@ -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 containing the login, identity and visibility. Users that are not visible to this
user will have 'visible' set to zero. 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> =item C<direct_group_membership>
Returns a reference to an array of group objects. Groups the user belong to Returns a reference to an array of group objects. Groups the user belong to
......
...@@ -262,7 +262,7 @@ if ($action eq 'del') { ...@@ -262,7 +262,7 @@ if ($action eq 'del') {
} }
# Group inheritance no longer appears in user_group_map. # 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 = my $hasusers =
$dbh->selectrow_array("SELECT 1 FROM user_group_map $dbh->selectrow_array("SELECT 1 FROM user_group_map
WHERE group_id IN ($grouplist) AND isbless = 0 " . WHERE group_id IN ($grouplist) AND isbless = 0 " .
...@@ -337,7 +337,7 @@ if ($action eq 'delete') { ...@@ -337,7 +337,7 @@ if ($action eq 'delete') {
my $cantdelete = 0; my $cantdelete = 0;
# Group inheritance no longer appears in user_group_map. # 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 = my $hasusers =
$dbh->selectrow_array("SELECT 1 FROM user_group_map $dbh->selectrow_array("SELECT 1 FROM user_group_map
WHERE group_id IN ($grouplist) AND isbless = 0 " . WHERE group_id IN ($grouplist) AND isbless = 0 " .
......
...@@ -164,7 +164,7 @@ if ($action eq 'search') { ...@@ -164,7 +164,7 @@ if ($action eq 'search') {
# Handle selection by group. # Handle selection by group.
if ($grouprestrict eq '1') { if ($grouprestrict eq '1') {
my $grouplist = join(',', 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 .= " $nextCondition ugm.group_id IN($grouplist) ";
} }
$query .= ' ORDER BY profiles.login_name'; $query .= ' ORDER BY profiles.login_name';
......
...@@ -34,6 +34,7 @@ use Bugzilla::Search; ...@@ -34,6 +34,7 @@ use Bugzilla::Search;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::Mailer; use Bugzilla::Mailer;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Group;
# create some handles that we'll need # create some handles that we'll need
my $template = Bugzilla->template; my $template = Bugzilla->template;
...@@ -250,7 +251,7 @@ sub get_next_event { ...@@ -250,7 +251,7 @@ sub get_next_event {
$groupname, $owner); $groupname, $owner);
if ($group_id) { if ($group_id) {
my $glist = join(',', my $glist = join(',',
@{Bugzilla::User->flatten_group_membership( @{Bugzilla::Group->flatten_group_membership(
$group_id)}); $group_id)});
$sth = $dbh->prepare("SELECT user_id FROM " . $sth = $dbh->prepare("SELECT user_id FROM " .
"user_group_map " . "user_group_map " .
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment