diff options
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/BMO/lib/WebService.pm | 81 | ||||
-rw-r--r-- | extensions/MyDashboard/lib/WebService.pm | 73 | ||||
-rw-r--r-- | extensions/ProdCompSearch/Extension.pm | 7 | ||||
-rw-r--r-- | extensions/ProdCompSearch/lib/WebService.pm | 2 | ||||
-rw-r--r-- | extensions/ProdCompSearch/web/js/prod_comp_search.js | 6 |
5 files changed, 14 insertions, 155 deletions
diff --git a/extensions/BMO/lib/WebService.pm b/extensions/BMO/lib/WebService.pm index a9387b330..cefcde2f6 100644 --- a/extensions/BMO/lib/WebService.pm +++ b/extensions/BMO/lib/WebService.pm @@ -100,87 +100,6 @@ sub getBugsVerifier { return \%users; } -sub prod_comp_search { - my ($self, $params) = @_; - my $user = Bugzilla->user; - my $dbh = Bugzilla->switch_to_shadow_db(); - - my $search = $params->{'search'}; - $search || ThrowCodeError('param_required', - { function => 'Bug.prod_comp_search', param => 'search' }); - - my $limit = detaint_natural($params->{'limit'}) - ? $dbh->sql_limit($params->{'limit'}) - : ''; - - # We do this in the DB directly as we want it to be fast and - # not have the overhead of loading full product objects - - # All products which the user has "Entry" access to. - my $enterable_ids = $dbh->selectcol_arrayref( - 'SELECT products.id FROM products - LEFT JOIN group_control_map - ON group_control_map.product_id = products.id - AND group_control_map.entry != 0 - AND group_id NOT IN (' . $user->groups_as_string . ') - WHERE group_id IS NULL - AND products.isactive = 1'); - - if (scalar @$enterable_ids) { - # And all of these products must have at least one component - # and one version. - $enterable_ids = $dbh->selectcol_arrayref( - 'SELECT DISTINCT products.id FROM products - WHERE ' . $dbh->sql_in('products.id', $enterable_ids) . - ' AND products.id IN (SELECT DISTINCT components.product_id - FROM components - WHERE components.isactive = 1) - AND products.id IN (SELECT DISTINCT versions.product_id - FROM versions - WHERE versions.isactive = 1)'); - } - - return { products => [] } if !scalar @$enterable_ids; - - my @list; - foreach my $word (split(/[\s,]+/, $search)) { - if ($word ne "") { - my $sql_word = $dbh->quote($word); - trick_taint($sql_word); - # XXX CONCAT_WS is MySQL specific - my $field = "CONCAT_WS(' ', products.name, components.name, components.description)"; - push(@list, $dbh->sql_iposition($sql_word, $field) . " > 0"); - } - } - - my $products = $dbh->selectall_arrayref(" - SELECT products.name AS product, - components.name AS component - FROM products - INNER JOIN components ON products.id = components.product_id - WHERE (" . join(" AND ", @list) . ") - AND products.id IN (" . join(",", @$enterable_ids) . ") - ORDER BY products.name $limit", - { Slice => {} }); - - # To help mozilla staff file bmo administration bugs into the right - # component, sort bmo in front of bugzilla. - if ($user->in_group('mozilla-corporation') || $user->in_group('mozilla-foundation')) { - $products = [ - sort { - return 1 if $a->{product} eq 'Bugzilla' - && $b->{product} eq 'bugzilla.mozilla.org'; - return -1 if $b->{product} eq 'Bugzilla' - && $a->{product} eq 'bugzilla.mozilla.org'; - return lc($a->{product}) cmp lc($b->{product}) - || lc($a->{component}) cmp lc($b->{component}); - } @$products - ]; - } - - return { products => $products }; -} - 1; __END__ diff --git a/extensions/MyDashboard/lib/WebService.pm b/extensions/MyDashboard/lib/WebService.pm index e9ea2315f..1f3b7ce06 100644 --- a/extensions/MyDashboard/lib/WebService.pm +++ b/extensions/MyDashboard/lib/WebService.pm @@ -19,77 +19,10 @@ use Bugzilla::WebService::Util qw(validate); use Bugzilla::Extension::MyDashboard::Queries qw(QUERY_DEFS query_bugs query_flags); use constant READ_ONLY => qw( - prod_comp_search run_bug_query run_flag_query ); -sub prod_comp_search { - my ($self, $params) = @_; - my $user = Bugzilla->user; - my $dbh = Bugzilla->switch_to_shadow_db(); - - my $search = $params->{'search'}; - $search || ThrowCodeError('param_required', - { function => 'Bug.prod_comp_search', param => 'search' }); - - my $limit = detaint_natural($params->{'limit'}) - ? $dbh->sql_limit($params->{'limit'}) - : ''; - - # We do this in the DB directly as we want it to be fast and - # not have the overhead of loading full product objects - - # All products which the user has "Entry" access to. - my $enterable_ids = $dbh->selectcol_arrayref( - 'SELECT products.id FROM products - LEFT JOIN group_control_map - ON group_control_map.product_id = products.id - AND group_control_map.entry != 0 - AND group_id NOT IN (' . $user->groups_as_string . ') - WHERE group_id IS NULL - AND products.isactive = 1'); - - if (scalar @$enterable_ids) { - # And all of these products must have at least one component - # and one version. - $enterable_ids = $dbh->selectcol_arrayref( - 'SELECT DISTINCT products.id FROM products - WHERE ' . $dbh->sql_in('products.id', $enterable_ids) . - ' AND products.id IN (SELECT DISTINCT components.product_id - FROM components - WHERE components.isactive = 1) - AND products.id IN (SELECT DISTINCT versions.product_id - FROM versions - WHERE versions.isactive = 1)'); - } - - return { products => [] } if !scalar @$enterable_ids; - - my @list; - foreach my $word (split(/[\s,]+/, $search)) { - if ($word ne "") { - my $sql_word = $dbh->quote($word); - trick_taint($sql_word); - # XXX CONCAT_WS is MySQL specific - my $field = "CONCAT_WS(' ', products.name, components.name, components.description)"; - push(@list, $dbh->sql_iposition($sql_word, $field) . " > 0"); - } - } - - my $products = $dbh->selectall_arrayref(" - SELECT products.name AS product, - components.name AS component - FROM products - INNER JOIN components ON products.id = components.product_id - WHERE (" . join(" AND ", @list) . ") - AND products.id IN (" . join(",", @$enterable_ids) . ") - ORDER BY products.name $limit", - { Slice => {} }); - - return { products => $products }; -} - sub run_bug_query { my($self, $params) = @_; my $dbh = Bugzilla->dbh; @@ -104,7 +37,7 @@ sub run_bug_query { foreach my $qdef (QUERY_DEFS) { next if $qdef->{name} ne $params->{query}; my ($bugs, $query_string) = query_bugs($qdef); - + # Add last changes to each bug foreach my $b (@$bugs) { my $last_changes = {}; @@ -115,7 +48,7 @@ sub run_bug_query { $last_changes->{activity} = $change_set->{changes}; foreach my $change (@{ $last_changes->{activity} }) { $change->{field_desc} - = template_var('field_descs')->{$change->{field_name}} || $change->{field_name}; + = template_var('field_descs')->{$change->{field_name}} || $change->{field_name}; } $last_changes->{email} = $change_set->{who}; $last_changes->{when} = $self->datetime_format_inbound($change_set->{when}); @@ -134,7 +67,7 @@ sub run_bug_query { } $b->{last_changes} = $last_changes; } - + $query_string =~ s/^POSTDATA=&//; $qdef->{bugs} = $bugs; $qdef->{buffer} = $query_string; diff --git a/extensions/ProdCompSearch/Extension.pm b/extensions/ProdCompSearch/Extension.pm index 4a4fae355..a5955fd8b 100644 --- a/extensions/ProdCompSearch/Extension.pm +++ b/extensions/ProdCompSearch/Extension.pm @@ -11,4 +11,11 @@ use base qw(Bugzilla::Extension); our $VERSION = '1'; +sub webservice { + my ($self, $args) = @_; + my $dispatch = $args->{dispatch}; + $dispatch->{PCS} = "Bugzilla::Extension::ProdCompSearch::WebService"; +} + + __PACKAGE__->NAME; diff --git a/extensions/ProdCompSearch/lib/WebService.pm b/extensions/ProdCompSearch/lib/WebService.pm index bbc355e00..dea2e5e51 100644 --- a/extensions/ProdCompSearch/lib/WebService.pm +++ b/extensions/ProdCompSearch/lib/WebService.pm @@ -22,7 +22,7 @@ sub prod_comp_search { my $search = $params->{'search'}; $search || ThrowCodeError('param_required', - { function => 'Bug.prod_comp_search', param => 'search' }); + { function => 'PCS.prod_comp_search', param => 'search' }); my $limit = detaint_natural($params->{'limit'}) ? $dbh->sql_limit($params->{'limit'}) diff --git a/extensions/ProdCompSearch/web/js/prod_comp_search.js b/extensions/ProdCompSearch/web/js/prod_comp_search.js index 1aa65d5e6..f58a8d330 100644 --- a/extensions/ProdCompSearch/web/js/prod_comp_search.js +++ b/extensions/ProdCompSearch/web/js/prod_comp_search.js @@ -24,7 +24,7 @@ YUI({ autoComplete = null; var resultListFormat = function(query, results) { - return Y.Array.map(results, function (result) { + return Y.Array.map(results, function(result) { var data = result.raw; result.text = data.product + ' :: ' + data.component; return Y.Escape.html(result.text); @@ -35,7 +35,7 @@ YUI({ counter = counter + 1; var json_object = { version: "1.1", - method : "MyDashboard.prod_comp_search", + method : "PCS.prod_comp_search", id : counter, params : { search: query } }; @@ -99,7 +99,7 @@ YUI({ } window.location.href = url; } - }, + } }); input.on('focus', function (e) { |