From: Kohei Yoshino Date: Wed, 17 Oct 2018 19:43:24 +0000 (-0400) Subject: Bug 1487171 - Allow setting bug flags when creating/updating attachment with API X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82749fe1524d610b237eb533099adf2c790d4482;p=thirdparty%2Fbugzilla.git Bug 1487171 - Allow setting bug flags when creating/updating attachment with API --- diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 61a95e07d..c1b98856b 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -934,6 +934,10 @@ sub add_attachment { my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); my $flags = delete $params->{flags}; + my $comment = delete $params->{comment}; + my $bug_flags = delete $params->{bug_flags}; + + $comment = $comment ? trim($comment) : ''; foreach my $bug (@bugs) { my $attachment = Bugzilla::Attachment->create({ @@ -953,11 +957,18 @@ sub add_attachment { } $attachment->update($timestamp); - my $comment = $params->{comment} || ''; - $attachment->bug->add_comment($comment, + + # The comment has to be added even if it's empty + $bug->add_comment($comment, { isprivate => $attachment->isprivate, type => CMT_ATTACHMENT_CREATED, extra_data => $attachment->id }); + + if ($bug_flags) { + my ($old_flags, $new_flags) = extract_flags($bug_flags, $bug); + $bug->set_flags($old_flags, $new_flags); + } + push(@created, $attachment); } $_->bug->update($timestamp) foreach @created; @@ -1002,6 +1013,9 @@ sub update_attachment { my $flags = delete $params->{flags}; my $comment = delete $params->{comment}; + my $bug_flags = delete $params->{bug_flags}; + + $comment = $comment ? trim($comment) : ''; # Update the values foreach my $attachment (@attachments) { @@ -1041,14 +1055,20 @@ sub update_attachment { my @result; foreach my $attachment (@attachments) { my $changes = $attachment->update(); + my $bug = $attachment->bug; - if ($comment = trim($comment)) { - $attachment->bug->add_comment($comment, + if ($comment) { + $bug->add_comment($comment, { isprivate => $attachment->isprivate, type => CMT_ATTACHMENT_UPDATED, extra_data => $attachment->id }); } + if ($bug_flags) { + my ($old_flags, $new_flags) = extract_flags($bug_flags, $bug); + $bug->set_flags($old_flags, $new_flags); + } + $changes = translate($changes, ATTACHMENT_MAPPED_RETURNS); my %hash = ( @@ -3680,6 +3700,11 @@ C The login of the requestee if the flag type is requestable to a specif =back +=item C + +C An optional array of hashes with flags to add to the attachment's +bug. See the C param for the L method for the object format. + =back =item B @@ -3854,6 +3879,11 @@ C Set to true if you specifically want a new flag to be created. =back +=item C + +C An optional array of hashes with changes to the flags of the attachment's +bug. See the C param for the L method for the object format. + =item B A C with a single field, "attachment". This points to an array of hashes diff --git a/docs/en/rst/api/core/v1/attachment.rst b/docs/en/rst/api/core/v1/attachment.rst index cbde4ba10..edba0e2c2 100644 --- a/docs/en/rst/api/core/v1/attachment.rst +++ b/docs/en/rst/api/core/v1/attachment.rst @@ -195,6 +195,9 @@ is_private boolean ``true`` if the attachment should be private not specified. flags array Flags objects to add to the attachment. The object format is described in the Flag object below. +bug_flags array Flag objects to add to the attachment's bug. See the + ``flags`` param for :ref:`rest_create_bug` for the + object format. ================ ======= ====================================================== Flag object: @@ -312,6 +315,9 @@ is_obsolete boolean ``true`` if the attachment is obsolete, ``false`` otherwise. flags array An array of Flag objects with changes to the flags. The object format is described in the Flag object below. +bug_flags array An optional array of Flag objects with changes to the + flags of the attachment's bug. See the ``flags`` param + for :ref:`rest_update_bug` for the object format. ============ ======= ========================================================== Flag object: