From c2ebd1bb43d06223d26426a233c00a6ca22f45d6 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sun, 6 Jan 2008 08:52:17 +0000 Subject: Bug 355847: Make the WebService able to add a comment to a bug Patch By Tsahi Asher r=mkanat, a=mkanat --- Bugzilla/WebService/Bug.pm | 81 +++++++++++++++++++++++++++++++++++++++- Bugzilla/WebService/Constants.pm | 2 + 2 files changed, 82 insertions(+), 1 deletion(-) (limited to 'Bugzilla/WebService') diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 8dacfe956..7148b78cb 100755 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -14,6 +14,8 @@ # # Contributor(s): Marc Schumann # Max Kanat-Alexander +# Mads Bondo Dydensborg +# Tsahi Asher package Bugzilla::WebService::Bug; @@ -25,7 +27,6 @@ use Bugzilla::Constants; use Bugzilla::Error; use Bugzilla::Field; use Bugzilla::WebService::Constants; -use Bugzilla::Util qw(detaint_natural); use Bugzilla::Bug; use Bugzilla::BugMail; use Bugzilla::Constants; @@ -177,6 +178,36 @@ sub legal_values { return { values => \@result }; } +sub add_comment { + my ($self, $params) = @_; + + #The user must login in order add a comment + Bugzilla->login(LOGIN_REQUIRED); + + # Check parameters + defined $params->{id} + || ThrowCodeError('param_required', { param => 'id' }); + ValidateBugID($params->{id}); + + my $comment = $params->{comment}; + defined $comment + || ThrowCodeError('param_required', { param => 'comment' }); + + my $bug = new Bugzilla::Bug($params->{id}); + + Bugzilla->user->can_edit_product($bug->product_id) + || ThrowUserError("product_edit_denied", {product => $bug->product}); + + # Append comment + $bug->add_comment($comment, { isprivate => $params->{private}, + work_time => $params->{work_time} }); + $bug->update(); + + # Send mail. + Bugzilla::BugMail::Send($bug->bug_id, { changer => Bugzilla->user->login }); + return undef; +} + 1; __END__ @@ -467,5 +498,53 @@ in them. The error message will have more details. =back +=item C B + +=over + +=item B + +This allows you to add a comment to a bug in Bugzilla. + +=item B + +=over + +=item C (int) B - The id or alias of the bug to append a +comment to. + +=item C (string) B - The comment to append to the bug. + +=item C (boolean) - If set to true, the comment is private, otherwise +it is assumed to be public. + +=item C (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 + +=item B + +=over + +=item 100 (Invalid Bug Alias) + +If you specified an alias and either: (a) the Bugzilla you're querying +doesn't support aliases or (b) there is no bug with that alias. + +=item 101 (Invalid Bug ID) + +The id you specified doesn't exist in the database. + +=item 108 (Bug Edit Denied) + +You did not have the necessary rights to edit the bug. + +=back + +=back + =back diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm index 2dfb0b112..a1ecb53ed 100755 --- a/Bugzilla/WebService/Constants.pm +++ b/Bugzilla/WebService/Constants.pm @@ -75,6 +75,8 @@ use constant WS_ERROR_CODE => { product_disabled => 106, # Invalid Summary require_summary => 107, + # Not authorized to edit the bug + product_edit_denied => 108, # Authentication errors are usually 300-400. invalid_username_or_password => 300, -- cgit v1.2.3-24-g4f1b