summaryrefslogtreecommitdiffstats
path: root/extensions/EditComments/lib/WebService.pm
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/EditComments/lib/WebService.pm')
-rw-r--r--extensions/EditComments/lib/WebService.pm89
1 files changed, 43 insertions, 46 deletions
diff --git a/extensions/EditComments/lib/WebService.pm b/extensions/EditComments/lib/WebService.pm
index 6969ca742..97e40b8b6 100644
--- a/extensions/EditComments/lib/WebService.pm
+++ b/extensions/EditComments/lib/WebService.pm
@@ -18,64 +18,61 @@ use Bugzilla::Util qw(trim);
use Bugzilla::WebService::Util qw(validate);
use constant PUBLIC_METHODS => qw(
- comments
+ comments
);
sub comments {
- my ($self, $params) = validate(@_, 'comment_ids');
- my $dbh = Bugzilla->switch_to_shadow_db();
- my $user = Bugzilla->user;
-
- if (!defined $params->{comment_ids}) {
- ThrowCodeError('param_required',
- { function => 'Bug.comments',
- param => 'comment_ids' });
+ my ($self, $params) = validate(@_, 'comment_ids');
+ my $dbh = Bugzilla->switch_to_shadow_db();
+ my $user = Bugzilla->user;
+
+ if (!defined $params->{comment_ids}) {
+ ThrowCodeError('param_required',
+ {function => 'Bug.comments', param => 'comment_ids'});
+ }
+
+ my @ids = map { trim($_) } @{$params->{comment_ids} || []};
+ my $comment_data = Bugzilla::Comment->new_from_list(\@ids);
+
+ # See if we were passed any invalid comment ids.
+ my %got_ids = map { $_->id => 1 } @$comment_data;
+ foreach my $comment_id (@ids) {
+ if (!$got_ids{$comment_id}) {
+ ThrowUserError('comment_id_invalid', {id => $comment_id});
}
+ }
- my @ids = map { trim($_) } @{ $params->{comment_ids} || [] };
- my $comment_data = Bugzilla::Comment->new_from_list(\@ids);
+ # Now make sure that we can see all the associated bugs.
+ my %got_bug_ids = map { $_->bug_id => 1 } @$comment_data;
+ $user->visible_bugs([keys %got_bug_ids]); # preload cache for visibility check
+ Bugzilla::Bug->check($_) foreach (keys %got_bug_ids);
- # See if we were passed any invalid comment ids.
- my %got_ids = map { $_->id => 1 } @$comment_data;
- foreach my $comment_id (@ids) {
- if (!$got_ids{$comment_id}) {
- ThrowUserError('comment_id_invalid', { id => $comment_id });
- }
+ my %comments;
+ foreach my $comment (@$comment_data) {
+ if ($comment->is_private && !$user->is_insider) {
+ ThrowUserError('comment_is_private', {id => $comment->id});
}
+ $comments{$comment->id} = $comment->body;
+ }
- # Now make sure that we can see all the associated bugs.
- my %got_bug_ids = map { $_->bug_id => 1 } @$comment_data;
- $user->visible_bugs([ keys %got_bug_ids ]); # preload cache for visibility check
- Bugzilla::Bug->check($_) foreach (keys %got_bug_ids);
-
- my %comments;
- foreach my $comment (@$comment_data) {
- if ($comment->is_private && !$user->is_insider) {
- ThrowUserError('comment_is_private', { id => $comment->id });
- }
- $comments{$comment->id} = $comment->body;
- }
-
- return { comments => \%comments };
+ return {comments => \%comments};
}
sub rest_resources {
- return [
- qr{^/editcomments/comment/(\d+)$}, {
- GET => {
- method => 'comments',
- params => sub {
- return { comment_ids => $_[0] };
- },
- },
+ return [
+ qr{^/editcomments/comment/(\d+)$},
+ {
+ GET => {
+ method => 'comments',
+ params => sub {
+ return {comment_ids => $_[0]};
},
- qr{^/editcomments/comment$}, {
- GET => {
- method => 'comments',
- },
- },
- ];
-};
+ },
+ },
+ qr{^/editcomments/comment$},
+ {GET => {method => 'comments',},},
+ ];
+}
1;