Commit 9bd3f08d authored by Simon Green's avatar Simon Green

Bug 1008764: Add a web service to create and update Flag types

r=glob, a=justdave
parent abf6ec5c
......@@ -644,9 +644,19 @@ sub sqlify_criteria {
my @criteria = ("1=1");
if ($criteria->{name}) {
my $name = $dbh->quote($criteria->{name});
trick_taint($name); # Detaint data as we have quoted it.
push(@criteria, "flagtypes.name = $name");
if (ref($criteria->{name}) eq 'ARRAY') {
my @names = map { $dbh->quote($_) } @{$criteria->{name}};
# Detaint data as we have quoted it.
foreach my $name (@names) {
trick_taint($name);
}
push @criteria, $dbh->sql_in('flagtypes.name', \@names);
}
else {
my $name = $dbh->quote($criteria->{name});
trick_taint($name); # Detaint data as we have quoted it.
push(@criteria, "flagtypes.name = $name");
}
}
if ($criteria->{target_type}) {
# The target type is stored in the database as a one-character string
......
......@@ -365,6 +365,8 @@ objects.
=item L<Bugzilla::WebService::Classification>
=item L<Bugzilla::WebService::FlagType>
=item L<Bugzilla::WebService::Group>
=item L<Bugzilla::WebService::Product>
......
......@@ -81,8 +81,9 @@ use constant WS_ERROR_CODE => {
illegal_field => 104,
freetext_too_long => 104,
# Component errors
require_component => 105,
component_name_too_long => 105,
require_component => 105,
component_name_too_long => 105,
product_unknown_component => 105,
# Invalid Product
no_products => 106,
entry_access_denied => 106,
......@@ -191,6 +192,13 @@ use constant WS_ERROR_CODE => {
# Search errors are 1000-1100
buglist_parameters_required => 1000,
# Flag type errors are 1100-1200
flag_type_name_invalid => 1101,
flag_type_description_invalid => 1102,
flag_type_cc_list_invalid => 1103,
flag_type_sortkey_invalid => 1104,
flag_type_not_editable => 1105,
# Errors thrown by the WebService itself. The ones that are negative
# conform to http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlrpc_invalid_value => -32600,
......@@ -269,6 +277,7 @@ sub WS_DISPATCH {
'Bugzilla' => 'Bugzilla::WebService::Bugzilla',
'Bug' => 'Bugzilla::WebService::Bug',
'Classification' => 'Bugzilla::WebService::Classification',
'FlagType' => 'Bugzilla::WebService::FlagType',
'Group' => 'Bugzilla::WebService::Group',
'Product' => 'Bugzilla::WebService::Product',
'User' => 'Bugzilla::WebService::User',
......
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
package Bugzilla::WebService::Server::REST::Resources::FlagType;
use 5.10.1;
use strict;
use Bugzilla::WebService::Constants;
use Bugzilla::WebService::FlagType;
use Bugzilla::Error;
BEGIN {
*Bugzilla::WebService::FlagType::rest_resources = \&_rest_resources;
};
sub _rest_resources {
my $rest_resources = [
qr{^/flagtype$}, {
POST => {
method => 'create',
success_code => STATUS_CREATED
}
},
qr{^/flagtype/([^/]+)$}, {
PUT => {
method => 'update',
params => sub {
my $param = $_[0] =~ /^\d+$/ ? 'ids' : 'names';
return { $param => [ $_[0] ] };
}
}
},
];
return $rest_resources;
}
1;
__END__
=head1 NAME
Bugzilla::Webservice::Server::REST::Resources::FlagType - The Flag Type REST API
=head1 DESCRIPTION
This part of the Bugzilla REST API allows you to create and update Flag types.
See L<Bugzilla::WebService::FlagType> for more details on how to use this
part of the REST API.
......@@ -259,7 +259,7 @@ sub GetGroups {
my %legal_groups;
foreach my $product_name (@$product_names) {
my $product = new Bugzilla::Product({name => $product_name});
my $product = Bugzilla::Product->new({name => $product_name, cache => 1});
foreach my $gid (keys %{$product->group_controls}) {
# The user can only edit groups they belong to.
......@@ -874,7 +874,7 @@ $vars->{'time_info'} = $time_info;
if (!$user->in_group('editbugs')) {
foreach my $product (keys %$bugproducts) {
my $prod = new Bugzilla::Product({name => $product});
my $prod = Bugzilla::Product->new({name => $product, cache => 1});
if (!$user->in_group('editbugs', $prod->id)) {
$vars->{'caneditbugs'} = 0;
last;
......@@ -905,12 +905,12 @@ $vars->{'currenttime'} = localtime(time());
my @products = keys %$bugproducts;
my $one_product;
if (scalar(@products) == 1) {
$one_product = new Bugzilla::Product({ name => $products[0] });
$one_product = Bugzilla::Product->new({ name => $products[0], cache => 1 });
}
# This is used in the "Zarroo Boogs" case.
elsif (my @product_input = $cgi->param('product')) {
if (scalar(@product_input) == 1 and $product_input[0] ne '') {
$one_product = new Bugzilla::Product({ name => $cgi->param('product') });
$one_product = Bugzilla::Product->new({ name => $cgi->param('product'), cache => 1 });
}
}
# We only want the template to use it if the user can actually
......@@ -993,10 +993,47 @@ if ($dotweak && scalar @bugs) {
$vars->{'versions'} = [map($_->name, grep($_->is_active, @{ $one_product->versions }))];
$vars->{'components'} = [map($_->name, grep($_->is_active, @{ $one_product->components }))];
if (Bugzilla->params->{'usetargetmilestone'}) {
$vars->{'targetmilestones'} = [map($_->name, grep($_->is_active,
$vars->{'milestones'} = [map($_->name, grep($_->is_active,
@{ $one_product->milestones }))];
}
}
else {
# We will only show the values at are active in all products.
my %values = ();
my @fields = ('components', 'versions');
if (Bugzilla->params->{'usetargetmilestone'}) {
push @fields, 'milestones';
}
# Go through each product and count the number of times each field
# is used
foreach my $product_name (@products) {
my $product = Bugzilla::Product->new({name => $product_name, cache => 1});
foreach my $field (@fields) {
my $list = $product->$field;
foreach my $item (@$list) {
++$values{$field}{$item->name} if $item->is_active;
}
}
}
# Now we get the list of each field and see which values have
# $product_count (i.e. appears in every product)
my $product_count = scalar(@products);
foreach my $field (@fields) {
my @values = grep { $values{$field}{$_} == $product_count } keys %{$values{$field}};
if (scalar @values) {
@{$vars->{$field}} = $field eq 'version'
? sort { vers_cmp(lc($a), lc($b)) } @values
: sort { lc($a) cmp lc($b) } @values
}
# Do we need to show a warning about limited visiblity?
if (@values != scalar keys %{$values{$field}}) {
$vars->{excluded_values} = 1;
}
}
}
}
# If we're editing a stored query, use the existing query name as default for
......
......@@ -44,6 +44,11 @@
</ol>
</div>
[% IF excluded_values %]
<p class="extra_info">Only values that are available for all products of the above
[%+ terms.bugs %] are shown.</p>
[% END %]
<table id="form">
<tr>
......@@ -124,7 +129,7 @@
<th><label for="target_milestone">Target Milestone:</label></th>
<td>
[% PROCESS selectmenu menuname = "target_milestone"
menuitems = targetmilestones %]
menuitems = milestones %]
</td>
[% END %]
</tr>
......
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