summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGervase Markham <gerv@gerv.net>2014-02-17 17:54:49 +0100
committerGervase Markham <gerv@mozilla.org>2014-02-17 17:54:49 +0100
commita62b8171da025e6fa5a8a5dd8a9c872f9f82d84a (patch)
tree34779933ac1cbcf706b84fb4302ae58c4b0bd82b
parent09317bf98d6100f3242150c6bd683c58d5e9793e (diff)
downloadbugzilla-a62b8171da025e6fa5a8a5dd8a9c872f9f82d84a.tar.gz
bugzilla-a62b8171da025e6fa5a8a5dd8a9c872f9f82d84a.tar.xz
Fix bad or_groups SQL for determining if a user can see a product. r=LpSolit, a=justdave.
https://bugzilla.mozilla.org/show_bug.cgi?id=970228
-rw-r--r--Bugzilla/User.pm38
1 files changed, 18 insertions, 20 deletions
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index 872c742db..e93d27ce8 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -1057,26 +1057,24 @@ sub get_selectable_products {
my $class_restricted = Bugzilla->params->{'useclassification'} && $class_id;
if (!defined $self->{selectable_products}) {
- my $query =
- Bugzilla->params->{'or_groups'}
- ? "SELECT id
- FROM products
- WHERE id NOT IN (
- SELECT product_id
- FROM group_control_map
- WHERE group_control_map.membercontrol = " . CONTROLMAPMANDATORY . "
- AND group_id NOT IN (" . $self->groups_as_string . ")
- )
- ORDER BY name"
- : "SELECT id
- FROM products
- LEFT JOIN group_control_map
- ON group_control_map.product_id = products.id
- AND group_control_map.membercontrol = " . CONTROLMAPMANDATORY . "
- AND group_id NOT IN(" . $self->groups_as_string . ")
- WHERE group_id IS NULL
- ORDER BY name";
-
+ my $query = "SELECT id
+ FROM products
+ LEFT JOIN group_control_map
+ ON group_control_map.product_id = products.id
+ AND group_control_map.membercontrol = " . CONTROLMAPMANDATORY;
+
+ if (Bugzilla->params->{'or_groups'}) {
+ # Either the user is in at least one of the MANDATORY groups, or
+ # there are no such groups for the product.
+ $query .= " WHERE group_id IN (" . $self->groups_as_string . ")
+ OR group_id IS NULL";
+ }
+ else {
+ # There must be no MANDATORY groups that the user is not in.
+ $query .= " AND group_id NOT IN (" . $self->groups_as_string . ")
+ WHERE group_id IS NULL";
+ }
+
my $prod_ids = Bugzilla->dbh->selectcol_arrayref($query);
$self->{selectable_products} = Bugzilla::Product->new_from_list($prod_ids);
}