Bug.pm 123 KB
Newer Older
1 2 3
# 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/.
4
#
5 6
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
7 8 9

package Bugzilla::WebService::Bug;

10
use 5.10.1;
11
use strict;
12
use warnings;
13

14
use parent qw(Bugzilla::WebService);
15

16
use Bugzilla::Comment;
17
use Bugzilla::Comment::TagWeights;
18 19 20
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Field;
21
use Bugzilla::WebService::Constants;
22
use Bugzilla::WebService::Util qw(extract_flags filter filter_wants validate translate);
23
use Bugzilla::Bug;
24
use Bugzilla::BugMail;
25
use Bugzilla::Util qw(trick_taint trim diff_arrays detaint_natural);
26 27 28
use Bugzilla::Version;
use Bugzilla::Milestone;
use Bugzilla::Status;
29
use Bugzilla::Token qw(issue_hash_token);
30
use Bugzilla::Search;
31 32
use Bugzilla::Product;
use Bugzilla::FlagType;
33
use Bugzilla::Search::Quicksearch;
34 35 36

use List::Util qw(max);
use List::MoreUtils qw(uniq);
37
use Storable qw(dclone);
38 39 40 41 42

#############
# Constants #
#############

43 44
use constant PRODUCT_SPECIFIC_FIELDS => qw(version target_milestone component);

45 46
use constant DATE_FIELDS => {
    comments => ['new_since'],
47
    history  => ['new_since'],
48 49 50
    search   => ['last_change_time', 'creation_time'],
};

51 52 53 54
use constant BASE64_FIELDS => {
    add_attachment => ['data'],
};

55 56 57 58 59 60 61 62 63 64
use constant READ_ONLY => qw(
    attachments
    comments
    fields
    get
    history
    legal_values
    search
);

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
use constant PUBLIC_METHODS => qw(
    add_attachment
    add_comment
    attachments
    comments
    create
    fields
    get
    history
    legal_values
    possible_duplicates
    render_comment
    search
    search_comment_tags
    update
    update_attachment
    update_comment_tags
    update_see_also
    update_tags
);

86 87 88 89 90 91 92 93 94 95 96 97 98 99
use constant ATTACHMENT_MAPPED_SETTERS => {
    file_name => 'filename',
    summary   => 'description',
};

use constant ATTACHMENT_MAPPED_RETURNS => {
    description => 'summary',
    ispatch     => 'is_patch',
    isprivate   => 'is_private',
    isobsolete  => 'is_obsolete',
    filename    => 'file_name',
    mimetype    => 'content_type',
};

100 101 102
###########
# Methods #
###########
103

104 105 106
sub fields {
    my ($self, $params) = validate(@_, 'ids', 'names');

107 108
    Bugzilla->switch_to_shadow_db();

109 110 111 112 113 114 115 116 117 118 119 120 121
    my @fields;
    if (defined $params->{ids}) {
        my $ids = $params->{ids};
        foreach my $id (@$ids) {
            my $loop_field = Bugzilla::Field->check({ id => $id });
            push(@fields, $loop_field);
        }
    }

    if (defined $params->{names}) {
        my $names = $params->{names};
        foreach my $field_name (@$names) {
            my $loop_field = Bugzilla::Field->check($field_name);
122 123 124 125 126
            # Don't push in duplicate fields if we also asked for this field
            # in "ids".
            if (!grep($_->id == $loop_field->id, @fields)) {
                push(@fields, $loop_field);
            }
127 128 129
        }
    }

130
    if (!defined $params->{ids} and !defined $params->{names}) {
131
        @fields = @{ Bugzilla->fields({ obsolete => 0 }) };
132 133 134 135
    }

    my @fields_out;
    foreach my $field (@fields) {
136
        my $visibility_field = $field->visibility_field
137
                               ? $field->visibility_field->name : undef;
138
        my $vis_values = $field->visibility_values;
139 140 141
        my $value_field = $field->value_field
                          ? $field->value_field->name : undef;

142
        my (@values, $has_values);
143
        if ( ($field->is_select and $field->name ne 'product')
144 145
             or grep($_ eq $field->name, PRODUCT_SPECIFIC_FIELDS)
             or $field->name eq 'keywords')
146
        {
147
             $has_values = 1;
148
             @values = @{ $self->_legal_field_values({ field => $field }) };
149
        } 
150 151 152 153 154

        if (grep($_ eq $field->name, PRODUCT_SPECIFIC_FIELDS)) {
             $value_field = 'product';
        }

155
        my %field_data = (
156 157 158 159 160
           id                => $self->type('int', $field->id),
           type              => $self->type('int', $field->type),
           is_custom         => $self->type('boolean', $field->custom),
           name              => $self->type('string', $field->name),
           display_name      => $self->type('string', $field->description),
161
           is_mandatory      => $self->type('boolean', $field->is_mandatory),
162 163
           is_on_bug_entry   => $self->type('boolean', $field->enter_bug),
           visibility_field  => $self->type('string', $visibility_field),
164 165
           visibility_values =>
              [ map { $self->type('string', $_->name) } @$vis_values ],
166 167 168 169 170 171
        );
        if ($has_values) {
           $field_data{value_field} = $self->type('string', $value_field);
           $field_data{values}      = \@values;
        };
        push(@fields_out, filter $params, \%field_data);
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    }

    return { fields => \@fields_out };
}

sub _legal_field_values {
    my ($self, $params) = @_;
    my $field = $params->{field};
    my $field_name = $field->name;
    my $user = Bugzilla->user;

    my @result;
    if (grep($_ eq $field_name, PRODUCT_SPECIFIC_FIELDS)) {
        my @list;
        if ($field_name eq 'version') {
            @list = Bugzilla::Version->get_all;
        }
        elsif ($field_name eq 'component') {
            @list = Bugzilla::Component->get_all;
        }
        else {
            @list = Bugzilla::Milestone->get_all;
        }

        foreach my $value (@list) {
            my $sortkey = $field_name eq 'target_milestone'
                          ? $value->sortkey : 0;
            # XXX This is very slow for large numbers of values.
            my $product_name = $value->product->name;
            if ($user->can_see_product($product_name)) {
                push(@result, {
203 204 205
                    name     => $self->type('string', $value->name),
                    sort_key => $self->type('int', $sortkey),
                    sortkey  => $self->type('int', $sortkey), # deprecated
206
                    visibility_values => [$self->type('string', $product_name)],
207
                    is_active         => $self->type('boolean', $value->is_active),
208 209 210 211 212 213 214
                });
            }
        }
    }

    elsif ($field_name eq 'bug_status') {
        my @status_all = Bugzilla::Status->get_all;
215 216 217 218 219
        my $initial_status = bless({ id => 0, name => '', is_open => 1, sortkey => 0,
                                     can_change_to => Bugzilla::Status->can_change_to },
                                   'Bugzilla::Status');
        unshift(@status_all, $initial_status);

220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
        foreach my $status (@status_all) {
            my @can_change_to;
            foreach my $change_to (@{ $status->can_change_to }) {
                # There's no need to note that a status can transition
                # to itself.
                next if $change_to->id == $status->id;
                my %change_to_hash = (
                    name => $self->type('string', $change_to->name),
                    comment_required => $self->type('boolean', 
                        $change_to->comment_required_on_change_from($status)),
                );
                push(@can_change_to, \%change_to_hash);
            }

            push (@result, {
235 236 237
               name     => $self->type('string', $status->name),
               is_open  => $self->type('boolean', $status->is_open),
               sort_key => $self->type('int', $status->sortkey),
Frédéric Buclin's avatar
Frédéric Buclin committed
238
               sortkey  => $self->type('int', $status->sortkey), # deprecated
239
               can_change_to => \@can_change_to,
240
               visibility_values => [],
241 242 243 244
            });
        }
    }

245 246 247 248 249 250 251 252 253
    elsif ($field_name eq 'keywords') {
        my @legal_keywords = Bugzilla::Keyword->get_all;
        foreach my $value (@legal_keywords) {
            push (@result, {
               name     => $self->type('string', $value->name),
               description => $self->type('string', $value->description),
            });
        }
    }
254 255 256
    else {
        my @values = Bugzilla::Field::Choice->type($field)->get_all();
        foreach my $value (@values) {
257
            my $vis_val = $value->visibility_value;
258
            push(@result, {
259 260
                name     => $self->type('string', $value->name),
                sort_key => $self->type('int'   , $value->sortkey),
Frédéric Buclin's avatar
Frédéric Buclin committed
261
                sortkey  => $self->type('int'   , $value->sortkey), # deprecated
262 263 264 265
                visibility_values => [
                    defined $vis_val ? $self->type('string', $vis_val->name) 
                                     : ()
                ],
266 267 268 269 270 271 272
            });
        }
    }

    return \@result;
}

273
sub comments {
274
    my ($self, $params) = validate(@_, 'ids', 'comment_ids');
275

276
    if (!(defined $params->{ids} || defined $params->{comment_ids})) {
277 278
        ThrowCodeError('params_required',
                       { function => 'Bug.comments',
279
                         params   => ['ids', 'comment_ids'] });
280 281
    }

282
    my $bug_ids = $params->{ids} || [];
283 284
    my $comment_ids = $params->{comment_ids} || [];

285
    my $dbh  = Bugzilla->switch_to_shadow_db();
286 287 288 289 290 291
    my $user = Bugzilla->user;

    my %bugs;
    foreach my $bug_id (@$bug_ids) {
        my $bug = Bugzilla::Bug->check($bug_id);
        # We want the API to always return comments in the same order.
292 293 294
   
        my $comments = $bug->comments({ order => 'oldest_to_newest',
                                        after => $params->{new_since} });
295 296
        my @result;
        foreach my $comment (@$comments) {
297
            next if $comment->is_private && !$user->is_insider;
298 299 300 301 302 303 304 305
            push(@result, $self->_translate_comment($comment, $params));
        }
        $bugs{$bug->id}{'comments'} = \@result;
    }

    my %comments;
    if (scalar @$comment_ids) {
        my @ids = map { trim($_) } @$comment_ids;
306
        my $comment_data = Bugzilla::Comment->new_from_list(\@ids);
307 308

        # See if we were passed any invalid comment ids.
309
        my %got_ids = map { $_->id => 1 } @$comment_data;
310 311 312 313 314 315 316
        foreach my $comment_id (@ids) {
            if (!$got_ids{$comment_id}) {
                ThrowUserError('comment_id_invalid', { id => $comment_id });
            }
        }
 
        # Now make sure that we can see all the associated bugs.
317
        my %got_bug_ids = map { $_->bug_id => 1 } @$comment_data;
318 319 320
        Bugzilla::Bug->check($_) foreach (keys %got_bug_ids);

        foreach my $comment (@$comment_data) {
321 322
            if ($comment->is_private && !$user->is_insider) {
                ThrowUserError('comment_is_private', { id => $comment->id });
323
            }
324
            $comments{$comment->id} =
325 326 327 328 329 330 331
                $self->_translate_comment($comment, $params);
        }
    }

    return { bugs => \%bugs, comments => \%comments };
}

332 333 334 335 336 337 338 339 340 341 342 343
sub render_comment {
    my ($self, $params) = @_;

    unless (defined $params->{text}) {
        ThrowCodeError('params_required',
                       { function => 'Bug.render_comment',
                         params   => ['text'] });
    }

    Bugzilla->switch_to_shadow_db();
    my $bug = $params->{id} ? Bugzilla::Bug->check($params->{id}) : undef;

344
    my $tmpl = '[% text FILTER quoteUrls(bug) %]';
345 346 347 348 349 350 351 352 353 354 355
    my $html;
    my $template = Bugzilla->template;
    $template->process(
        \$tmpl,
        { bug => $bug, text => $params->{text}},
        \$html
    );

    return { html => $html };
}

356 357
# Helper for Bug.comments
sub _translate_comment {
358
    my ($self, $comment, $filters, $types, $prefix) = @_;
359 360
    my $attach_id = $comment->is_about_attachment ? $comment->extra_data
                                                  : undef;
361 362

    my $comment_hash = {
363 364 365 366
        id         => $self->type('int', $comment->id),
        bug_id     => $self->type('int', $comment->bug_id),
        creator    => $self->type('email', $comment->author->login),
        time       => $self->type('dateTime', $comment->creation_ts),
367
        creation_time => $self->type('dateTime', $comment->creation_ts),
368 369
        is_private => $self->type('boolean', $comment->is_private),
        text       => $self->type('string', $comment->body_full),
370
        attachment_id => $self->type('int', $attach_id),
371
        count      => $self->type('int', $comment->count),
372
    };
373 374 375 376 377 378 379 380 381

    # Don't load comment tags unless enabled
    if (Bugzilla->params->{'comment_taggers_group'}) {
        $comment_hash->{tags} = [
            map { $self->type('string', $_) }
            @{ $comment->tags }
        ];
    }

382
    return filter($filters, $comment_hash, $types, $prefix);
383 384
}

385
sub get {
386 387
    my ($self, $params) = validate(@_, 'ids');

388
    Bugzilla->switch_to_shadow_db() unless Bugzilla->user->id;
389

390 391 392
    my $ids = $params->{ids};
    defined $ids || ThrowCodeError('param_required', { param => 'ids' });

393
    my (@bugs, @faults, @hashes);
394 395 396 397 398 399

    # Cache permissions for bugs. This highly reduces the number of calls to the DB.
    # visible_bugs() is only able to handle bug IDs, so we have to skip aliases.
    my @int = grep { $_ =~ /^\d+$/ } @$ids;
    Bugzilla->user->visible_bugs(\@int);

400
    foreach my $bug_id (@$ids) {
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
        my $bug;
        if ($params->{permissive}) {
            eval { $bug = Bugzilla::Bug->check($bug_id); };
            if ($@) {
                push(@faults, {id => $bug_id,
                               faultString => $@->faultstring,
                               faultCode => $@->faultcode,
                              }
                    );
                undef $@;
                next;
            }
        }
        else {
            $bug = Bugzilla::Bug->check($bug_id);
        }
417 418
        push(@bugs, $bug);
        push(@hashes, $self->_bug_to_hash($bug, $params));
419
    }
420

421 422 423
    # Set the ETag before inserting the update tokens
    # since the tokens will always be unique even if
    # the data has not changed.
424
    $self->bz_etag(\@hashes);
425

426
    $self->_add_update_tokens($params, \@bugs, \@hashes);
427

428
    return { bugs => \@hashes, faults => \@faults };
429 430
}

431 432
# this is a function that gets bug activity for list of bug ids 
# it can be called as the following:
433 434
# $call = $rpc->call( 'Bug.history', { ids => [1,2] });
sub history {
435
    my ($self, $params) = validate(@_, 'ids');
436

437 438
    Bugzilla->switch_to_shadow_db();

439 440 441
    my $ids = $params->{ids};
    defined $ids || ThrowCodeError('param_required', { param => 'ids' });

442 443
    my %api_name = reverse %{ Bugzilla::Bug::FIELD_MAP() };
    $api_name{'bug_group'} = 'groups';
444

445
    my @return;
446 447
    foreach my $bug_id (@$ids) {
        my %item;
448 449
        my $bug = Bugzilla::Bug->check($bug_id);
        $bug_id = $bug->id;
450
        $item{id} = $self->type('int', $bug_id);
451

452
        my ($activity) = $bug->get_activity(undef, $params->{new_since});
453

454
        my @history;
455 456
        foreach my $changeset (@$activity) {
            my %bug_history;
457
            $bug_history{when} = $self->type('dateTime', $changeset->{when});
458
            $bug_history{who}  = $self->type('string', $changeset->{who});
459 460
            $bug_history{changes} = [];
            foreach my $change (@{ $changeset->{changes} }) {
461
                my $api_field = $api_name{$change->{fieldname}} || $change->{fieldname};
462 463
                my $attach_id = delete $change->{attachid};
                if ($attach_id) {
464
                    $change->{attachment_id} = $self->type('int', $attach_id);
465
                }
466 467
                $change->{removed} = $self->type('string', $change->{removed});
                $change->{added}   = $self->type('string', $change->{added});
468 469
                $change->{field_name} = $self->type('string', $api_field);
                delete $change->{fieldname};
470 471 472
                push (@{$bug_history{changes}}, $change);
            }
            
473 474 475 476
            push (@history, \%bug_history);
        }

        $item{history} = \@history;
477 478 479 480

        # alias is returned in case users passes a mixture of ids and aliases
        # then they get to know which bug activity relates to which value  
        # they passed
481
        $item{alias} = [ map { $self->type('string', $_) } @{ $bug->alias } ];
482 483 484 485 486 487

        push(@return, \%item);
    }

    return { bugs => \@return };
}
488

489 490
sub search {
    my ($self, $params) = @_;
491 492
    my $user = Bugzilla->user;
    my $dbh  = Bugzilla->dbh;
493

494 495
    Bugzilla->switch_to_shadow_db();

496 497 498 499 500 501 502 503 504 505 506 507
    my $match_params = dclone($params);
    delete $match_params->{include_fields};
    delete $match_params->{exclude_fields};

    # Determine whether this is a quicksearch query
    if (exists $match_params->{quicksearch}) {
        my $quicksearch = quicksearch($match_params->{'quicksearch'});
        my $cgi = Bugzilla::CGI->new($quicksearch);
        $match_params = $cgi->Vars;
    }

    if ( defined($match_params->{offset}) and !defined($match_params->{limit}) ) {
508
        ThrowCodeError('param_required',
509
                       { param => 'limit', function => 'Bug.search()' });
510
    }
511 512

    my $max_results = Bugzilla->params->{max_search_results};
513 514 515
    unless (defined $match_params->{limit} && $match_params->{limit} == 0) {
        if (!defined $match_params->{limit} || $match_params->{limit} > $max_results) {
            $match_params->{limit} = $max_results;
516 517 518
        }
    }
    else {
519 520
        delete $match_params->{limit};
        delete $match_params->{offset};
521 522
    }

523
    $match_params = Bugzilla::Bug::map_fields($match_params);
524

525 526 527
    my %options = ( fields => ['bug_id'] );

    # Find the highest custom field id
528
    my @field_ids = grep(/^f(\d+)$/, keys %$match_params);
529
    my $last_field_id = @field_ids ? max @field_ids + 1 : 1;
530

531
    # Do special search types for certain fields.
532 533 534 535
    if (my $change_when = delete $match_params->{'delta_ts'}) {
        $match_params->{"f${last_field_id}"} = 'delta_ts';
        $match_params->{"o${last_field_id}"} = 'greaterthaneq';
        $match_params->{"v${last_field_id}"} = $change_when;
536
        $last_field_id++;
537
    }
538 539 540 541
    if (my $creation_when = delete $match_params->{'creation_ts'}) {
        $match_params->{"f${last_field_id}"} = 'creation_ts';
        $match_params->{"o${last_field_id}"} = 'greaterthaneq';
        $match_params->{"v${last_field_id}"} = $creation_when;
542
        $last_field_id++;
543
    }
544 545 546

    # Some fields require a search type such as short desc, keywords, etc.
    foreach my $param (qw(short_desc longdesc status_whiteboard bug_file_loc)) {
547 548
        if (defined $match_params->{$param} && !defined $match_params->{$param . '_type'}) {
            $match_params->{$param . '_type'} = 'allwordssubstr';
549
        }
550
    }
551 552
    if (defined $match_params->{'keywords'} && !defined $match_params->{'keywords_type'}) {
        $match_params->{'keywords_type'} = 'allwords';
553
    }
554

555
    # Backwards compatibility with old method regarding role search
556
    $match_params->{'reporter'} = delete $match_params->{'creator'} if $match_params->{'creator'};
557
    foreach my $role (qw(assigned_to reporter qa_contact longdesc cc)) {
558 559 560 561 562
        next if !exists $match_params->{$role};
        my $value = delete $match_params->{$role};
        $match_params->{"f${last_field_id}"} = $role;
        $match_params->{"o${last_field_id}"} = "anywordssubstr";
        $match_params->{"v${last_field_id}"} = ref $value ? join(" ", @{$value}) : $value;
563 564 565
        $last_field_id++;
    }

566
    # If no other parameters have been passed other than limit and offset
567
    # then we throw error if system is configured to do so.
568
    if (!grep(!/^(limit|offset)$/, keys %$match_params)
569 570 571 572 573
        && !Bugzilla->params->{search_allow_no_criteria})
    {
        ThrowUserError('buglist_parameters_required');
    }

574 575
    $options{order}  = [ split(/\s*,\s*/, delete $match_params->{order}) ] if $match_params->{order};
    $options{params} = $match_params;
576

577 578 579 580 581 582 583 584 585
    my $search = new Bugzilla::Search(%options);
    my ($data) = $search->data;

    if (!scalar @$data) {
        return { bugs => [] };
    }

    # Search.pm won't return bugs that the user shouldn't see so no filtering is needed.
    my @bug_ids = map { $_->[0] } @$data;
586 587 588
    my %bug_objects = map { $_->id => $_ } @{ Bugzilla::Bug->new_from_list(\@bug_ids) };
    my @bugs = map { $bug_objects{$_} } @bug_ids;
    @bugs = map { $self->_bug_to_hash($_, $params) } @bugs;
589 590

    return { bugs => \@bugs };
591 592 593
}

sub possible_duplicates {
594
    my ($self, $params) = validate(@_, 'products');
595 596
    my $user = Bugzilla->user;

597 598
    Bugzilla->switch_to_shadow_db();

599 600 601 602 603
    # Undo the array-ification that validate() does, for "summary".
    $params->{summary} || ThrowCodeError('param_required',
        { function => 'Bug.possible_duplicates', param => 'summary' });

    my @products;
604
    foreach my $name (@{ $params->{'products'} || [] }) {
605 606 607 608 609 610 611 612
        my $object = $user->can_enter_product($name, THROW_ERROR);
        push(@products, $object);
    }

    my $possible_dupes = Bugzilla::Bug->possible_duplicates(
        { summary => $params->{summary}, products => \@products,
          limit   => $params->{limit} });
    my @hashes = map { $self->_bug_to_hash($_, $params) } @$possible_dupes;
613
    $self->_add_update_tokens($params, $possible_dupes, \@hashes);
614 615 616
    return { bugs => \@hashes };
}

617 618 619 620 621 622
sub update {
    my ($self, $params) = validate(@_, 'ids');

    my $user = Bugzilla->login(LOGIN_REQUIRED);
    my $dbh = Bugzilla->dbh;

623 624 625 626
    # We skip certain fields because their set_ methods actually use
    # the external names instead of the internal names.
    $params = Bugzilla::Bug::map_fields($params, 
        { summary => 1, platform => 1, severity => 1, url => 1 });
627 628 629 630

    my $ids = delete $params->{ids};
    defined $ids || ThrowCodeError('param_required', { param => 'ids' });

631
    my @bugs = map { Bugzilla::Bug->check_for_edit($_) } @$ids;
632 633 634 635 636 637 638 639 640 641 642 643

    my %values = %$params;
    $values{other_bugs} = \@bugs;

    if (exists $values{comment} and exists $values{comment}{comment}) {
        $values{comment}{body} = delete $values{comment}{comment};
    }

    # Prevent bugs that could be triggered by specifying fields that
    # have valid "set_" functions in Bugzilla::Bug, but shouldn't be
    # called using those field names.
    delete $values{dependencies};
644

645 646 647 648 649 650 651 652 653 654
    # For backwards compatibility, treat alias string or array as a set action
    if (exists $values{alias}) {
        if (not ref $values{alias}) {
            $values{alias} = { set => [ $values{alias} ] };
        }
        elsif (ref $values{alias} eq 'ARRAY') {
            $values{alias} = { set => $values{alias} };
        }
    }

655
    my $flags = delete $values{flags};
656 657 658

    foreach my $bug (@bugs) {
        $bug->set_all(\%values);
659 660 661 662
        if ($flags) {
            my ($old_flags, $new_flags) = extract_flags($flags, $bug);
            $bug->set_flags($old_flags, $new_flags);
        }
663 664 665 666 667 668 669 670
    }

    my %all_changes;
    $dbh->bz_start_transaction();
    foreach my $bug (@bugs) {
        $all_changes{$bug->id} = $bug->update();
    }
    $dbh->bz_commit_transaction();
671

672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
    foreach my $bug (@bugs) {
        $bug->send_changes($all_changes{$bug->id});
    }

    my %api_name = reverse %{ Bugzilla::Bug::FIELD_MAP() };
    # This doesn't normally belong in FIELD_MAP, but we do want to translate
    # "bug_group" back into "groups".
    $api_name{'bug_group'} = 'groups';

    my @result;
    foreach my $bug (@bugs) {
        my %hash = (
            id               => $self->type('int', $bug->id),
            last_change_time => $self->type('dateTime', $bug->delta_ts),
            changes          => {},
        );

        # alias is returned in case users pass a mixture of ids and aliases,
        # so that they can know which set of changes relates to which value
        # they passed.
692
        $hash{alias} = [ map { $self->type('string', $_) } @{ $bug->alias } ];
693 694 695 696 697

        my %changes = %{ $all_changes{$bug->id} };
        foreach my $field (keys %changes) {
            my $change = $changes{$field};
            my $api_field = $api_name{$field} || $field;
698 699 700 701 702
            # We normalize undef to an empty string, so that the API
            # stays consistent for things like Deadline that can become
            # empty.
            $change->[0] = '' if !defined $change->[0];
            $change->[1] = '' if !defined $change->[1];
703 704 705 706 707 708 709 710 711 712 713 714
            $hash{changes}->{$api_field} = {
                removed => $self->type('string', $change->[0]),
                added   => $self->type('string', $change->[1]) 
            };
        }

        push(@result, \%hash);
    }

    return { bugs => \@result };
}

715 716
sub create {
    my ($self, $params) = @_;
717 718
    my $dbh = Bugzilla->dbh;

719
    Bugzilla->login(LOGIN_REQUIRED);
720

721
    $params = Bugzilla::Bug::map_fields($params);
722 723 724 725 726 727 728

    my $flags = delete $params->{flags};

    # We start a nested transaction in case flag setting fails
    # we want the bug creation to roll back as well.
    $dbh->bz_start_transaction();

729
    my $bug = Bugzilla::Bug->create($params);
730 731 732 733 734 735 736 737 738 739

    # Set bug flags
    if ($flags) {
        my ($flags, $new_flags) = extract_flags($flags, $bug);
        $bug->set_flags($flags, $new_flags);
        $bug->update($bug->creation_ts);
    }

    $dbh->bz_commit_transaction();

740 741
    $bug->send_changes();

742
    return { id => $self->type('int', $bug->bug_id) };
743 744
}

745 746
sub legal_values {
    my ($self, $params) = @_;
747

748 749
    Bugzilla->switch_to_shadow_db();

750 751 752
    defined $params->{field} 
        or ThrowCodeError('param_required', { param => 'field' });

753 754
    my $field = Bugzilla::Bug::FIELD_MAP->{$params->{field}} 
                || $params->{field};
755

756 757
    my @global_selects =
        @{ Bugzilla->fields({ is_select => 1, is_abnormal => 0 }) };
758 759

    my $values;
760
    if (grep($_->name eq $field, @global_selects)) {
761 762
        # The field is a valid one.
        trick_taint($field);
763 764 765 766 767 768 769
        $values = get_legal_field_values($field);
    }
    elsif (grep($_ eq $field, PRODUCT_SPECIFIC_FIELDS)) {
        my $id = $params->{product_id};
        defined $id || ThrowCodeError('param_required',
            { function => 'Bug.legal_values', param => 'product_id' });
        grep($_->id eq $id, @{Bugzilla->user->get_accessible_products})
770
            || ThrowUserError('product_access_denied', { id => $id });
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791

        my $product = new Bugzilla::Product($id);
        my @objects;
        if ($field eq 'version') {
            @objects = @{$product->versions};
        }
        elsif ($field eq 'target_milestone') {
            @objects = @{$product->milestones};
        }
        elsif ($field eq 'component') {
            @objects = @{$product->components};
        }

        $values = [map { $_->name } @objects];
    }
    else {
        ThrowCodeError('invalid_field_name', { field => $params->{field} });
    }

    my @result;
    foreach my $val (@$values) {
792
        push(@result, $self->type('string', $val));
793 794 795 796 797
    }

    return { values => \@result };
}

798 799 800 801 802 803 804 805 806 807
sub add_attachment {
    my ($self, $params) = validate(@_, 'ids');
    my $dbh = Bugzilla->dbh;

    Bugzilla->login(LOGIN_REQUIRED);
    defined $params->{ids}
        || ThrowCodeError('param_required', { param => 'ids' });
    defined $params->{data}
        || ThrowCodeError('param_required', { param => 'data' });

808
    my @bugs = map { Bugzilla::Bug->check_for_edit($_) } @{ $params->{ids} };
809 810 811

    my @created;
    $dbh->bz_start_transaction();
812 813
    my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');

814 815
    my $flags = delete $params->{flags};

816 817 818
    foreach my $bug (@bugs) {
        my $attachment = Bugzilla::Attachment->create({
            bug         => $bug,
819
            creation_ts => $timestamp,
820 821 822 823 824 825 826
            data        => $params->{data},
            description => $params->{summary},
            filename    => $params->{file_name},
            mimetype    => $params->{content_type},
            ispatch     => $params->{is_patch},
            isprivate   => $params->{is_private},
        });
827 828 829 830 831 832 833

        if ($flags) {
            my ($old_flags, $new_flags) = extract_flags($flags, $bug, $attachment);
            $attachment->set_flags($old_flags, $new_flags);
        }

        $attachment->update($timestamp);
834
        my $comment = $params->{comment} || '';
835 836 837 838
        $attachment->bug->add_comment($comment, 
            { isprivate  => $attachment->isprivate,
              type       => CMT_ATTACHMENT_CREATED,
              extra_data => $attachment->id });
839 840
        push(@created, $attachment);
    }
841
    $_->bug->update($timestamp) foreach @created;
842 843 844 845
    $dbh->bz_commit_transaction();

    $_->send_changes() foreach @bugs;

846
    my @created_ids = map { $_->id } @created;
847

848
    return { ids => \@created_ids };
849 850
}

851 852 853 854 855 856 857 858 859 860 861 862 863 864
sub update_attachment {
    my ($self, $params) = validate(@_, 'ids');

    my $user = Bugzilla->login(LOGIN_REQUIRED);
    my $dbh = Bugzilla->dbh;

    my $ids = delete $params->{ids};
    defined $ids || ThrowCodeError('param_required', { param => 'ids' });

    # Some fields cannot be sent to set_all
    foreach my $key (qw(login password token)) {
        delete $params->{$key};
    }

865
    $params = translate($params, ATTACHMENT_MAPPED_SETTERS);
866 867 868 869 870 871 872 873 874 875 876 877 878 879

    # Get all the attachments, after verifying that they exist and are editable
    my @attachments = ();
    my %bugs = ();
    foreach my $id (@$ids) {
        my $attachment = Bugzilla::Attachment->new($id)
          || ThrowUserError("invalid_attach_id", { attach_id => $id });
        my $bug = $attachment->bug;
        $attachment->_check_bug;

        push @attachments, $attachment;
        $bugs{$bug->id} = $bug;
    }

880
    my $flags = delete $params->{flags};
881
    my $comment = delete $params->{comment};
882

883 884
    # Update the values
    foreach my $attachment (@attachments) {
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
        my ($update_flags, $new_flags) = $flags
            ? extract_flags($flags, $attachment->bug, $attachment)
            : ([], []);
        if ($attachment->validate_can_edit) {
            $attachment->set_all($params);
            $attachment->set_flags($update_flags, $new_flags) if $flags;
        }
        elsif (scalar @$update_flags && !scalar(@$new_flags) && !scalar keys %$params) {
            # Requestees can set flags targetted to them, even if they cannot
            # edit the attachment. Flag setters can edit their own flags too.
            my %flag_list = map { $_->{id} => $_ } @$update_flags;
            my $flag_objs = Bugzilla::Flag->new_from_list([ keys %flag_list ]);
            my @editable_flags;
            foreach my $flag_obj (@$flag_objs) {
                if ($flag_obj->setter_id == $user->id
                    || ($flag_obj->requestee_id && $flag_obj->requestee_id == $user->id))
                {
                    push(@editable_flags, $flag_list{$flag_obj->id});
                }
            }
            if (!scalar @editable_flags) {
                ThrowUserError("illegal_attachment_edit", { attach_id => $attachment->id });
            }
            $attachment->set_flags(\@editable_flags, []);
        }
        else {
            ThrowUserError("illegal_attachment_edit", { attach_id => $attachment->id });
912
        }
913 914 915 916 917 918 919 920 921
    }

    $dbh->bz_start_transaction();

    # Do the actual update and get information to return to user
    my @result;
    foreach my $attachment (@attachments) {
        my $changes = $attachment->update();

922 923
        if ($comment = trim($comment)) {
            $attachment->bug->add_comment($comment,
924 925 926
                { isprivate  => $attachment->isprivate,
                  type       => CMT_ATTACHMENT_UPDATED,
                  extra_data => $attachment->id });
927 928
        }

929 930
        $changes = translate($changes, ATTACHMENT_MAPPED_RETURNS);

931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
        my %hash = (
            id               => $self->type('int', $attachment->id),
            last_change_time => $self->type('dateTime', $attachment->modification_time),
            changes          => {},
        );

        foreach my $field (keys %$changes) {
            my $change = $changes->{$field};

            # We normalize undef to an empty string, so that the API
            # stays consistent for things like Deadline that can become
            # empty.
            $hash{changes}->{$field} = {
                removed => $self->type('string', $change->[0] // ''),
                added   => $self->type('string', $change->[1] // '')
            };
        }

        push(@result, \%hash);
    }

    $dbh->bz_commit_transaction();

    # Email users about the change
    foreach my $bug (values %bugs) {
956 957
        $bug->update();
        $bug->send_changes();
958 959 960 961 962 963
    }

    # Return the information to the user
    return { attachments => \@result };
}

964 965
sub add_comment {
    my ($self, $params) = @_;
966 967 968 969

    # The user must login in order add a comment
    my $user = Bugzilla->login(LOGIN_REQUIRED);

970 971
    # Check parameters
    defined $params->{id} 
972
        || ThrowCodeError('param_required', { param => 'id' }); 
973
    my $comment = $params->{comment}; 
974
    (defined $comment && trim($comment) ne '')
975 976
        || ThrowCodeError('param_required', { param => 'comment' });
    
977
    my $bug = Bugzilla::Bug->check_for_edit($params->{id});
978

979 980 981 982
    # Backwards-compatibility for versions before 3.6    
    if (defined $params->{private}) {
        $params->{is_private} = delete $params->{private};
    }
983
    # Append comment
984 985
    $bug->add_comment($comment, { isprivate => $params->{is_private},
                                  work_time => $params->{work_time} });
986
    $bug->update();
987 988 989

    my $new_comment_id = $bug->{added_comments}[0]->id;

990
    # Send mail.
991 992
    Bugzilla::BugMail::Send($bug->bug_id, { changer => $user });

993
    return { id => $self->type('int', $new_comment_id) };
994 995
}

996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
sub update_see_also {
    my ($self, $params) = @_;

    my $user = Bugzilla->login(LOGIN_REQUIRED);

    # Check parameters
    $params->{ids}
        || ThrowCodeError('param_required', { param => 'id' });
    my ($add, $remove) = @$params{qw(add remove)};
    ($add || $remove)
        or ThrowCodeError('params_required', { params => ['add', 'remove'] });

    my @bugs;
    foreach my $id (@{ $params->{ids} }) {
1010
        my $bug = Bugzilla::Bug->check_for_edit($id);
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
        push(@bugs, $bug);
        if ($remove) {
            $bug->remove_see_also($_) foreach @$remove;
        }
        if ($add) {
            $bug->add_see_also($_) foreach @$add;
        }
    }
    
    my %changes;
    foreach my $bug (@bugs) {
        my $change = $bug->update();
        if (my $see_also = $change->{see_also}) {
1024
            $changes{$bug->id}->{see_also} = {
1025 1026 1027 1028 1029 1030
                removed => [split(', ', $see_also->[0])],
                added   => [split(', ', $see_also->[1])],
            };
        }
        else {
            # We still want a changes entry, for API consistency.
1031
            $changes{$bug->id}->{see_also} = { added => [], removed => [] };
1032 1033
        }

1034
        Bugzilla::BugMail::Send($bug->id, { changer => $user });
1035 1036 1037 1038 1039
    }

    return { changes => \%changes };
}

1040
sub attachments {
1041
    my ($self, $params) = validate(@_, 'ids', 'attachment_ids');
1042

1043
    Bugzilla->switch_to_shadow_db() unless Bugzilla->user->id;
1044

1045
    if (!(defined $params->{ids}
1046
          or defined $params->{attachment_ids}))
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
    {
        ThrowCodeError('param_required',
                       { function => 'Bug.attachments', 
                         params   => ['ids', 'attachment_ids'] });
    }

    my $ids = $params->{ids} || [];
    my $attach_ids = $params->{attachment_ids} || [];

    my %bugs;
1057 1058
    foreach my $bug_id (@$ids) {
        my $bug = Bugzilla::Bug->check($bug_id);
1059
        $bugs{$bug->id} = [];
1060
        foreach my $attach (@{$bug->attachments}) {
1061
            push @{$bugs{$bug->id}},
1062 1063 1064
                $self->_attachment_to_hash($attach, $params);
        }
    }
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077

    my %attachments;
    foreach my $attach (@{Bugzilla::Attachment->new_from_list($attach_ids)}) {
        Bugzilla::Bug->check($attach->bug_id);
        if ($attach->isprivate && !Bugzilla->user->is_insider) {
            ThrowUserError('auth_failure', {action    => 'access',
                                            object    => 'attachment',
                                            attach_id => $attach->id});
        }
        $attachments{$attach->id} =
            $self->_attachment_to_hash($attach, $params);
    }

1078
    return { bugs => \%bugs, attachments => \%attachments };
1079 1080
}

1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
sub update_tags {
    my ($self, $params) = @_;

    Bugzilla->login(LOGIN_REQUIRED);

    my $ids  = $params->{ids};
    my $tags = $params->{tags};

    ThrowCodeError('param_required',
                   { function => 'Bug.update_tags', 
                     param    => 'ids' }) if !defined $ids;

    ThrowCodeError('param_required',
                   { function => 'Bug.update_tags', 
                     param    => 'tags' }) if !defined $tags;

    my %changes;
    foreach my $bug_id (@$ids) {
        my $bug = Bugzilla::Bug->check($bug_id);
        my @old_tags = @{ $bug->tags };

        $bug->remove_tag($_) foreach @{ $tags->{remove} || [] };
        $bug->add_tag($_) foreach @{ $tags->{add} || [] };

        my ($removed, $added) = diff_arrays(\@old_tags, $bug->tags);

        my @removed = map { $self->type('string', $_) } @$removed;
        my @added   = map { $self->type('string', $_) } @$added;

        $changes{$bug->id}->{tags} = {
            removed => \@removed,
            added   => \@added
        };
    }

    return { changes => \%changes };
}

1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
sub update_comment_tags {
    my ($self, $params) = @_;

    my $user = Bugzilla->login(LOGIN_REQUIRED);
    Bugzilla->params->{'comment_taggers_group'}
        || ThrowUserError("comment_tag_disabled");
    $user->can_tag_comments
        || ThrowUserError("auth_failure",
                          { group  => Bugzilla->params->{'comment_taggers_group'},
                            action => "update",
                            object => "comment_tags" });

    my $comment_id  = $params->{comment_id}
        // ThrowCodeError('param_required',
                          { function => 'Bug.update_comment_tags',
                            param    => 'comment_id' });

    my $comment = Bugzilla::Comment->new($comment_id)
        || return [];
    $comment->bug->check_is_visible();
    if ($comment->is_private && !$user->is_insider) {
        ThrowUserError('comment_is_private', { id => $comment_id });
    }

    my $dbh = Bugzilla->dbh;
    $dbh->bz_start_transaction();
    foreach my $tag (@{ $params->{add} || [] }) {
        $comment->add_tag($tag) if defined $tag;
    }
    foreach my $tag (@{ $params->{remove} || [] }) {
        $comment->remove_tag($tag) if defined $tag;
    }
    $comment->update();
    $dbh->bz_commit_transaction();

    return $comment->tags;
}

sub search_comment_tags {
    my ($self, $params) = @_;

    Bugzilla->login(LOGIN_REQUIRED);
    Bugzilla->params->{'comment_taggers_group'}
        || ThrowUserError("comment_tag_disabled");
    Bugzilla->user->can_tag_comments
        || ThrowUserError("auth_failure", { group  => Bugzilla->params->{'comment_taggers_group'},
                                            action => "search",
                                            object => "comment_tags"});

    my $query = $params->{query};
    $query
        // ThrowCodeError('param_required', { param => 'query' });
1171 1172 1173 1174 1175
    my $limit = $params->{limit} || 7;
    detaint_natural($limit)
        || ThrowCodeError('param_must_be_numeric', { param    => 'limit',
                                                     function => 'Bug.search_comment_tags' });

1176 1177 1178 1179 1180 1181 1182 1183 1184 1185

    my $tags = Bugzilla::Comment::TagWeights->match({
        WHERE => {
            'tag LIKE ?' => "\%$query\%",
        },
        LIMIT => $limit,
    });
    return [ map { $_->tag } @$tags ];
}

1186 1187 1188 1189
##############################
# Private Helper Subroutines #
##############################

1190 1191 1192 1193 1194
# A helper for get() and search(). This is done in this fashion in order
# to produce a stable API and to explicitly type return values.
# The internals of Bugzilla::Bug are not stable enough to just
# return them directly.

1195
sub _bug_to_hash {
1196 1197 1198 1199 1200
    my ($self, $bug, $params) = @_;

    # All the basic bug attributes are here, in alphabetical order.
    # A bug attribute is "basic" if it doesn't require an additional
    # database call to get the info.
1201
    my %item = %{ filter $params, {
1202 1203 1204
        # No need to format $bug->deadline specially, because Bugzilla::Bug
        # already does it for us.
        deadline         => $self->type('string', $bug->deadline),
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
        id               => $self->type('int', $bug->bug_id),
        is_confirmed     => $self->type('boolean', $bug->everconfirmed),
        op_sys           => $self->type('string', $bug->op_sys),
        platform         => $self->type('string', $bug->rep_platform),
        priority         => $self->type('string', $bug->priority),
        resolution       => $self->type('string', $bug->resolution),
        severity         => $self->type('string', $bug->bug_severity),
        status           => $self->type('string', $bug->bug_status),
        summary          => $self->type('string', $bug->short_desc),
        target_milestone => $self->type('string', $bug->target_milestone),
        url              => $self->type('string', $bug->bug_file_loc),
        version          => $self->type('string', $bug->version),
        whiteboard       => $self->type('string', $bug->status_whiteboard),
1218
    } };
1219

1220 1221
    # First we handle any fields that require extra work (such as date parsing
    # or SQL calls).
1222 1223 1224
    if (filter_wants $params, 'alias') {
        $item{alias} = [ map { $self->type('string', $_) } @{ $bug->alias } ];
    }
1225
    if (filter_wants $params, 'assigned_to') {
1226
        $item{'assigned_to'} = $self->type('email', $bug->assigned_to->login);
1227
        $item{'assigned_to_detail'} = $self->_user_to_hash($bug->assigned_to, $params, undef, 'assigned_to');
1228 1229 1230 1231 1232
    }
    if (filter_wants $params, 'blocks') {
        my @blocks = map { $self->type('int', $_) } @{ $bug->blocked };
        $item{'blocks'} = \@blocks;
    }
1233 1234 1235 1236 1237 1238
    if (filter_wants $params, 'classification') {
        $item{classification} = $self->type('string', $bug->classification);
    }
    if (filter_wants $params, 'component') {
        $item{component} = $self->type('string', $bug->component);
    }
1239
    if (filter_wants $params, 'cc') {
1240
        my @cc = map { $self->type('email', $_) } @{ $bug->cc };
1241
        $item{'cc'} = \@cc;
1242
        $item{'cc_detail'} = [ map { $self->_user_to_hash($_, $params, undef, 'cc') } @{ $bug->cc_users } ];
1243
    }
1244 1245 1246
    if (filter_wants $params, 'creation_time') {
        $item{'creation_time'} = $self->type('dateTime', $bug->creation_ts);
    }
1247
    if (filter_wants $params, 'creator') {
1248
        $item{'creator'} = $self->type('email', $bug->reporter->login);
1249
        $item{'creator_detail'} = $self->_user_to_hash($bug->reporter, $params, undef, 'creator');
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
    }
    if (filter_wants $params, 'depends_on') {
        my @depends_on = map { $self->type('int', $_) } @{ $bug->dependson };
        $item{'depends_on'} = \@depends_on;
    }
    if (filter_wants $params, 'dupe_of') {
        $item{'dupe_of'} = $self->type('int', $bug->dup_id);
    }
    if (filter_wants $params, 'groups') {
        my @groups = map { $self->type('string', $_->name) }
                     @{ $bug->groups_in };
        $item{'groups'} = \@groups;
    }
    if (filter_wants $params, 'is_open') {
        $item{'is_open'} = $self->type('boolean', $bug->status->is_open);
    }
    if (filter_wants $params, 'keywords') {
        my @keywords = map { $self->type('string', $_->name) }
                       @{ $bug->keyword_objects };
        $item{'keywords'} = \@keywords;
    }
1271 1272 1273
    if (filter_wants $params, 'last_change_time') {
        $item{'last_change_time'} = $self->type('dateTime', $bug->delta_ts);
    }
1274 1275 1276
    if (filter_wants $params, 'product') {
        $item{product} = $self->type('string', $bug->product);
    }
1277 1278
    if (filter_wants $params, 'qa_contact') {
        my $qa_login = $bug->qa_contact ? $bug->qa_contact->login : '';
1279
        $item{'qa_contact'} = $self->type('email', $qa_login);
1280
        if ($bug->qa_contact) {
1281
            $item{'qa_contact_detail'} = $self->_user_to_hash($bug->qa_contact, $params, undef, 'qa_contact');
1282
        }
1283 1284
    }
    if (filter_wants $params, 'see_also') {
1285 1286
        my @see_also = map { $self->type('string', $_->name) }
                       @{ $bug->see_also };
1287 1288
        $item{'see_also'} = \@see_also;
    }
1289 1290 1291
    if (filter_wants $params, 'flags') {
        $item{'flags'} = [ map { $self->_flag_to_hash($_) } @{$bug->flags} ];
    }
1292 1293 1294
    if (filter_wants $params, 'tags', 'extra') {
        $item{'tags'} = $bug->tags;
    }
1295

1296 1297 1298 1299
    # And now custom fields
    my @custom_fields = Bugzilla->active_custom_fields;
    foreach my $field (@custom_fields) {
        my $name = $field->name;
1300
        next if !filter_wants($params, $name, ['default', 'custom']);
1301 1302 1303
        if ($field->type == FIELD_TYPE_BUG_ID) {
            $item{$name} = $self->type('int', $bug->$name);
        }
1304 1305 1306
        elsif ($field->type == FIELD_TYPE_DATETIME
               || $field->type == FIELD_TYPE_DATE)
        {
1307 1308 1309 1310 1311 1312 1313 1314 1315
            $item{$name} = $self->type('dateTime', $bug->$name);
        }
        elsif ($field->type == FIELD_TYPE_MULTI_SELECT) {
            my @values = map { $self->type('string', $_) } @{ $bug->$name };
            $item{$name} = \@values;
        }
        else {
            $item{$name} = $self->type('string', $bug->$name);
        }
1316 1317
    }

1318 1319
    # Timetracking fields are only sent if the user can see them.
    if (Bugzilla->user->is_timetracker) {
1320 1321 1322 1323 1324 1325
        if (filter_wants $params, 'estimated_time') {
            $item{'estimated_time'} = $self->type('double', $bug->estimated_time);
        }
        if (filter_wants $params, 'remaining_time') {
            $item{'remaining_time'} = $self->type('double', $bug->remaining_time);
        }
1326 1327 1328
        if (filter_wants $params, 'actual_time') {
            $item{'actual_time'} = $self->type('double', $bug->actual_time);
        }
1329
    }
1330

1331 1332
    # The "accessible" bits go here because they have long names and it
    # makes the code look nicer to separate them out.
1333 1334 1335 1336 1337 1338
    if (filter_wants $params, 'is_cc_accessible') {
        $item{'is_cc_accessible'} = $self->type('boolean', $bug->cclist_accessible);
    }
    if (filter_wants $params, 'is_creator_accessible') {
        $item{'is_creator_accessible'} = $self->type('boolean', $bug->reporter_accessible);
    }
1339

1340
    return \%item;
1341 1342
}

1343
sub _user_to_hash {
1344
    my ($self, $user, $filters, $types, $prefix) = @_;
1345 1346 1347 1348 1349
    my $item = filter $filters, {
        id        => $self->type('int', $user->id),
        real_name => $self->type('string', $user->name),
        name      => $self->type('email', $user->login),
        email     => $self->type('email', $user->email),
1350
    }, $types, $prefix;
1351 1352 1353
    return $item;
}

1354
sub _attachment_to_hash {
1355
    my ($self, $attach, $filters, $types, $prefix) = @_;
1356

1357
    my $item = filter $filters, {
1358 1359 1360
        creation_time    => $self->type('dateTime', $attach->attached),
        last_change_time => $self->type('dateTime', $attach->modification_time),
        id               => $self->type('int', $attach->id),
1361
        bug_id           => $self->type('int', $attach->bug_id),
1362
        file_name        => $self->type('string', $attach->filename),
1363
        summary          => $self->type('string', $attach->description),
1364 1365 1366 1367
        content_type     => $self->type('string', $attach->contenttype),
        is_private       => $self->type('int', $attach->isprivate),
        is_obsolete      => $self->type('int', $attach->isobsolete),
        is_patch         => $self->type('int', $attach->ispatch),
1368
    }, $types, $prefix;
1369

1370
    # creator requires an extra lookup, so we only send them if
1371
    # the filter wants them.
1372 1373
    if (filter_wants $filters, 'creator', $types, $prefix) {
        $item->{'creator'} = $self->type('email', $attach->attacher->login);
1374 1375
    }

1376
    if (filter_wants $filters, 'data', $types, $prefix) {
1377 1378 1379
        $item->{'data'} = $self->type('base64', $attach->data);
    }

1380
    if (filter_wants $filters, 'size', $types, $prefix) {
1381 1382 1383
        $item->{'size'} = $self->type('int', $attach->datasize);
    }

1384
    if (filter_wants $filters, 'flags', $types, $prefix) {
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404
        $item->{'flags'} = [ map { $self->_flag_to_hash($_) } @{$attach->flags} ];
    }

    return $item;
}

sub _flag_to_hash {
    my ($self, $flag) = @_;

    my $item = {
        id                => $self->type('int', $flag->id),
        name              => $self->type('string', $flag->name),
        type_id           => $self->type('int', $flag->type_id),
        creation_date     => $self->type('dateTime', $flag->creation_date), 
        modification_date => $self->type('dateTime', $flag->modification_date), 
        status            => $self->type('string', $flag->status)
    };

    foreach my $field (qw(setter requestee)) {
        my $field_id = $field . "_id";
1405
        $item->{$field} = $self->type('email', $flag->$field->login)
1406 1407 1408
            if $flag->$field_id;
    }

1409
    return $item;
1410 1411
}

1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
sub _add_update_tokens {
    my ($self, $params, $bugs, $hashes) = @_;

    return if !Bugzilla->user->id;
    return if !filter_wants($params, 'update_token');

    for(my $i = 0; $i < @$bugs; $i++) {
        my $token = issue_hash_token([$bugs->[$i]->id, $bugs->[$i]->delta_ts]);
        $hashes->[$i]->{'update_token'} = $self->type('string', $token);
    }
}

1424
1;
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434

__END__

=head1 NAME

Bugzilla::Webservice::Bug - The API for creating, changing, and getting the
details of bugs.

=head1 DESCRIPTION

1435 1436
This part of the Bugzilla API allows you to file a new bug in Bugzilla,
or get information about bugs that have already been filed.
1437 1438 1439

=head1 METHODS

1440 1441
See L<Bugzilla::WebService> for a description of how parameters are passed,
and what B<STABLE>, B<UNSTABLE>, and B<EXPERIMENTAL> mean.
1442

1443 1444 1445 1446
Although the data input and output is the same for JSONRPC, XMLRPC and REST,
the directions for how to access the data via REST is noted in each method
where applicable.

1447
=head1 Utility Functions
1448

1449
=head2 fields
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459

B<UNSTABLE>

=over

=item B<Description>

Get information about valid bug fields, including the lists of legal values
for each field.

1460 1461 1462 1463 1464 1465 1466
=item B<REST>

You have several options for retreiving information about fields. The first
part is the request method and the rest is the related path needed.

To get information about all fields:

1467
GET /rest/field/bug
1468 1469 1470

To get information related to a single field:

1471
GET /rest/field/bug/<id_or_name>
1472 1473 1474

The returned data format is the same as below.

1475 1476 1477 1478
=item B<Params>

You can pass either field ids or field names.

1479
B<Note>: If neither C<ids> nor C<names> is specified, then all
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
non-obsolete fields will be returned.

In addition to the parameters below, this method also accepts the
standard L<include_fields|Bugzilla::WebService/include_fields> and
L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.

=over

=item C<ids>   (array) - An array of integer field ids.

=item C<names> (array) - An array of strings representing field names.

=back

=item B<Returns>

A hash containing a single element, C<fields>. This is an array of hashes,
containing the following keys:

=over

=item C<id>

Matt Selsky's avatar
Matt Selsky committed
1503
C<int> An integer id uniquely identifying this field in this installation only.
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526

=item C<type>

C<int> The number of the fieldtype. The following values are defined:

=over

=item C<0> Unknown

=item C<1> Free Text

=item C<2> Drop Down

=item C<3> Multiple-Selection Box

=item C<4> Large Text Box

=item C<5> Date/Time

=item C<6> Bug Id

=item C<7> Bug URLs ("See Also")

1527 1528 1529 1530 1531 1532
=item C<8> Keywords

=item C<9> Date

=item C<10> Integer value

1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
=back

=item C<is_custom>

C<boolean> True when this is a custom field, false otherwise.

=item C<name>

C<string> The internal name of this field. This is a unique identifier for
this field. If this is not a custom field, then this name will be the same
across all Bugzilla installations.

=item C<display_name>

C<string> The name of the field, as it is shown in the user interface.

1549 1550 1551 1552 1553 1554
=item C<is_mandatory>

C<boolean> True if the field must have a value when filing new bugs.
Also, mandatory fields cannot have their value cleared when updating
bugs.

1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
=item C<is_on_bug_entry>

C<boolean> For custom fields, this is true if the field is shown when you
enter a new bug. For standard fields, this is currently always false,
even if the field shows up when entering a bug. (To know whether or not
a standard field is valid on bug entry, see L</create>.)

=item C<visibility_field>

C<string>  The name of a field that controls the visibility of this field
in the user interface. This field only appears in the user interface when
the named field is equal to one of the values in C<visibility_values>.
Can be null.

=item C<visibility_values>

C<array> of C<string>s This field is only shown when C<visibility_field>
matches one of these values. When C<visibility_field> is null,
then this is an empty array.

=item C<value_field>

C<string>  The name of the field that controls whether or not particular
values of the field are shown in the user interface. Can be null.

=item C<values>

This is an array of hashes, representing the legal values for
select-type (drop-down and multiple-selection) fields. This is also
1584
populated for the C<component>, C<version>, C<target_milestone>, and C<keywords>
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600
fields, but not for the C<product> field (you must use
L<Product.get_accessible_products|Bugzilla::WebService::Product/get_accessible_products>
for that.

For fields that aren't select-type fields, this will simply be an empty
array.

Each hash has the following keys:

=over 

=item C<name>

C<string> The actual value--this is what you would specify for this
field in L</create>, etc.

1601
=item C<sort_key>
1602 1603 1604 1605

C<int> Values, when displayed in a list, are sorted first by this integer
and then secondly by their name.

1606 1607 1608 1609
=item C<sortkey>

B<DEPRECATED> - Use C<sort_key> instead.

1610 1611 1612 1613 1614 1615 1616
=item C<visibility_values>

If C<value_field> is defined for this field, then this value is only shown
if the C<value_field> is set to one of the values listed in this array.
Note that for per-product fields, C<value_field> is set to C<'product'>
and C<visibility_values> will reflect which product(s) this value appears in.

1617 1618 1619 1620 1621 1622
=item C<is_active>

C<boolean> This value is defined only for certain product specific fields
such as version, target_milestone or component. When true, the value is active,
otherwise the value is not active.

1623 1624 1625 1626 1627
=item C<description>

C<string> The description of the value. This item is only included for the
C<keywords> field.

1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674
=item C<is_open>

C<boolean> For C<bug_status> values, determines whether this status
specifies that the bug is "open" (true) or "closed" (false). This item
is only included for the C<bug_status> field.

=item C<can_change_to>

For C<bug_status> values, this is an array of hashes that determines which
statuses you can transition to from this status. (This item is only included
for the C<bug_status> field.)

Each hash contains the following items:

=over

=item C<name>

the name of the new status

=item C<comment_required>

this C<boolean> True if a comment is required when you change a bug into
this status using this transition.

=back

=back

=back

=item B<Errors>

=over

=item 51 (Invalid Field Name or Id)

You specified an invalid field name or id.

=back

=item B<History>

=over

=item Added in Bugzilla B<3.6>.

1675 1676
=item The C<is_mandatory> return value was added in Bugzilla B<4.0>.

1677 1678
=item C<sortkey> was renamed to C<sort_key> in Bugzilla B<4.2>.

1679 1680
=item C<is_active> return key for C<values> was added in Bugzilla B<4.4>.

1681 1682
=item REST API call added in Bugzilla B<5.0>

1683 1684 1685 1686
=back

=back

1687
=head2 legal_values
1688

1689
B<DEPRECATED> - Use L</fields> instead.
1690 1691 1692 1693 1694 1695 1696

=over

=item B<Description>

Tells you what values are allowed for a particular field.

1697 1698 1699 1700
=item B<REST>

To get information on the values for a field based on field name:

1701
GET /rest/field/bug/<field_name>/values
1702 1703 1704

To get information based on field name and a specific product:

1705
GET /rest/field/bug/<field_name>/<product_id>/values
1706 1707 1708

The returned data format is the same as below.

1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
=item B<Params>

=over

=item C<field> - The name of the field you want information about.
This should be the same as the name you would use in L</create>, below.

=item C<product_id> - If you're picking a product-specific field, you have
to specify the id of the product you want the values for.

=back

=item B<Returns> 

C<values> - An array of strings: the legal values for this field.
The values will be sorted as they normally would be in Bugzilla.

=item B<Errors>

=over

=item 106 (Invalid Product)

You were required to specify a product, and either you didn't, or you
specified an invalid product (or a product that you can't access).

=item 108 (Invalid Field Name)

You specified a field that doesn't exist or isn't a drop-down field.

=back

1741 1742 1743 1744 1745 1746 1747 1748
=item B<History>

=over

=item REST API call added in Bugzilla B<5.0>.

=back

1749 1750
=back

1751
=head1 Bug Information
1752

1753
=head2 attachments
1754 1755 1756 1757 1758 1759 1760

B<EXPERIMENTAL>

=over

=item B<Description>

1761 1762
It allows you to get data about attachments, given a list of bugs
and/or attachment ids.
1763 1764 1765 1766

B<Note>: Private attachments will only be returned if you are in the 
insidergroup or if you are the submitter of the attachment.

1767 1768 1769 1770
=item B<REST>

To get all current attachments for a bug:

1771
GET /rest/bug/<bug_id>/attachment
1772 1773 1774

To get a specific attachment based on attachment ID:

1775
GET /rest/bug/attachment/<attachment_id>
1776 1777 1778

The returned data format is the same as below.

1779 1780
=item B<Params>

1781 1782
B<Note>: At least one of C<ids> or C<attachment_ids> is required.

1783 1784
=over

1785
=item C<ids>
1786

1787
See the description of the C<ids> parameter in the L</get> method.
1788

1789 1790 1791 1792
=item C<attachment_ids>

C<array> An array of integer attachment ids.

1793 1794
=back

1795 1796 1797
Also accepts the L<include_fields|Bugzilla::WebService/include_fields>,
and L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.

1798 1799
=item B<Returns>

1800 1801 1802 1803 1804
A hash containing two elements: C<bugs> and C<attachments>. The return
value looks like this:

 {
     bugs => {
1805 1806 1807 1808 1809 1810 1811 1812
         1345 => [
             { (attachment) },
             { (attachment) }
         ],
         9874 => [
             { (attachment) },
             { (attachment) }
         ],
1813 1814 1815 1816 1817 1818 1819 1820 1821 1822
     },

     attachments => {
         234 => { (attachment) },
         123 => { (attachment) },
     }
 }

The attachments of any bugs that you specified in the C<ids> argument in
input are returned in C<bugs> on output. C<bugs> is a hash that has integer
1823 1824
bug IDs for keys and the values are arrayrefs that contain hashes as attachments.
(Fields for attachments are described below.)
1825 1826 1827 1828 1829 1830 1831

For any attachments that you specified directly in C<attachment_ids>, they
are returned in C<attachments> on output. This is a hash where the attachment
ids point directly to hashes describing the individual attachment.

The fields for each attachment (where it says C<(attachment)> in the
diagram above) are:
1832 1833 1834

=over

1835 1836 1837 1838
=item C<data>

C<base64> The raw data of the attachment, encoded as Base64.

1839 1840 1841 1842
=item C<size>

C<int> The length (in bytes) of the attachment.

1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
=item C<creation_time>

C<dateTime> The time the attachment was created.

=item C<last_change_time>

C<dateTime> The last time the attachment was modified.

=item C<id>

C<int> The numeric id of the attachment.

=item C<bug_id>

C<int> The numeric id of the bug that the attachment is attached to.

=item C<file_name>

C<string> The file name of the attachment.

1863 1864 1865
=item C<summary>

C<string> A short string describing the attachment.
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883

=item C<content_type>

C<string> The MIME type of the attachment.

=item C<is_private>

C<boolean> True if the attachment is private (only visible to a certain
group called the "insidergroup"), False otherwise.

=item C<is_obsolete>

C<boolean> True if the attachment is obsolete, False otherwise.

=item C<is_patch>

C<boolean> True if the attachment is a patch, False otherwise.

1884
=item C<creator>
1885 1886 1887

C<string> The login name of the user that created the attachment.

1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929
=item C<flags>

An array of hashes containing the information about flags currently set
for each attachment. Each flag hash contains the following items:

=over

=item C<id> 

C<int> The id of the flag.

=item C<name>

C<string> The name of the flag.

=item C<type_id>

C<int> The type id of the flag.

=item C<creation_date>

C<dateTime> The timestamp when this flag was originally created.

=item C<modification_date>

C<dateTime> The timestamp when the flag was last modified.

=item C<status>

C<string> The current status of the flag.

=item C<setter>

C<string> The login name of the user who created or last modified the flag.

=item C<requestee>

C<string> The login name of the user this flag has been requested to be granted or denied.
Note, this field is only returned if a requestee is set.

=back

1930 1931 1932 1933
=back

=item B<Errors>

1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945
This method can throw all the same errors as L</get>. In addition,
it can also throw the following error:

=over

=item 304 (Auth Failure, Attachment is Private)

You specified the id of a private attachment in the C<attachment_ids>
argument, and you are not in the "insider group" that can see
private attachments.

=back
1946 1947 1948 1949 1950 1951 1952

=item B<History>

=over

=item Added in Bugzilla B<3.6>.

1953 1954 1955
=item In Bugzilla B<4.0>, the C<attacher> return value was renamed to
C<creator>.

1956 1957 1958
=item In Bugzilla B<4.0>, the C<description> return value was renamed to
C<summary>.

1959 1960
=item The C<data> return value was added in Bugzilla B<4.0>.

1961 1962 1963
=item In Bugzilla B<4.2>, the C<is_url> return value was removed
(this attribute no longer exists for attachments).

1964
=item The C<size> return value was added in Bugzilla B<4.4>.
1965

1966 1967
=item The C<flags> array was added in Bugzilla B<4.4>.

1968 1969
=item REST API call added in Bugzilla B<5.0>.

1970 1971 1972 1973 1974
=back

=back


1975
=head2 comments
1976

1977
B<STABLE>
1978 1979 1980 1981 1982 1983 1984 1985

=over

=item B<Description>

This allows you to get data about comments, given a list of bugs 
and/or comment ids.

1986 1987 1988 1989
=item B<REST>

To get all comments for a particular bug using the bug ID or alias:

1990
GET /rest/bug/<id_or_alias>/comment
1991 1992 1993

To get a specific comment based on the comment ID:

1994
GET /rest/bug/comment/<comment_id>
1995 1996 1997

The returned data format is the same as below.

1998 1999
=item B<Params>

2000
B<Note>: At least one of C<ids> or C<comment_ids> is required.
2001 2002 2003 2004 2005 2006 2007

In addition to the parameters below, this method also accepts the
standard L<include_fields|Bugzilla::WebService/include_fields> and
L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.

=over

2008
=item C<ids>
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019

C<array> An array that can contain both bug IDs and bug aliases.
All of the comments (that are visible to you) will be returned for the
specified bugs.

=item C<comment_ids> 

C<array> An array of integer comment_ids. These comments will be
returned individually, separate from any other comments in their
respective bugs.

2020 2021 2022
=item C<new_since>

C<dateTime> If specified, the method will only return comments I<newer>
2023
than this time. This only affects comments returned from the C<ids>
2024 2025 2026
argument. You will always be returned all comments you request in the
C<comment_ids> argument, even if they are older than this date.

2027 2028 2029 2030 2031 2032 2033 2034 2035 2036
=back

=item B<Returns>

Two items are returned:

=over

=item C<bugs>

2037
This is used for bugs specified in C<ids>. This is a hash,
2038 2039 2040 2041 2042
where the keys are the numeric ids of the bugs, and the value is
a hash with a single key, C<comments>, which is an array of comments.
(The format of comments is described below.)

Note that any individual bug will only be returned once, so if you
2043
specify an id multiple times in C<ids>, it will still only be
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066
returned once.

=item C<comments>

Each individual comment requested in C<comment_ids> is returned here,
in a hash where the numeric comment id is the key, and the value
is the comment. (The format of comments is described below.) 

=back

A "comment" as described above is a hash that contains the following
keys:

=over

=item id

C<int> The globally unique ID for the comment.

=item bug_id

C<int> The ID of the bug that this comment is on.

2067 2068 2069 2070 2071
=item attachment_id

C<int> If the comment was made on an attachment, this will be the
ID of that attachment. Otherwise it will be null.

2072 2073 2074 2075 2076
=item count

C<int> The number of the comment local to the bug. The Description is 0,
comments start with 1.

2077 2078 2079 2080
=item text

C<string> The actual text of the comment.

2081
=item creator
2082 2083 2084 2085 2086 2087 2088

C<string> The login name of the comment's author.

=item time

C<dateTime> The time (in Bugzilla's timezone) that the comment was added.

2089 2090 2091 2092 2093 2094 2095
=item creation_time

C<dateTime> This is exactly same as the C<time> key. Use this field instead of
C<time> for consistency with other methods including L</get> and L</attachments>.
For compatibility, C<time> is still usable. However, please note that C<time>
may be deprecated and removed in a future release.

2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123
=item is_private

C<boolean> True if this comment is private (only visible to a certain
group called the "insidergroup"), False otherwise.

=back

=item B<Errors>

This method can throw all the same errors as L</get>. In addition,
it can also throw the following errors:

=over

=item 110 (Comment Is Private)

You specified the id of a private comment in the C<comment_ids>
argument, and you are not in the "insider group" that can see
private comments.

=item 111 (Invalid Comment ID)

You specified an id in the C<comment_ids> argument that is invalid--either
you specified something that wasn't a number, or there is no comment with
that id.

=back

2124 2125 2126 2127 2128 2129 2130 2131
=item B<History>

=over

=item Added in Bugzilla B<3.4>.

=item C<attachment_id> was added to the return value in Bugzilla B<3.6>.

2132 2133 2134
=item In Bugzilla B<4.0>, the C<author> return value was renamed to
C<creator>.

2135
=item C<count> was added to the return value in Bugzilla B<4.4>.
2136

2137 2138
=item C<creation_time> was added in Bugzilla B<4.4>.

2139 2140
=item REST API call added in Bugzilla B<5.0>.

2141 2142
=back

2143 2144 2145
=back


2146
=head2 get
2147

2148
B<STABLE>
2149 2150 2151 2152 2153 2154 2155

=over

=item B<Description>

Gets information about particular bugs in the database.

2156 2157 2158 2159
=item B<REST>

To get information about a particular bug using its ID or alias:

2160
GET /rest/bug/<id_or_alias>
2161 2162 2163

The returned data format is the same as below.

2164 2165
=item B<Params>

2166 2167 2168 2169
In addition to the parameters below, this method also accepts the
standard L<include_fields|Bugzilla::WebService/include_fields> and
L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.

2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180
=over

=item C<ids>

An array of numbers and strings.

If an element in the array is entirely numeric, it represents a bug_id
from the Bugzilla database to fetch. If it contains any non-numeric 
characters, it is considered to be a bug alias instead, and the bug with 
that alias will be loaded. 

2181
=item C<permissive> B<EXPERIMENTAL>
2182 2183 2184 2185 2186 2187 2188

C<boolean> Normally, if you request any inaccessible or invalid bug ids,
Bug.get will throw an error. If this parameter is True, instead of throwing an
error we return an array of hashes with a C<id>, C<faultString> and C<faultCode> 
for each bug that fails, and return normal information for the other bugs that 
were accessible.

2189 2190 2191 2192
=back

=item B<Returns>

2193 2194 2195 2196 2197 2198 2199 2200
Two items are returned:

=over

=item C<bugs>

An array of hashes that contains information about the bugs with 
the valid ids. Each hash contains the following items:
2201

2202 2203 2204
These fields are returned by default or by specifying C<_default>
in C<include_fields>.

2205 2206
=over

2207 2208 2209 2210 2211 2212 2213
=item C<actual_time>

C<double> The total number of hours that this bug has taken (so far).

If you are not in the time-tracking group, this field will not be included
in the return value.

2214
=item C<alias>
2215

2216 2217
C<array> of C<string>s The unique aliases of this bug. An empty array will be
returned if this bug has no aliases.
2218

2219
=item C<assigned_to>
2220

2221 2222
C<string> The login name of the user to whom the bug is assigned.

2223 2224 2225 2226 2227
=item C<assigned_to_detail> 

C<hash> A hash containing detailed user information for the assigned_to. To see the 
keys included in the user detail hash, see below.

2228 2229 2230 2231 2232 2233 2234 2235 2236
=item C<blocks>

C<array> of C<int>s. The ids of bugs that are "blocked" by this bug.

=item C<cc>

C<array> of C<string>s. The login names of users on the CC list of this
bug.

2237 2238 2239 2240 2241
=item C<cc_detail>

C<array> of hashes containing detailed user information for each of the cc list
members. To see the keys included in the user detail hash, see below.

2242 2243 2244 2245 2246
=item C<classification>

C<string> The name of the current classification the bug is in.

=item C<component>
2247 2248

C<string> The name of the current component of this bug.
2249

2250
=item C<creation_time>
2251 2252 2253

C<dateTime> When the bug was created.

2254 2255 2256 2257
=item C<creator>

C<string> The login name of the person who filed this bug (the reporter).

2258 2259 2260 2261 2262
=item C<creator_detail> 

C<hash> A hash containing detailed user information for the creator. To see the 
keys included in the user detail hash, see below.

2263 2264
=item C<deadline>

2265 2266
C<string> The day that this bug is due to be completed, in the format
C<YYYY-MM-DD>.
2267 2268 2269 2270 2271 2272

=item C<depends_on>

C<array> of C<int>s. The ids of bugs that this bug "depends on".

=item C<dupe_of>
2273

2274
C<int> The bug ID of the bug that this bug is a duplicate of. If this bug 
2275
isn't a duplicate of any bug, this will be null.
2276

2277
=item C<estimated_time>
2278

2279 2280 2281 2282 2283 2284
C<double> The number of hours that it was estimated that this bug would
take.

If you are not in the time-tracking group, this field will not be included
in the return value.

2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326
=item C<flags>

An array of hashes containing the information about flags currently set
for the bug. Each flag hash contains the following items:

=over

=item C<id> 

C<int> The id of the flag.

=item C<name>

C<string> The name of the flag.

=item C<type_id>

C<int> The type id of the flag.

=item C<creation_date>

C<dateTime> The timestamp when this flag was originally created.

=item C<modification_date>

C<dateTime> The timestamp when the flag was last modified.

=item C<status>

C<string> The current status of the flag.

=item C<setter>

C<string> The login name of the user who created or last modified the flag.

=item C<requestee>

C<string> The login name of the user this flag has been requested to be granted or denied.
Note, this field is only returned if a requestee is set.

=back

2327
=item C<groups>
2328

2329
C<array> of C<string>s. The names of all the groups that this bug is in.
2330

2331 2332 2333
=item C<id>

C<int> The unique numeric id of this bug.
2334

2335
=item C<is_cc_accessible>
2336

2337 2338
C<boolean> If true, this bug can be accessed by members of the CC list,
even if they are not in the groups the bug is restricted to.
2339

2340
=item C<is_confirmed>
2341

2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352
C<boolean> True if the bug has been confirmed. Usually this means that
the bug has at some point been moved out of the C<UNCONFIRMED> status
and into another open status.

=item C<is_open>

C<boolean> True if this bug is open, false if it is closed.

=item C<is_creator_accessible>

C<boolean> If true, this bug can be accessed by the creator (reporter)
2353
of the bug, even if they are not a member of the groups the bug
2354 2355 2356 2357 2358 2359 2360
is restricted to.

=item C<keywords>

C<array> of C<string>s. Each keyword that is on this bug.

=item C<last_change_time>
2361 2362 2363

C<dateTime> When the bug was last changed.

2364 2365 2366 2367 2368 2369 2370 2371 2372
=item C<op_sys>

C<string> The name of the operating system that the bug was filed against.

=item C<platform>

C<string> The name of the platform (hardware) that the bug was filed against.

=item C<priority>
2373 2374 2375

C<string> The priority of the bug.

2376
=item C<product>
2377 2378 2379

C<string> The name of the product this bug is in.

2380
=item C<qa_contact>
2381

2382
C<string> The login name of the current QA Contact on the bug.
2383

2384 2385 2386 2387 2388
=item C<qa_contact_detail>

C<hash> A hash containing detailed user information for the qa_contact. To see the
keys included in the user detail hash, see below.

2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408
=item C<remaining_time>

C<double> The number of hours of work remaining until work on this bug
is complete.

If you are not in the time-tracking group, this field will not be included
in the return value.

=item C<resolution>

C<string> The current resolution of the bug, or an empty string if the bug
is open.

=item C<see_also>

B<UNSTABLE>

C<array> of C<string>s. The URLs in the See Also field on the bug.

=item C<severity>
2409 2410 2411

C<string> The current severity of the bug.

2412
=item C<status>
2413 2414 2415

C<string> The current status of the bug.

2416
=item C<summary>
2417 2418 2419

C<string> The summary of this bug.

2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451
=item C<target_milestone>

C<string> The milestone that this bug is supposed to be fixed by, or for
closed bugs, the milestone that it was fixed for.

=item C<update_token>

C<string> The token that you would have to pass to the F<process_bug.cgi>
page in order to update this bug. This changes every time the bug is
updated.

This field is not returned to logged-out users.

=item C<url>

B<UNSTABLE>

C<string> A URL that demonstrates the problem described in
the bug, or is somehow related to the bug report.

=item C<version>

C<string> The version the bug was reported against.

=item C<whiteboard>

C<string> The value of the "status whiteboard" field on the bug.

=item I<custom fields>

Every custom field in this installation will also be included in the
return value. Most fields are returned as C<string>s. However, some
2452 2453 2454 2455 2456
field types have different return values.

Normally custom fields are returned by default similar to normal bug
fields or you can specify only custom fields by using C<_custom> in
C<include_fields>.
2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467

=over

=item Bug ID Fields - C<int>

=item Multiple-Selection Fields - C<array> of C<string>s.

=item Date/Time Fields - C<dateTime>

=back 

2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491
=item I<user detail hashes> 

Each user detail hash contains the following items:

=over

=item C<id>

C<int> The user id for this user.

=item C<real_name>

C<string> The 'real' name for this user, if any.

=item C<name>

C<string> The user's Bugzilla login.

=item C<email>

C<string> The user's email address. Currently this is the same value as the name.

=back

2492 2493
=back

2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505
These fields are returned only by specifying "_extra" or the field name in "include_fields".

=over

=item C<tags>

C<array> of C<string>s.  Each array item is a tag name.

Note that tags are personal to the currently logged in user.

=back

2506
=item C<faults> B<EXPERIMENTAL>
2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518

An array of hashes that contains invalid bug ids with error messages
returned for them. Each hash contains the following items:

=over

=item id

C<int> The numeric bug_id of this bug.

=item faultString 

2519
C<string> This will only be returned for invalid bugs if the C<permissive>
2520 2521 2522 2523 2524
argument was set when calling Bug.get, and it is an error indicating that 
the bug id was invalid.

=item faultCode

2525
C<int> This will only be returned for invalid bugs if the C<permissive>
2526 2527 2528 2529 2530 2531 2532
argument was set when calling Bug.get, and it is the error code for the 
invalid bug error.

=back

=back

2533 2534 2535 2536 2537 2538
=item B<Errors>

=over

=item 100 (Invalid Bug Alias)

2539
If you specified an alias and there is no bug with that alias.
2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550

=item 101 (Invalid Bug ID)

The bug_id you specified doesn't exist in the database.

=item 102 (Access Denied)

You do not have access to the bug_id you specified.

=back

2551 2552 2553 2554
=item B<History>

=over

2555
=item C<permissive> argument added to this method's params in Bugzilla B<3.4>.
2556 2557

=item The following properties were added to this method's return values
2558 2559 2560 2561
in Bugzilla B<3.4>:

=over

2562 2563 2564 2565
=item For C<bugs>

=over

2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583
=item assigned_to

=item component 

=item dupe_of

=item is_open

=item priority

=item product

=item resolution

=item severity

=item status

2584 2585 2586 2587 2588 2589
=back 

=item C<faults>

=back 

2590 2591 2592 2593 2594 2595 2596 2597
=item In Bugzilla B<4.0>, the following items were added to the C<bugs>
return value: C<blocks>, C<cc>, C<classification>, C<creator>,
C<deadline>, C<depends_on>, C<estimated_time>, C<is_cc_accessible>, 
C<is_confirmed>, C<is_creator_accessible>, C<groups>, C<keywords>,
C<op_sys>, C<platform>, C<qa_contact>, C<remaining_time>, C<see_also>,
C<target_milestone>, C<update_token>, C<url>, C<version>, C<whiteboard>,
and all custom fields.

2598
=item The C<flags> array was added in Bugzilla B<4.4>.
2599

2600 2601 2602
=item The C<actual_time> item was added to the C<bugs> return value
in Bugzilla B<4.4>.

2603 2604
=item REST API call added in Bugzilla B<5.0>.

2605 2606
=item In Bugzilla B<5.0>, the following items were added to the bugs return value: C<assigned_to_detail>, C<creator_detail>, C<qa_contact_detail>. 

2607
=back
2608

2609 2610
=back

2611
=head2 history
2612

2613
B<EXPERIMENTAL>
2614 2615 2616 2617 2618 2619 2620

=over

=item B<Description>

Gets the history of changes for particular bugs in the database.

2621 2622 2623 2624
=item B<REST>

To get the history for a specific bug ID:

2625
GET /rest/bug/<bug_id>/history
2626 2627 2628

The returned data format will be the same as below.

2629 2630 2631 2632 2633 2634 2635
=item B<Params>

=over

=item C<ids>

An array of numbers and strings.
2636

2637 2638 2639
If an element in the array is entirely numeric, it represents a bug_id 
from the Bugzilla database to fetch. If it contains any non-numeric 
characters, it is considered to be a bug alias instead, and the data bug 
2640 2641
with that alias will be loaded.

Frédéric Buclin's avatar
Frédéric Buclin committed
2642
=item C<new_since>
2643 2644 2645

C<dateTime> If specified, the method will only return changes I<newer>
than this time.
2646 2647 2648 2649 2650

=back

=item B<Returns>

2651 2652
A hash containing a single element, C<bugs>. This is an array of hashes,
containing the following keys:
2653 2654 2655

=over

2656 2657 2658 2659
=item id

C<int> The numeric id of the bug.

2660 2661
=item alias

2662 2663
C<array> of C<string>s The unique aliases of this bug. An empty array will be
returned if this bug has no aliases.
2664

2665 2666 2667 2668 2669 2670
=item history

C<array> An array of hashes, each hash having the following keys:

=over

2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709
=item when

C<dateTime> The date the bug activity/change happened.

=item who

C<string> The login name of the user who performed the bug change.

=item changes

C<array> An array of hashes which contain all the changes that happened
to the bug at this time (as specified by C<when>). Each hash contains 
the following items:

=over

=item field_name

C<string> The name of the bug field that has changed.

=item removed

C<string> The previous value of the bug field which has been deleted 
by the change.

=item added

C<string> The new value of the bug field which has been added by the change.

=item attachment_id

C<int> The id of the attachment that was changed. This only appears if 
the change was to an attachment, otherwise C<attachment_id> will not be
present in this hash.

=back

=back

2710 2711
=back

2712 2713 2714 2715
=item B<Errors>

The same as L</get>.

2716 2717 2718 2719 2720 2721
=item B<History>

=over

=item Added in Bugzilla B<3.4>.

2722 2723 2724
=item Field names returned by the C<field_name> field changed to be
consistent with other methods. Since Bugzilla B<4.4>, they now match
names used by L<Bug.update|/"update"> for consistency.
2725

2726 2727
=item REST API call added Bugzilla B<5.0>.

2728 2729
=item Added C<new_since> parameter if Bugzilla B<5.0>.

2730 2731 2732 2733
=back

=back

2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783
=head2 possible_duplicates

B<UNSTABLE>

=over

=item B<Description>

Allows a user to find possible duplicate bugs based on a set of keywords
such as a user may use as a bug summary. Optionally the search can be
narrowed down to specific products.

=item B<Params>

=over

=item C<summary> (string) B<Required> - A string of keywords defining
the type of bug you are trying to report.

=item C<products> (array) - One or more product names to narrow the
duplicate search to. If omitted, all bugs are searched.

=back

=item B<Returns>

The same as L</get>.

Note that you will only be returned information about bugs that you
can see. Bugs that you can't see will be entirely excluded from the
results. So, if you want to see private bugs, you will have to first 
log in and I<then> call this method.

=item B<Errors>

=over

=item 50 (Param Required)

You must specify a value for C<summary> containing a string of keywords to 
search for duplicates.

=back

=item B<History>

=over

=item Added in Bugzilla B<4.0>.

2784 2785 2786
=item The C<product> parameter has been renamed to C<products> in
Bugzilla B<5.0>.

2787 2788 2789
=back

=back
2790

2791
=head2 search
2792 2793 2794 2795 2796 2797 2798 2799 2800

B<UNSTABLE>

=over

=item B<Description>

Allows you to search for bugs based on particular criteria.

2801 2802 2803 2804 2805 2806 2807 2808
=item <REST>

To search for bugs:

GET /bug

The URL parameters and the returned data format are the same as below.

2809 2810
=item B<Params>

2811 2812 2813 2814 2815
Unless otherwise specified in the description of a parameter, bugs are
returned if they match I<exactly> the criteria you specify in these 
parameters. That is, we don't match against substrings--if a bug is in
the "Widgets" product and you ask for bugs in the "Widg" product, you
won't get anything.
2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828

Criteria are joined in a logical AND. That is, you will be returned
bugs that match I<all> of the criteria, not bugs that match I<any> of
the criteria.

Each parameter can be either the type it says, or an array of the types
it says. If you pass an array, it means "Give me bugs with I<any> of
these values." For example, if you wanted bugs that were in either
the "Foo" or "Bar" products, you'd pass:

 product => ['Foo', 'Bar']

Some Bugzillas may treat your arguments case-sensitively, depending
2829 2830
on what database system they are using. Most commonly, though, Bugzilla is
not case-sensitive with the arguments passed (because MySQL is the
2831 2832
most-common database to use with Bugzilla, and MySQL is not case sensitive).

2833 2834 2835 2836 2837 2838 2839 2840 2841
In addition to the fields listed below, you may also use criteria that
is similar to what is used in the Advanced Search screen of the Bugzilla
UI. This includes fields specified by C<Search by Change History> and
C<Custom Search>. The easiest way to determine what the field names are and what
format Bugzilla expects, is to first construct your query using the
Advanced Search UI, execute it and use the query parameters in they URL
as your key/value pairs for the WebService call. With REST, you can
just reuse the query parameter portion in the REST call itself.

2842 2843 2844 2845
=over

=item C<alias>

2846 2847
C<array> of C<string>s The unique aliases of this bug. An empty array will be
returned if this bug has no aliases.
2848 2849 2850 2851 2852 2853 2854 2855

=item C<assigned_to>

C<string> The login name of a user that a bug is assigned to.

=item C<component>

C<string> The name of the Component that the bug is in. Note that
timeless's avatar
timeless committed
2856
if there are multiple Components with the same name, and you search
2857 2858 2859 2860 2861
for that name, bugs in I<all> those Components will be returned. If you
don't want this, be sure to also specify the C<product> argument.

=item C<creation_time>

2862 2863
C<dateTime> Searches for bugs that were created at this time or later.
May not be an array.
2864

2865 2866 2867 2868
=item C<creator>

C<string> The login name of the user who created the bug.

2869 2870 2871
You can also pass this argument with the name C<reporter>, for
backwards compatibility with older Bugzillas.

2872 2873 2874 2875 2876 2877
=item C<id>

C<int> The numeric id of the bug.

=item C<last_change_time>

2878 2879
C<dateTime> Searches for bugs that were modified at this time or later.
May not be an array.
2880 2881 2882

=item C<limit>

2883 2884 2885 2886
C<int> Limit the number of results returned to C<int> records. If the limit
is more than zero and higher than the maximum limit set by the administrator,
then the maximum limit will be used instead. If you set the limit equal to zero,
then all matching results will be returned instead.
2887 2888 2889

=item C<offset>

2890 2891 2892
C<int> Used in conjunction with the C<limit> argument, C<offset> defines
the starting position for the search. For example, given a search that
would return 100 bugs, setting C<limit> to 10 and C<offset> to 10 would return
2893
bugs 11 through 20 from the set of 100.
2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926

=item C<op_sys>

C<string> The "Operating System" field of a bug.

=item C<platform>

C<string> The Platform (sometimes called "Hardware") field of a bug.

=item C<priority>

C<string> The Priority field on a bug.

=item C<product>

C<string> The name of the Product that the bug is in.

=item C<resolution>

C<string> The current resolution--only set if a bug is closed. You can
find open bugs by searching for bugs with an empty resolution.

=item C<severity>

C<string> The Severity field on a bug.

=item C<status>

C<string> The current status of a bug (not including its resolution,
if it has one, which is a separate field above).

=item C<summary>

2927 2928 2929 2930 2931 2932 2933 2934
C<string> Searches for substrings in the single-line Summary field on
bugs. If you specify an array, then bugs whose summaries match I<any> of the
passed substrings will be returned.

Note that unlike searching in the Bugzilla UI, substrings are not split
on spaces. So searching for C<foo bar> will match "This is a foo bar"
but not "This foo is a bar". C<['foo', 'bar']>, would, however, match
the second item.
2935

2936
=item C<tags>
2937 2938 2939 2940

C<string> Searches for a bug with the specified tag.  If you specify an
array, then any bugs that match I<any> of the tags will be returned.

2941
Note that tags are personal to the currently logged in user.
2942

2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967
=item C<target_milestone>

C<string> The Target Milestone field of a bug. Note that even if this
Bugzilla does not have the Target Milestone field enabled, you can
still search for bugs by Target Milestone. However, it is likely that
in that case, most bugs will not have a Target Milestone set (it
defaults to "---" when the field isn't enabled).

=item C<qa_contact>

C<string> The login name of the bug's QA Contact. Note that even if
this Bugzilla does not have the QA Contact field enabled, you can
still search for bugs by QA Contact (though it is likely that no bug
will have a QA Contact set, if the field is disabled).

=item C<url>

C<string> The "URL" field of a bug.

=item C<version>

C<string> The Version field of a bug.

=item C<whiteboard>

2968 2969 2970
C<string> Search the "Status Whiteboard" field on bugs for a substring.
Works the same as the C<summary> field described above, but searches the
Status Whiteboard field.
2971

2972 2973 2974 2975
=item C<quicksearch>

C<string> Search for bugs using quicksearch syntax.

2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988
=back

=item B<Returns>

The same as L</get>.

Note that you will only be returned information about bugs that you
can see. Bugs that you can't see will be entirely excluded from the
results. So, if you want to see private bugs, you will have to first 
log in and I<then> call this method.

=item B<Errors>

2989 2990 2991 2992 2993 2994 2995 2996 2997 2998
If you specify an invalid value for a particular field, you just won't
get any results for that value.

=over

=item 1000 (Parameters Required)

You may not search without any search terms.

=back
2999 3000 3001 3002 3003 3004 3005

=item B<History>

=over

=item Added in Bugzilla B<3.4>.

3006
=item Searching by C<votes> was removed in Bugzilla B<4.0>.
3007

3008 3009 3010
=item The C<reporter> input parameter was renamed to C<creator>
in Bugzilla B<4.0>.

3011 3012 3013 3014
=item In B<4.2.6> and newer, added the ability to return all results if
C<limit> is set equal to zero. Otherwise maximum results returned are limited
by system configuration.

3015 3016
=item REST API call added in Bugzilla B<5.0>.

3017
=item Updated to allow for full search capability similar to the Bugzilla UI
3018 3019
in Bugzilla B<5.0>.

3020 3021
=item Updated to allow quicksearch capability in Bugzilla B<5.0>.

3022 3023 3024 3025 3026
=back

=back


3027
=head1 Bug Creation and Modification
3028

3029
=head2 create
3030

3031
B<STABLE>
3032 3033 3034 3035 3036 3037

=over

=item B<Description>

This allows you to create a new bug in Bugzilla. If you specify any
3038 3039 3040
invalid fields, an error will be thrown stating which field is invalid.
If you specify any fields you are not allowed to set, they will just be
set to their defaults or ignored.
3041 3042 3043 3044 3045 3046 3047

You cannot currently set all the items here that you can set on enter_bug.cgi.

The WebService interface may allow you to set things other than those listed
here, but realize that anything undocumented is B<UNSTABLE> and will very
likely change in the future.

3048 3049 3050 3051
=item B<REST>

To create a new bug in Bugzilla:

3052
POST /rest/bug
3053 3054 3055 3056

The params to include in the POST body as well as the returned data format,
are the same as below.

3057 3058 3059
=item B<Params>

Some params must be set, or an error will be thrown. These params are
3060
marked B<Required>.
3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103

Some parameters can have defaults set in Bugzilla, by the administrator.
If these parameters have defaults set, you can omit them. These parameters
are marked B<Defaulted>.

Clients that want to be able to interact uniformly with multiple
Bugzillas should always set both the params marked B<Required> and those 
marked B<Defaulted>, because some Bugzillas may not have defaults set
for B<Defaulted> parameters, and then this method will throw an error
if you don't specify them.

The descriptions of the parameters below are what they mean when Bugzilla is
being used to track software bugs. They may have other meanings in some
installations.

=over

=item C<product> (string) B<Required> - The name of the product the bug
is being filed against.

=item C<component> (string) B<Required> - The name of a component in the
product above.

=item C<summary> (string) B<Required> - A brief description of the bug being
filed.

=item C<version> (string) B<Required> - A version of the product above;
the version the bug was found in.

=item C<description> (string) B<Defaulted> - The initial description for 
this bug. Some Bugzilla installations require this to not be blank.

=item C<op_sys> (string) B<Defaulted> - The operating system the bug was
discovered on.

=item C<platform> (string) B<Defaulted> - What type of hardware the bug was
experienced on.

=item C<priority> (string) B<Defaulted> - What order the bug will be fixed
in by the developer, compared to the developer's other bugs.

=item C<severity> (string) B<Defaulted> - How severe the bug is.

3104
=item C<alias> (array) - A brief alias for the bug that can be used
3105 3106 3107 3108 3109 3110 3111 3112
instead of a bug number when accessing this bug. Must be unique in
all of this Bugzilla.

=item C<assigned_to> (username) - A user to assign this bug to, if you
don't want it to be assigned to the component owner.

=item C<cc> (array) - An array of usernames to CC on this bug.

3113 3114 3115
=item C<comment_is_private> (boolean) - If set to true, the description
is private, otherwise it is assumed to be public.

3116 3117 3118
=item C<groups> (array) - An array of group names to put this
bug into. You can see valid group names on the Permissions
tab of the Preferences screen, or, if you are an administrator,
3119 3120
in the Groups control panel.
If you don't specify this argument, then the bug will be added into
3121 3122 3123
all the groups that are set as being "Default" for this product. (If
you want to avoid that, you should specify C<groups> as an empty array.)

3124 3125 3126 3127 3128 3129 3130
=item C<qa_contact> (username) - If this installation has QA Contacts
enabled, you can set the QA Contact here if you don't want to use
the component's default QA Contact.

=item C<status> (string) - The status that this bug should start out as.
Note that only certain statuses can be set on bug creation.

3131 3132 3133 3134 3135
=item C<resolution> (string) - If you are filing a closed bug, then
you will have to specify a resolution. You cannot currently specify
a resolution of C<DUPLICATE> for new bugs, though. That must be done
with L</update>.

3136 3137 3138
=item C<target_milestone> (string) - A valid target milestone for this
product.

3139 3140 3141 3142
=item C<flags>

C<array> An array of hashes with flags to add to the bug. To create a flag,
at least the status and the type_id or name must be provided. An optional
3143
requestee can be passed if the flag type is requestable to a specific user.
3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160

=over

=item C<name>

C<string> The name of the flag type.

=item C<type_id>

C<int> The internal flag type id.

=item C<status>

C<string> The flags new status (i.e. "?", "+", "-" or "X" to clear a flag).

=item C<requestee>

3161
C<string> The login of the requestee if the flag type is requestable to a specific user.
3162 3163 3164

=back

3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178
=back

In addition to the above parameters, if your installation has any custom
fields, you can set them just by passing in the name of the field and
its value as a string.

=item B<Returns>

A hash with one element, C<id>. This is the id of the newly-filed bug.

=item B<Errors>

=over

3179 3180
=item 51 (Invalid Object)

3181 3182
You specified a field value that is invalid. The error message will have
more details.
3183

3184 3185 3186 3187 3188 3189 3190
=item 103 (Invalid Alias)

The alias you specified is invalid for some reason. See the error message
for more details.

=item 104 (Invalid Field)

3191 3192
One of the drop-down fields has an invalid value, or a value entered in a
text field is too long. The error message will have more detail.
3193 3194 3195

=item 105 (Invalid Component)

3196
You didn't specify a component.
3197 3198 3199 3200 3201 3202 3203 3204 3205 3206

=item 106 (Invalid Product)

Either you didn't specify a product, this product doesn't exist, or
you don't have permission to enter bugs in this product.

=item 107 (Invalid Summary)

You didn't specify a summary for the bug.

3207 3208 3209 3210 3211
=item 116 (Dependency Loop)

You specified values in the C<blocks> or C<depends_on> fields
that would cause a circular dependency between bugs.

3212 3213 3214 3215 3216
=item 120 (Group Restriction Denied)

You tried to restrict the bug to a group which does not exist, or which
you cannot use with this product.

3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238
=item 129 (Flag Status Invalid)

The flag status is invalid.

=item 130 (Flag Modification Denied)

You tried to request, grant, or deny a flag but only a user with the required
permissions may make the change.

=item 131 (Flag not Requestable from Specific Person)

You can't ask a specific person for the flag.

=item 133 (Flag Type not Unique)

The flag type specified matches several flag types. You must specify
the type id value to update or add a flag.

=item 134 (Inactive Flag Type)

The flag type is inactive and cannot be used to create new flags.

3239 3240 3241 3242 3243 3244 3245
=item 504 (Invalid User)

Either the QA Contact, Assignee, or CC lists have some invalid user
in them. The error message will have more details.

=back

3246 3247 3248 3249 3250 3251 3252
=item B<History>

=over

=item Before B<3.0.4>, parameters marked as B<Defaulted> were actually
B<Required>, due to a bug in Bugzilla.

3253 3254
=item The C<groups> argument was added in Bugzilla B<4.0>. Before
Bugzilla 4.0, bugs were only added into Mandatory groups by this
3255 3256 3257
method. Since Bugzilla B<4.0.2>, passing an illegal group name will
throw an error. In Bugzilla 4.0 and 4.0.1, illegal group names were
silently ignored.
3258

3259 3260 3261 3262
=item The C<comment_is_private> argument was added in Bugzilla B<4.0>.
Before Bugzilla 4.0, you had to use the undocumented C<commentprivacy>
argument.

3263 3264 3265
=item Error 116 was added in Bugzilla B<4.0>. Before that, dependency
loop errors had a generic code of C<32000>.

3266
=item The ability to file new bugs with a C<resolution> was added in
3267
Bugzilla B<4.4>.
3268

3269 3270
=item REST API call added in Bugzilla B<5.0>.

3271 3272
=back

3273 3274
=back

3275

3276
=head2 add_attachment
3277

3278
B<STABLE>
3279 3280 3281 3282 3283 3284 3285

=over

=item B<Description>

This allows you to add an attachment to a bug in Bugzilla.

3286 3287 3288 3289
=item B<REST>

To create attachment on a current bug:

3290
POST /rest/bug/<bug_id>/attachment
3291 3292 3293 3294 3295

The params to include in the POST body, as well as the returned
data format are the same as below. The C<ids> param will be
overridden as it it pulled from the URL path.

3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308
=item B<Params>

=over

=item C<ids>

B<Required> C<array> An array of ints and/or strings--the ids
or aliases of bugs that you want to add this attachment to.
The same attachment and comment will be added to all
these bugs.

=item C<data>

3309 3310 3311
B<Required> C<base64> or C<string> The content of the attachment.
If the content of the attachment is not ASCII text, you must encode
it in base64 and declare it as the C<base64> type.
3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329

=item C<file_name>

B<Required> C<string> The "file name" that will be displayed
in the UI for this attachment.

=item C<summary>

B<Required> C<string> A short string describing the
attachment.

=item C<content_type>

B<Required> C<string> The MIME type of the attachment, like
C<text/plain> or C<image/png>.

=item C<comment>

3330
C<string> A comment to add along with this attachment.
3331 3332 3333 3334

=item C<is_patch>

C<boolean> True if Bugzilla should treat this attachment as a patch.
3335
If you specify this, you do not need to specify a C<content_type>.
3336
The C<content_type> of the attachment will be forced to C<text/plain>.
3337 3338 3339 3340 3341 3342 3343 3344 3345 3346

Defaults to False if not specified.

=item C<is_private>

C<boolean> True if the attachment should be private (restricted
to the "insidergroup"), False if the attachment should be public.

Defaults to False if not specified.

3347 3348 3349 3350
=item C<flags>

C<array> An array of hashes with flags to add to the attachment. to create a flag,
at least the status and the type_id or name must be provided. An optional requestee
3351
can be passed if the flag type is requestable to a specific user.
3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368

=over

=item C<name>

C<string> The name of the flag type.

=item C<type_id>

C<int> The internal flag type id.

=item C<status>

C<string> The flags new status (i.e. "?", "+", "-" or "X" to clear a flag).

=item C<requestee>

3369
C<string> The login of the requestee if the flag type is requestable to a specific user.
3370 3371 3372

=back

3373 3374 3375 3376
=back

=item B<Returns>

3377 3378
A single item C<ids>, which contains an array of the
attachment id(s) created.
3379 3380 3381 3382 3383 3384 3385

=item B<Errors>

This method can throw all the same errors as L</get>, plus:

=over

3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407
=item 129 (Flag Status Invalid)

The flag status is invalid.

=item 130 (Flag Modification Denied)

You tried to request, grant, or deny a flag but only a user with the required
permissions may make the change.

=item 131 (Flag not Requestable from Specific Person)

You can't ask a specific person for the flag.

=item 133 (Flag Type not Unique)

The flag type specified matches several flag types. You must specify
the type id value to update or add a flag.

=item 134 (Inactive Flag Type)

The flag type is inactive and cannot be used to create new flags.

3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424
=item 600 (Attachment Too Large)

You tried to attach a file that was larger than Bugzilla will accept.

=item 601 (Invalid MIME Type)

You specified a C<content_type> argument that was blank, not a valid
MIME type, or not a MIME type that Bugzilla accepts for attachments.

=item 603 (File Name Not Specified)

You did not specify a valid for the C<file_name> argument.

=item 604 (Summary Required)

You did not specify a value for the C<summary> argument.

3425 3426 3427 3428
=item 606 (Empty Data)

You set the "data" field to an empty string.

3429 3430 3431 3432 3433 3434 3435
=back

=item B<History>

=over

=item Added in Bugzilla B<4.0>.
3436

3437
=item The C<is_url> parameter was removed in Bugzilla B<4.2>.
3438

3439 3440
=item The return value has changed in Bugzilla B<4.4>.

3441 3442
=item REST API call added in Bugzilla B<5.0>.

3443 3444 3445 3446 3447
=back

=back


3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461
=head2 update_attachment

B<UNSTABLE>

=over

=item B<Description>

This allows you to update attachment metadata in Bugzilla.

=item B<REST>

To update attachment metadata on a current attachment:

3462
PUT /rest/bug/attachment/<attach_id>
3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486

The params to include in the POST body, as well as the returned
data format are the same as below. The C<ids> param will be
overridden as it it pulled from the URL path.

=item B<Params>

=over

=item C<ids>

B<Required> C<array> An array of integers -- the ids of the attachments you
want to update.

=item C<file_name>

C<string> The "file name" that will be displayed
in the UI for this attachment.

=item C<summary>

C<string> A short string describing the
attachment.

3487 3488
=item C<comment>

3489
C<string> An optional comment to add to the attachment's bug.
3490

3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510
=item C<content_type>

C<string> The MIME type of the attachment, like
C<text/plain> or C<image/png>.

=item C<is_patch>

C<boolean> True if Bugzilla should treat this attachment as a patch.
If you specify this, you do not need to specify a C<content_type>.
The C<content_type> of the attachment will be forced to C<text/plain>.

=item C<is_private>

C<boolean> True if the attachment should be private (restricted
to the "insidergroup"), False if the attachment should be public.

=item C<is_obsolete>

C<boolean> True if the attachment is obsolete, False otherwise.

3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534
=item C<flags>

C<array> An array of hashes with changes to the flags. The following values
can be specified. At least the status and one of type_id, id, or name must
be specified. If a type_id or name matches a single currently set flag,
the flag will be updated unless new is specified.

=over

=item C<name>

C<string> The name of the flag that will be created or updated.

=item C<type_id>

C<int> The internal flag type id that will be created or updated. You will
need to specify the C<type_id> if more than one flag type of the same name exists.

=item C<status>

C<string> The flags new status (i.e. "?", "+", "-" or "X" to clear a flag).

=item C<requestee>

3535
C<string> The login of the requestee if the flag type is requestable to a specific user.
3536 3537 3538 3539 3540 3541 3542 3543 3544 3545

=item C<id>

C<int> Use id to specify the flag to be updated. You will need to specify the C<id>
if more than one flag is set of the same name.

=item C<new>

C<boolean> Set to true if you specifically want a new flag to be created.

3546 3547 3548 3549
=back

=item B<Returns>

3550
A C<hash> with a single field, "attachments". This points to an array of hashes
3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610
with the following fields:

=over

=item C<id>

C<int> The id of the attachment that was updated.

=item C<last_change_time>

C<dateTime> The exact time that this update was done at, for this attachment.
If no update was done (that is, no fields had their values changed and
no comment was added) then this will instead be the last time the attachment
was updated.

=item C<changes>

C<hash> The changes that were actually done on this bug. The keys are
the names of the fields that were changed, and the values are a hash
with two keys:

=over

=item C<added> (C<string>) The values that were added to this field.
possibly a comma-and-space-separated list if multiple values were added.

=item C<removed> (C<string>) The values that were removed from this
field.

=back

=back

Here's an example of what a return value might look like:

 {
   attachments => [
     {
       id    => 123,
       last_change_time => '2010-01-01T12:34:56',
       changes => {
         summary => {
           removed => 'Sample ptach',
           added   => 'Sample patch'
         },
         is_obsolete => {
           removed => '0',
           added   => '1',
         }
       },
     }
   ]
 }

=item B<Errors>

This method can throw all the same errors as L</get>, plus:

=over

3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637
=item 129 (Flag Status Invalid)

The flag status is invalid.

=item 130 (Flag Modification Denied)

You tried to request, grant, or deny a flag but only a user with the required
permissions may make the change.

=item 131 (Flag not Requestable from Specific Person)

You can't ask a specific person for the flag.

=item 132 (Flag not Unique)

The flag specified has been set multiple times. You must specify the id
value to update the flag.

=item 133 (Flag Type not Unique)

The flag type specified matches several flag types. You must specify
the type id value to update or add a flag.

=item 134 (Inactive Flag Type)

The flag type is inactive and cannot be used to create new flags.

3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662
=item 601 (Invalid MIME Type)

You specified a C<content_type> argument that was blank, not a valid
MIME type, or not a MIME type that Bugzilla accepts for attachments.

=item 603 (File Name Not Specified)

You did not specify a valid for the C<file_name> argument.

=item 604 (Summary Required)

You did not specify a value for the C<summary> argument.

=back

=item B<History>

=over

=item Added in Bugzilla B<5.0>.

=back

=back

3663
=back
3664

3665
=head2 add_comment
3666

3667
B<STABLE>
3668 3669 3670 3671 3672 3673 3674

=over

=item B<Description>

This allows you to add a comment to a bug in Bugzilla.

3675 3676 3677 3678
=item B<REST>

To create a comment on a current bug:

3679
POST /rest/bug/<bug_id>/comment
3680 3681 3682 3683

The params to include in the POST body as well as the returned data format,
are the same as below.

3684 3685 3686 3687
=item B<Params>

=over

3688
=item C<id> (int or string) B<Required> - The id or alias of the bug to append a 
3689 3690 3691
comment to.

=item C<comment> (string) B<Required> - The comment to append to the bug.
3692 3693
If this is empty or all whitespace, an error will be thrown saying that
you did not set the C<comment> parameter.
3694

3695 3696
=item C<is_private> (boolean) - If set to true, the comment is private, 
otherwise it is assumed to be public.
3697 3698 3699 3700 3701 3702 3703 3704

=item C<work_time> (double) - Adds this many hours to the "Hours Worked"
on the bug. If you are not in the time tracking group, this value will
be ignored.


=back

3705 3706 3707 3708
=item B<Returns>

A hash with one element, C<id> whose value is the id of the newly-created comment.

3709 3710 3711 3712
=item B<Errors>

=over

3713 3714 3715 3716 3717
=item 54 (Hours Worked Too Large)

You specified a C<work_time> larger than the maximum allowed value of
C<99999.99>.

3718 3719
=item 100 (Invalid Bug Alias) 

3720
If you specified an alias and there is no bug with that alias.
3721 3722 3723 3724 3725

=item 101 (Invalid Bug ID)

The id you specified doesn't exist in the database.

3726
=item 109 (Bug Edit Denied)
3727 3728 3729

You did not have the necessary rights to edit the bug.

3730 3731 3732 3733
=item 113 (Can't Make Private Comments)

You tried to add a private comment, but don't have the necessary rights.

3734 3735 3736 3737 3738
=item 114 (Comment Too Long)

You tried to add a comment longer than the maximum allowed length
(65,535 characters).

3739 3740
=back

3741 3742 3743 3744 3745 3746
=item B<History>

=over

=item Added in Bugzilla B<3.2>.

3747 3748
=item Modified to return the new comment's id in Bugzilla B<3.4>

3749 3750 3751
=item Modified to throw an error if you try to add a private comment
but can't, in Bugzilla B<3.4>.

3752 3753 3754 3755
=item Before Bugzilla B<3.6>, the C<is_private> argument was called
C<private>, and you can still call it C<private> for backwards-compatibility
purposes if you wish.

3756 3757 3758
=item Before Bugzilla B<3.6>, error 54 and error 114 had a generic error
code of 32000.

3759 3760
=item REST API call added in Bugzilla B<5.0>.

3761 3762
=back

3763 3764
=back

3765

3766
=head2 update
3767 3768 3769 3770 3771 3772 3773 3774 3775 3776

B<UNSTABLE>

=over

=item B<Description>

Allows you to update the fields of a bug. Automatically sends emails
out about the changes.

3777 3778 3779 3780
=item B<REST>

To update the fields of a current bug:

3781
PUT /rest/bug/<bug_id>
3782 3783 3784 3785 3786

The params to include in the PUT body as well as the returned data format,
are the same as below. The C<ids> param will be overridden as it is
pulled from the URL path.

3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804
=item B<Params>

=over

=item C<ids>

Array of C<int>s or C<string>s. The ids or aliases of the bugs that
you want to modify.

=back

B<Note>: All following fields specify the values you want to set on the
bugs you are updating.

=over

=item C<alias>

3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827
C<hash> These specify the aliases of a bug that can be used instead of a bug
number when acessing this bug. To set these, you should pass a hash as the
value. The hash may contain the following fields:

=over

=item C<add> An array of C<string>s. Aliases to add to this field.

=item C<remove> An array of C<string>s. Aliases to remove from this field.
If the aliases are not already in the field, they will be ignored.

=item C<set> An array of C<string>s. An exact set of aliases to set this
field to, overriding the current value. If you specify C<set>, then C<add>
and  C<remove> will be ignored.

=back

You can only set this if you are modifying a single bug. If there is more
than one bug specified in C<ids>, passing in a value for C<alias> will cause
an error to be thrown.

For backwards compatibility, you can also specify a single string. This will
be treated as if you specified the set key above.
3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870

=item C<assigned_to>

C<string> The full login name of the user this bug is assigned to.

=item C<blocks>

=item C<depends_on>

C<hash> These specify the bugs that this bug blocks or depends on,
respectively. To set these, you should pass a hash as the value. The hash
may contain the following fields:

=over

=item C<add> An array of C<int>s. Bug ids to add to this field.

=item C<remove> An array of C<int>s. Bug ids to remove from this field.
If the bug ids are not already in the field, they will be ignored.

=item C<set> An array of C<int>s. An exact set of bug ids to set this
field to, overriding the current value. If you specify C<set>, then C<add>
and  C<remove> will be ignored.

=back

=item C<cc>

C<hash> The users on the cc list. To modify this field, pass a hash, which
may have the following fields:

=over

=item C<add> Array of C<string>s. User names to add to the CC list.
They must be full user names, and an error will be thrown if you pass
in an invalid user name.

=item C<remove> Array of C<string>s. User names to remove from the CC
list. They must be full user names, and an error will be thrown if you
pass in an invalid user name.

=back

3871
=item C<is_cc_accessible>
3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909

C<boolean> Whether or not users in the CC list are allowed to access
the bug, even if they aren't in a group that can normally access the bug.

=item C<comment>

C<hash>. A comment on the change. The hash may contain the following fields:

=over

=item C<body> C<string> The actual text of the comment.
B<Note>: For compatibility with the parameters to L</add_comment>,
you can also call this field C<comment>, if you want.

=item C<is_private> C<boolean> Whether the comment is private or not.
If you try to make a comment private and you don't have the permission
to, an error will be thrown.

=back

=item C<comment_is_private>

C<hash> This is how you update the privacy of comments that are already
on a bug. This is a hash, where the keys are the C<int> id of comments (not
their count on a bug, like #1, #2, #3, but their globally-unique id,
as returned by L</comments>) and the value is a C<boolean> which specifies
whether that comment should become private (C<true>) or public (C<false>).

The comment ids must be valid for the bug being updated. Thus, it is not
practical to use this while updating multiple bugs at once, as a single
comment id will never be valid on multiple bugs.

=item C<component>

C<string> The Component the bug is in.

=item C<deadline>

3910 3911
C<string> The Deadline field--a date specifying when the bug must
be completed by, in the format C<YYYY-MM-DD>.
3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925

=item C<dupe_of>

C<int> The bug that this bug is a duplicate of. If you want to mark
a bug as a duplicate, the safest thing to do is to set this value
and I<not> set the C<status> or C<resolution> fields. They will
automatically be set by Bugzilla to the appropriate values for
duplicate bugs.

=item C<estimated_time>

C<double> The total estimate of time required to fix the bug, in hours.
This is the I<total> estimate, not the amount of time remaining to fix it.

3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949
=item C<flags>

C<array> An array of hashes with changes to the flags. The following values
can be specified. At least the status and one of type_id, id, or name must
be specified. If a type_id or name matches a single currently set flag,
the flag will be updated unless new is specified.

=over

=item C<name>

C<string> The name of the flag that will be created or updated.

=item C<type_id>

C<int> The internal flag type id that will be created or updated. You will
need to specify the C<type_id> if more than one flag type of the same name exists.

=item C<status>

C<string> The flags new status (i.e. "?", "+", "-" or "X" to clear a flag).

=item C<requestee>

3950
C<string> The login of the requestee if the flag type is requestable to a specific user.
3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962

=item C<id>

C<int> Use id to specify the flag to be updated. You will need to specify the C<id>
if more than one flag is set of the same name.

=item C<new>

C<boolean> Set to true if you specifically want a new flag to be created.

=back

3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036
=item C<groups>

C<hash> The groups a bug is in. To modify this field, pass a hash, which
may have the following fields:

=over

=item C<add> Array of C<string>s. The names of groups to add. Passing
in an invalid group name or a group that you cannot add to this bug will
cause an error to be thrown.

=item C<remove> Array of C<string>s. The names of groups to remove. Passing
in an invalid group name or a group that you cannot remove from this bug
will cause an error to be thrown.

=back

=item C<keywords>

C<hash> Keywords on the bug. To modify this field, pass a hash, which
may have the following fields:

=over

=item C<add> An array of C<strings>s. The names of keywords to add to
the field on the bug. Passing something that isn't a valid keyword name
will cause an error to be thrown. 

=item C<remove> An array of C<string>s. The names of keywords to remove
from the field on the bug. Passing something that isn't a valid keyword
name will cause an error to be thrown.

=item C<set> An array of C<strings>s. An exact set of keywords to set the
field to, on the bug. Passing something that isn't a valid keyword name
will cause an error to be thrown. Specifying C<set> overrides C<add> and
C<remove>.

=back

=item C<op_sys>

C<string> The Operating System ("OS") field on the bug.

=item C<platform>

C<string> The Platform or "Hardware" field on the bug.

=item C<priority>

C<string> The Priority field on the bug.

=item C<product>

C<string> The name of the product that the bug is in. If you change
this, you will probably also want to change C<target_milestone>,
C<version>, and C<component>, since those have different legal
values in every product. 

If you cannot change the C<target_milestone> field, it will be reset to
the default for the product, when you move a bug to a new product.

You may also wish to add or remove groups, as which groups are
valid on a bug depends on the product. Groups that are not valid
in the new product will be automatically removed, and groups which
are mandatory in the new product will be automaticaly added, but no
other automatic group changes will be done.

Note that users can only move a bug into a product if they would
normally have permission to file new bugs in that product.

=item C<qa_contact>

C<string> The full login name of the bug's QA Contact.

4037
=item C<is_creator_accessible>
4038 4039

C<boolean> Whether or not the bug's reporter is allowed to access
4040
the bug, even if they aren't in a group that can normally access
4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145
the bug.

=item C<remaining_time>

C<double> How much work time is remaining to fix the bug, in hours.
If you set C<work_time> but don't explicitly set C<remaining_time>,
then the C<work_time> will be deducted from the bug's C<remaining_time>.

=item C<reset_assigned_to>

C<boolean> If true, the C<assigned_to> field will be reset to the
default for the component that the bug is in. (If you have set the
component at the same time as using this, then the component used
will be the new component, not the old one.)

=item C<reset_qa_contact>

C<boolean> If true, the C<qa_contact> field will be reset  to the
default for the component that the bug is in. (If you have set the
component at the same time as using this, then the component used
will be the new component, not the old one.)

=item C<resolution>

C<string> The current resolution. May only be set if you are closing
a bug or if you are modifying an already-closed bug. Attempting to set
the resolution to I<any> value (even an empty or null string) on an
open bug will cause an error to be thrown.

If you change the C<status> field to an open status, the resolution
field will automatically be cleared, so you don't have to clear it
manually.

=item C<see_also>

C<hash> The See Also field on a bug, specifying URLs to bugs in other
bug trackers. To modify this field, pass a hash, which may have the
following fields:

=over

=item C<add> An array of C<strings>s. URLs to add to the field.
Each URL must be a valid URL to a bug-tracker, or an error will
be thrown.

=item C<remove> An array of C<string>s. URLs to remove from the field.
Invalid URLs will be ignored.

=back

=item C<severity>

C<string> The Severity field of a bug.

=item C<status>

C<string> The status you want to change the bug to. Note that if
a bug is changing from open to closed, you should also specify
a C<resolution>.

=item C<summary>

C<string> The Summary field of the bug.

=item C<target_milestone>

C<string> The bug's Target Milestone.

=item C<url>

C<string> The "URL" field of a bug.

=item C<version>

C<string> The bug's Version field.

=item C<whiteboard>

C<string> The Status Whiteboard field of a bug.

=item C<work_time>

C<double> The number of hours worked on this bug as part of this change.
If you set C<work_time> but don't explicitly set C<remaining_time>,
then the C<work_time> will be deducted from the bug's C<remaining_time>.

=back

You can also set the value of any custom field by passing its name as
a parameter, and the value to set the field to. For multiple-selection
fields, the value should be an array of strings.

=item B<Returns>

A C<hash> with a single field, "bugs". This points to an array of hashes
with the following fields:

=over

=item C<id>

C<int> The id of the bug that was updated.

=item C<alias>

4146 4147
C<array> of C<string>s The aliases of the bug that was updated, if this bug
has any alias.
4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180

=item C<last_change_time>

C<dateTime> The exact time that this update was done at, for this bug.
If no update was done (that is, no fields had their values changed and
no comment was added) then this will instead be the last time the bug
was updated.

=item C<changes>

C<hash> The changes that were actually done on this bug. The keys are
the names of the fields that were changed, and the values are a hash
with two keys:

=over

=item C<added> (C<string>) The values that were added to this field,
possibly a comma-and-space-separated list if multiple values were added.

=item C<removed> (C<string>) The values that were removed from this
field, possibly a comma-and-space-separated list if multiple values were
removed.

=back

=back

Here's an example of what a return value might look like:

 { 
   bugs => [
     {
       id    => 123,
4181
       alias => [ 'foo' ],
4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196
       last_change_time => '2010-01-01T12:34:56',
       changes => {
         status => {
           removed => 'NEW',
           added   => 'ASSIGNED'
         },
         keywords => {
           removed => 'bar',
           added   => 'qux, quo, qui', 
         }
       },
     }
   ]
 }

4197 4198 4199 4200 4201
Currently, some fields are not tracked in changes: C<comment>,
C<comment_is_private>, and C<work_time>. This means that they will not
show up in the return value even if they were successfully updated.
This may change in a future version of Bugzilla.

4202 4203
=item B<Errors>

4204 4205
This function can throw all of the errors that L</get>, L</create>,
and L</add_comment> can throw, plus:
4206 4207 4208

=over

4209
=item 50 (Empty Field)
4210

4211 4212
You tried to set some field to be empty, but that field cannot be empty.
The error message will have more details.
4213

4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240
=item 52 (Input Not A Number)

You tried to set a numeric field to a value that wasn't numeric.

=item 54 (Number Too Large)

You tried to set a numeric field to a value larger than that field can
accept.

=item 55 (Number Too Small)

You tried to set a negative value in a numeric field that does not accept
negative values.

=item 56 (Bad Date/Time)

You specified an invalid date or time in a date/time field (such as
the C<deadline> field or a custom date/time field).

=item 112 (See Also Invalid)

You attempted to add an invalid value to the C<see_also> field.

=item 115 (Permission Denied)

You don't have permission to change a particular field to a particular value.
The error message will have more detail.
4241

4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280
=item 116 (Dependency Loop)

You specified a value in the C<blocks> or C<depends_on> fields that causes
a dependency loop.

=item 117 (Invalid Comment ID)

You specified a comment id in C<comment_is_private> that isn't on this bug.

=item 118 (Duplicate Loop)

You specified a value for C<dupe_of> that causes an infinite loop of
duplicates.

=item 119 (dupe_of Required)

You changed the resolution to C<DUPLICATE> but did not specify a value
for the C<dupe_of> field.

=item 120 (Group Add/Remove Denied)

You tried to add or remove a group that you don't have permission to modify
for this bug, or you tried to add a group that isn't valid in this product.

=item 121 (Resolution Required)

You tried to set the C<status> field to a closed status, but you didn't
specify a resolution.

=item 122 (Resolution On Open Status)

This bug has an open status, but you specified a value for the C<resolution>
field.

=item 123 (Invalid Status Transition)

You tried to change from one status to another, but the status workflow
rules don't allow that change.

4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307
=item 129 (Flag Status Invalid)

The flag status is invalid.

=item 130 (Flag Modification Denied)

You tried to request, grant, or deny a flag but only a user with the required
permissions may make the change.

=item 131 (Flag not Requestable from Specific Person)

You can't ask a specific person for the flag.

=item 132 (Flag not Unique)

The flag specified has been set multiple times. You must specify the id
value to update the flag.

=item 133 (Flag Type not Unique)

The flag type specified matches several flag types. You must specify
the type id value to update or add a flag.

=item 134 (Inactive Flag Type)

The flag type is inactive and cannot be used to create new flags.

4308
=back
4309 4310 4311 4312 4313 4314 4315

=item B<History>

=over

=item Added in Bugzilla B<4.0>.

4316 4317
=item REST API call added Bugzilla B<5.0>.

4318 4319 4320 4321 4322
=back

=back


4323
=head2 update_see_also
4324

4325
B<EXPERIMENTAL>
4326 4327 4328 4329 4330 4331

=over

=item B<Description>

Adds or removes URLs for the "See Also" field on bugs. These URLs must
4332
point to some valid bug in some Bugzilla installation or in Launchpad.
4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345

=item B<Params>

=over

=item C<ids>

Array of C<int>s or C<string>s. The ids or aliases of bugs that you want
to modify.

=item C<add>

Array of C<string>s. URLs to Bugzilla bugs. These URLs will be added to
4346 4347 4348 4349 4350
the See Also field. They must be valid URLs to C<show_bug.cgi> in a
Bugzilla installation or to a bug filed at launchpad.net.

If the URLs don't start with C<http://> or C<https://>, it will be assumed
that C<http://> should be added to the beginning of the string.
4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383

It is safe to specify URLs that are already in the "See Also" field on
a bug--they will just be silently ignored.

=item C<remove>

Array of C<string>s. These URLs will be removed from the See Also field.
You must specify the full URL that you want removed. However, matching
is done case-insensitively, so you don't have to specify the URL in
exact case, if you don't want to.

If you specify a URL that is not in the See Also field of a particular bug,
it will just be silently ignored. Invaild URLs are currently silently ignored,
though this may change in some future version of Bugzilla.

=back

NOTE: If you specify the same URL in both C<add> and C<remove>, it will
be I<added>. (That is, C<add> overrides C<remove>.)

=item B<Returns>

C<changes>, a hash where the keys are numeric bug ids and the contents
are a hash with one key, C<see_also>. C<see_also> points to a hash, which
contains two keys, C<added> and C<removed>. These are arrays of strings,
representing the actual changes that were made to the bug.

Here's a diagram of what the return value looks like for updating
bug ids 1 and 2:

 {
   changes => {
       1 => {
4384 4385 4386 4387
           see_also => {
               added   => (an array of bug URLs),
               removed => (an array of bug URLs),
           }
4388 4389
       },
       2 => {
4390 4391 4392 4393
           see_also => {
               added   => (an array of bug URLs),
               removed => (an array of bug URLs),
           }
4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407
       }
   }
 }

This return value allows you to tell what this method actually did. It is in
this format to be compatible with the return value of a future C<Bug.update>
method.

=item B<Errors>

This method can throw all of the errors that L</get> throws, plus:

=over

4408
=item 109 (Bug Edit Denied)
4409 4410 4411 4412 4413 4414 4415

You did not have the necessary rights to edit the bug.

=item 112 (Invalid Bug URL)

One of the URLs you provided did not look like a valid bug URL.

4416 4417 4418 4419 4420
=item 115 (See Also Edit Denied)

You did not have the necessary rights to edit the See Also field for
this bug.

4421 4422 4423 4424 4425 4426 4427 4428
=back

=item B<History>

=over

=item Added in Bugzilla B<3.4>.

4429 4430
=item Before Bugzilla B<3.6>, error 115 had a generic error code of 32000.

4431 4432 4433
=back

=back
4434 4435 4436 4437 4438 4439


=head2 update_tags

B<UNSTABLE>

Tiago Mello's avatar
Tiago Mello committed
4440 4441
=over

4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476
=item B<Description>

Adds or removes tags on bugs.

=item B<Params>

=over

=item C<ids>

B<Required> C<array> An array of ints and/or strings--the ids
or aliases of bugs that you want to add or remove tags to. All the tags
will be added or removed to all these bugs.

=item C<tags>

B<Required> C<hash> A hash representing tags to be added and/or removed.
The hash has the following fields:

=over

=item C<add> An array of C<string>s representing tag names
to be added to the bugs.

It is safe to specify tags that are already associated with the 
bugs--they will just be silently ignored.

=item C<remove> An array of C<string>s representing tag names
to be removed from the bugs.

It is safe to specify tags that are not associated with any
bugs--they will just be silently ignored.

=back

Tiago Mello's avatar
Tiago Mello committed
4477 4478
=back

4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497
=item B<Returns>

C<changes>, a hash containing bug IDs as keys and one single value
name "tags" which is also a hash, with C<added> and C<removed> as keys.
See L</update_see_also> for an example of how it looks like.

=item B<Errors>

This method can throw the same errors as L</get>.

=item B<History>

=over

=item Added in Bugzilla B<4.4>.

=back

=back
4498

4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512
=head2 search_comment_tags

B<UNSTABLE>

=over

=item B<Description>

Searches for tags which contain the provided substring.

=item B<REST>

To search for comment tags:

4513
GET /rest/bug/comment/tags/<query>
4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568

=item B<Params>

=over

=item C<query>

B<Required> C<string> Only tags containg this substring will be returned.

=item C<limit>

C<int> If provided will return no more than C<limit> tags.  Defaults to C<10>.

=back

=item B<Returns>

An C<array of strings> of matching tags.

=item B<Errors>

This method can throw all of the errors that L</get> throws, plus:

=over

=item 125 (Comment Tagging Disabled)

Comment tagging support is not available or enabled.

=back

=item B<History>

=over

=item Added in Bugzilla B<5.0>.

=back

=back

=head2 update_comment_tags

B<UNSTABLE>

=over

=item B<Description>

Adds or removes tags from a comment.

=item B<REST>

To update the tags comments attached to a comment:

4569
PUT /rest/bug/comment/tags
4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629

The params to include in the PUT body as well as the returned data format,
are the same as below.

=item B<Params>

=over

=item C<comment_id>

B<Required> C<int> The ID of the comment to update.

=item C<add>

C<array of strings> The tags to attach to the comment.

=item C<remove>

C<array of strings> The tags to detach from the comment.

=back

=item B<Returns>

An C<array of strings> containing the comment's updated tags.

=item B<Errors>

This method can throw all of the errors that L</get> throws, plus:

=over

=item 125 (Comment Tagging Disabled)

Comment tagging support is not available or enabled.

=item 126 (Invalid Comment Tag)

The comment tag provided was not valid (eg. contains invalid characters).

=item 127 (Comment Tag Too Short)

The comment tag provided is shorter than the minimum length.

=item 128 (Comment Tag Too Long)

The comment tag provided is longer than the maximum length.

=back

=item B<History>

=over

=item Added in Bugzilla B<5.0>.

=back

=back

4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670
=head2 render_comment

B<UNSTABLE>

=over

=item B<Description>

Returns the HTML rendering of the provided comment text.

=item B<Params>

=over

=item C<text>

B<Required> C<strings> Text comment text to render.

=item C<id>

C<int> The ID of the bug to render the comment against.

=back

=item B<Returns>

C<html> containing the HTML rendering.

=item B<Errors>

This method can throw all of the errors that L</get> throws.

=item B<History>

=over

=item Added in Bugzilla B<5.0>.

=back

=back