]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1487171 - Allow setting bug flags when creating/updating attachment with API
authorKohei Yoshino <kohei.yoshino@gmail.com>
Wed, 17 Oct 2018 19:43:24 +0000 (15:43 -0400)
committerdklawren <dklawren@users.noreply.github.com>
Wed, 17 Oct 2018 19:43:24 +0000 (15:43 -0400)
Bugzilla/WebService/Bug.pm
docs/en/rst/api/core/v1/attachment.rst

index 61a95e07dcc023fee78dbc2774271b881310d048..c1b98856bf5f07b6ef98110f80b7cb64c0db3074 100644 (file)
@@ -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<string> The login of the requestee if the flag type is requestable to a specif
 
 =back
 
+=item C<bug_flags>
+
+C<array> An optional array of hashes with flags to add to the attachment's
+bug. See the C<flags> param for the L</update> method for the object format.
+
 =back
 
 =item B<Returns>
@@ -3854,6 +3879,11 @@ C<boolean> Set to true if you specifically want a new flag to be created.
 
 =back
 
+=item C<bug_flags>
+
+C<array> An optional array of hashes with changes to the flags of the attachment's
+bug. See the C<flags> param for the L</update> method for the object format.
+
 =item B<Returns>
 
 A C<hash> with a single field, "attachment". This points to an array of hashes
index cbde4ba10c6a44a3d31a0d201d5acb46e0713ca9..edba0e2c2482e102007545baf50a2321554ec6e5 100644 (file)
@@ -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: