Commit 44e26f06 authored by Dave Lawrence's avatar Dave Lawrence

Bug 756048 - Add and update bug and attachment flags using the WebService API

r=sgreen,a=justdave
parent 4fa178ae
......@@ -126,6 +126,13 @@ use constant WS_ERROR_CODE => {
missing_resolution => 121,
resolution_not_allowed => 122,
illegal_bug_status_transition => 123,
# Flag errors
flag_status_invalid => 129,
flag_update_denied => 130,
flag_type_requestee_disabled => 131,
flag_not_unique => 132,
flag_type_not_unique => 133,
flag_type_inactive => 134,
# Authentication errors are usually 300-400.
invalid_login_or_password => 300,
......
......@@ -151,7 +151,23 @@ sub _rest_resources {
}
}
},
qr{^/flag_types/([^/]+)/([^/]+)$}, {
GET => {
method => 'flag_types',
params => sub {
return { product => $_[0],
component => $_[1] };
}
}
},
qr{^/flag_types/([^/]+)$}, {
GET => {
method => 'flag_types',
params => sub {
return { product => $_[0] };
}
}
}
];
return $rest_resources;
}
......
......@@ -10,6 +10,12 @@ package Bugzilla::WebService::Util;
use 5.10.1;
use strict;
use Bugzilla::Flag;
use Bugzilla::FlagType;
use Bugzilla::Error;
use Storable qw(dclone);
use parent qw(Exporter);
# We have to "require", not "use" this, because otherwise it tries to
......@@ -17,6 +23,7 @@ use parent qw(Exporter);
require Test::Taint;
our @EXPORT_OK = qw(
extract_flags
filter
filter_wants
taint_data
......@@ -26,6 +33,80 @@ our @EXPORT_OK = qw(
fix_credentials
);
sub extract_flags {
my ($flags, $bug, $attachment) = @_;
my (@new_flags, @old_flags);
my $flag_types = $attachment ? $attachment->flag_types : $bug->flag_types;
my $current_flags = $attachment ? $attachment->flags : $bug->flags;
# Copy the user provided $flags as we may call extract_flags more than
# once when editing multiple bugs or attachments.
my $flags_copy = dclone($flags);
foreach my $flag (@$flags_copy) {
my $id = $flag->{id};
my $type_id = $flag->{type_id};
my $new = delete $flag->{new};
my $name = delete $flag->{name};
if ($id) {
my $flag_obj = grep($id == $_->id, @$current_flags);
$flag_obj || ThrowUserError('object_does_not_exist',
{ class => 'Bugzilla::Flag', id => $id });
}
elsif ($type_id) {
my $type_obj = grep($type_id == $_->id, @$flag_types);
$type_obj || ThrowUserError('object_does_not_exist',
{ class => 'Bugzilla::FlagType', id => $type_id });
if (!$new) {
my @flag_matches = grep($type_id == $_->type->id, @$current_flags);
@flag_matches > 1 && ThrowUserError('flag_not_unique',
{ value => $type_id });
if (!@flag_matches) {
delete $flag->{id};
}
else {
delete $flag->{type_id};
$flag->{id} = $flag_matches[0]->id;
}
}
}
elsif ($name) {
my @type_matches = grep($name eq $_->name, @$flag_types);
@type_matches > 1 && ThrowUserError('flag_type_not_unique',
{ value => $name });
@type_matches || ThrowUserError('object_does_not_exist',
{ class => 'Bugzilla::FlagType', name => $name });
if ($new) {
delete $flag->{id};
$flag->{type_id} = $type_matches[0]->id;
}
else {
my @flag_matches = grep($name eq $_->type->name, @$current_flags);
@flag_matches > 1 && ThrowUserError('flag_not_unique', { value => $name });
if (@flag_matches) {
$flag->{id} = $flag_matches[0]->id;
}
else {
delete $flag->{id};
$flag->{type_id} = $type_matches[0]->id;
}
}
}
if ($flag->{id}) {
push(@old_flags, $flag);
}
else {
push(@new_flags, $flag);
}
}
return (\@old_flags, \@new_flags);
}
sub filter ($$;$) {
my ($params, $hash, $prefix) = @_;
my %newhash = %$hash;
......@@ -232,6 +313,12 @@ Allows for certain parameters related to authentication such as Bugzilla_login,
Bugzilla_password, and Bugzilla_token to have shorter named equivalents passed in.
This function converts the shorter versions to their respective internal names.
=head2 extract_flags
Subroutine that takes a list of hashes that are potential flag changes for
both bugs and attachments. Then breaks the list down into two separate lists
based on if the change is to add a new flag or to update an existing flag.
=head1 B<Methods in need of POD>
=over
......
......@@ -745,6 +745,16 @@
You are not allowed to edit properties of the '[% flagtype.name FILTER html %]'
flag type, because this flag type is not available for the products you can administer.
[% ELSIF error == "flag_not_unique" %]
[% title = "Flag not Unique" %]
The flag '[% value FILTER html %]' has been set multiple times.
You must specify the id value to update the flag.
[% ELSIF error == "flag_type_not_unique" %]
[% title = "Flag Type not Unique" %]
The flag type '[% value FILTER html %]' matches several flag types.
You must specify the type id value to update or add a flag.
[% ELSIF error == "flag_type_not_multiplicable" %]
[% docslinks = {'flags-overview.html' => 'An overview on Flags',
'flags.html' => 'Using Flags'} %]
......
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