From b34fcddb0e8c135d4f2feb9686223fddd9a8e7df Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Mon, 11 May 2015 16:30:39 +0100 Subject: Bug 1161716: backport bug 1140575 to allow adding comment tags via webservice API when creating/updating --- Bugzilla/Bug.pm | 24 +++++++++++++++++++++-- Bugzilla/WebService/Bug.pm | 47 +++++++++++++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index af3f5a355..eee35360b 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -726,6 +726,7 @@ sub create { my $keywords = delete $params->{keywords}; my $creation_comment = delete $params->{comment}; my $see_also = delete $params->{see_also}; + my $comment_tags = delete $params->{comment_tags}; # We don't want the bug to appear in the system until it's correctly # protected by groups. @@ -814,7 +815,16 @@ sub create { # Insert the comment. We always insert a comment on bug creation, # but sometimes it's blank. - Bugzilla::Comment->insert_create_data($creation_comment); + my $comment = Bugzilla::Comment->insert_create_data($creation_comment); + + # Add comment tags + if (defined $comment_tags && Bugzilla->user->can_tag_comments) { + $comment_tags = ref $comment_tags ? $comment_tags : [ $comment_tags ]; + foreach my $tag (@{$comment_tags}) { + $comment->add_tag($tag) if defined $tag; + } + $comment->update(); + } # BMO - add the stash param from bug_start_of_create Bugzilla::Hook::process('bug_end_of_create', { bug => $bug, @@ -1020,7 +1030,7 @@ sub update { join(', ', @added_names)]; } - # Comments + # Comments and comment tags foreach my $comment (@{$self->{added_comments} || []}) { # Override the Comment's timestamp to be identical to the update # timestamp. @@ -1030,6 +1040,10 @@ sub update { LogActivityEntry($self->id, "work_time", "", $comment->work_time, $user->id, $delta_ts); } + foreach my $tag (@{$self->{added_comment_tags} || []}) { + $comment->add_tag($tag) if defined $tag; + } + $comment->update() if @{$self->{added_comment_tags} || []}; } # Comment Privacy @@ -2454,6 +2468,12 @@ sub set_all { work_time => $params->{'work_time'} }); } + if (defined $params->{comment_tags} && Bugzilla->user->can_tag_comments()) { + $self->{added_comment_tags} = ref $params->{comment_tags} + ? $params->{comment_tags} + : [ $params->{comment_tags} ]; + } + my %normal_set_all; foreach my $name (keys %$params) { # These are handled separately below. diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index b76c30b19..2edd2f3d0 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -1044,7 +1044,7 @@ sub update_attachment { sub add_comment { my ($self, $params) = @_; - + # BMO: Don't allow updating of bugs if disabled if (Bugzilla->params->{disable_bug_updates}) { ThrowErrorPage('bug/process/updates-disabled.html.tmpl', @@ -1053,42 +1053,46 @@ sub add_comment { #The user must login in order add a comment Bugzilla->login(LOGIN_REQUIRED); - + # Check parameters - defined $params->{id} - || ThrowCodeError('param_required', { param => 'id' }); - my $comment = $params->{comment}; + defined $params->{id} + || ThrowCodeError('param_required', { param => 'id' }); + my $comment = $params->{comment}; (defined $comment && trim($comment) ne '') || ThrowCodeError('param_required', { param => 'comment' }); - + my $bug = Bugzilla::Bug->check($params->{id}); - + Bugzilla->user->can_edit_product($bug->product_id) || ThrowUserError("product_edit_denied", {product => $bug->product}); - - # Backwards-compatibility for versions before 3.6 + + # Backwards-compatibility for versions before 3.6 if (defined $params->{private}) { $params->{is_private} = delete $params->{private}; } # Append comment $bug->add_comment($comment, { isprivate => $params->{is_private}, work_time => $params->{work_time} }); - - # Capture the call to bug->update (which creates the new comment) in + + # Add comment tags + $bug->set_all({ comment_tags => $params->{comment_tags} }) + if defined $params->{comment_tags}; + + # Capture the call to bug->update (which creates the new comment) in # a transaction so we're sure to get the correct comment_id. - + my $dbh = Bugzilla->dbh; $dbh->bz_start_transaction(); - + $bug->update(); - + my $new_comment_id = $dbh->bz_last_key('longdescs', 'comment_id'); - + $dbh->bz_commit_transaction(); - + # Send mail. Bugzilla::BugMail::Send($bug->bug_id, { changer => Bugzilla->user }); - + return { id => $self->type('int', $new_comment_id) }; } @@ -3354,6 +3358,9 @@ don't want it to be assigned to the component owner. =item C (boolean) - If set to true, the description is private, otherwise it is assumed to be public. +=item C (array) - An array of strings to add as comment +tags to the description. + =item C (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, @@ -3931,6 +3938,8 @@ otherwise it is assumed to be public. on the bug. If you are not in the time tracking group, this value will be ignored. +=item C (array) - Array of strings to add as comment tags for +the new comment. =back @@ -4116,6 +4125,10 @@ 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 + +C An array of strings to add as comment tags for the new comment. + =item C C The Component the bug is in. -- cgit v1.2.3-24-g4f1b