Bug 244239: Add group-based pronouns to query

r=erik,justdave
a=justdave


git-svn-id: svn://10.0.0.236/trunk@160666 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bugreport%peshkin.net
2004-08-11 14:00:34 +00:00
parent 9d0e5a4575
commit 12e5e8c5f9
5 changed files with 101 additions and 13 deletions

View File

@@ -36,6 +36,7 @@ package Bugzilla::Search;
use Bugzilla::Config;
use Bugzilla::Error;
use Bugzilla::Util;
use Bugzilla::Constants;
use Date::Format;
use Date::Parse;
@@ -330,6 +331,26 @@ sub init {
my %funcsbykey;
my @funcdefs =
(
"^(?:assigned_to|reporter|qa_contact),(?:notequals|equals|anyexact),%group\\.(\\w+)%" => sub {
my $group = $1;
my $groupid = ValidateGroupName( $group, ($user));
$groupid || ThrowUserError('invalid_group_name',{name => $group});
my @childgroups = @{$user->flatten_group_membership($groupid)};
my $table = "user_group_map_$chartid";
push (@supptables, "LEFT JOIN user_group_map $table " .
"ON $table.user_id = bugs.$f " .
"AND $table.group_id IN(" .
join(',', @childgroups) . ") " .
"AND $table.isbless = 0 " .
"AND $table.grant_type IN(" .
GRANT_DIRECT . "," . GRANT_REGEXP . ")"
);
if ($t =~ /^not/) {
$term = "$table.group_id IS NULL";
} else {
$term = "$table.group_id IS NOT NULL";
}
},
"^(?:assigned_to|reporter|qa_contact),(?:equals|anyexact),(%\\w+%)" => sub {
$term = "bugs.$f = " . pronoun($1, $user);
},
@@ -347,6 +368,34 @@ sub init {
$f = "COALESCE(map_$f.login_name,'')";
},
"^(?:cc),(?:notequals|equals|anyexact),%group\\.(\\w+)%" => sub {
my $group = $1;
my $groupid = ValidateGroupName( $group, ($user));
$groupid || ThrowUserError('invalid_group_name',{name => $group});
my @childgroups = @{$user->flatten_group_membership($groupid)};
my $chartseq = $chartid;
if ($chartid eq "") {
$chartseq = "CC$sequence";
$sequence++;
}
my $table = "user_group_map_$chartseq";
push(@supptables, "LEFT JOIN cc cc_$chartseq " .
"ON bugs.bug_id = cc_$chartseq.bug_id");
push(@supptables, "LEFT JOIN user_group_map $table " .
"ON $table.user_id = cc_$chartseq.who " .
"AND $table.group_id IN(" .
join(',', @childgroups) . ") " .
"AND $table.isbless = 0 " .
"AND $table.grant_type IN(" .
GRANT_DIRECT . "," . GRANT_REGEXP . ")"
);
if ($t =~ /^not/) {
$term = "$table.group_id IS NULL";
} else {
$term = "$table.group_id IS NOT NULL";
}
},
"^cc,(?:equals|anyexact),(%\\w+%)" => sub {
my $match = pronoun($1, $user);
my $chartseq = $chartid;
@@ -1355,4 +1404,23 @@ sub pronoun {
}
return 0;
}
# ValidateGroupName checks to see if ANY of the users in the provided list
# of user objects can see the named group. It returns the group id if
# successful and undef otherwise.
sub ValidateGroupName {
my ($name, @users) = (@_);
my @visible = (-1);
foreach my $user (@users) {
$user && push @visible, @{$user->visible_groups_direct};
}
my $visible = join(', ', @visible);
my $dbh = Bugzilla->dbh;
my $sth = $dbh->prepare("SELECT id FROM groups " .
"WHERE name = ? AND id IN($visible)");
$sth->execute($name);
my ($ret) = $sth->fetchrow_array();
return $ret;
}
1;