diff --git a/docs/en/md/api/core/v1/flag-activity.md b/docs/en/md/api/core/v1/flag-activity.md index 5867533ff4..3710d65bcb 100644 --- a/docs/en/md/api/core/v1/flag-activity.md +++ b/docs/en/md/api/core/v1/flag-activity.md @@ -45,7 +45,9 @@ Fetches activity for all flags of the type specified by its name. GET /rest/review/flag_activity ``` -Fetches activity for all flags. +Fetches activity matching the `flag_ids`, `type_id`, `type_name`, +`requestee`, `setter`, `bug_id` or `status` query parameters. At least one of +them is required. There are also query parameters that can be used to further filter the response: @@ -147,5 +149,5 @@ If a nonexistent but properly specified (i.e. integer value) flag or flag-type ID is given, a 200 OK response will be returned with an empty array. In other cases, different response codes may be returned: -- 400 (Bad Request): An invalid flag or flag-type ID was given, or `offset` was - given without a value for `limit`. +- 400 (Bad Request): An invalid flag or flag-type ID was given, `offset` was + given without a value for `limit`, or no search criteria were given. diff --git a/extensions/BugModal/lib/API/V1/BugModal.pm b/extensions/BugModal/lib/API/V1/BugModal.pm index 0f464d6b6d..bd0f153ab6 100644 --- a/extensions/BugModal/lib/API/V1/BugModal.pm +++ b/extensions/BugModal/lib/API/V1/BugModal.pm @@ -109,12 +109,12 @@ sub initial_field_values { # GET /bug_modal/product_info?product= sub product_info { my ($self) = @_; - my $params = $self->_params or return; + my $params = $self->_params(['product']) or return; + my $names = $params->{product} || []; ThrowCodeError('params_required', {function => 'BugModal.components', params => ['product']}) - if ref $params->{product}; - my $product - = Bugzilla::Product->check({name => $params->{product}, cache => 1}); + if @$names > 1; + my $product = Bugzilla::Product->check({name => $names->[0], cache => 1}); $product = Bugzilla->user->can_enter_product($product, 1); my @components = map { { name => $_->name, @@ -300,16 +300,16 @@ sub _render_comment_html { # GET /bug_modal/new_product/?product= sub new_product { my ($self) = @_; - my $params = $self->_params or return; + my $params = $self->_params(['product']) or return; my $dbh = Bugzilla->dbh; my $user = Bugzilla->user; my $bug = Bugzilla::Bug->check({id => $params->{id}}); + my $names = $params->{product} || []; ThrowCodeError('params_required', {function => 'BugModal.new_product', params => ['product']}) - if ref $params->{product}; - my $product - = Bugzilla::Product->check({name => $params->{product}, cache => 1}); - my $true = $self->type('boolean', 1); + if @$names > 1; + my $product = Bugzilla::Product->check({name => $names->[0], cache => 1}); + my $true = $self->type('boolean', 1); my %result; # components diff --git a/extensions/BugModal/t/bmo/bug-modal-api.t b/extensions/BugModal/t/bmo/bug-modal-api.t index dcfbc4a7df..8c3050f264 100644 --- a/extensions/BugModal/t/bmo/bug-modal-api.t +++ b/extensions/BugModal/t/bmo/bug-modal-api.t @@ -97,6 +97,9 @@ $t->get_ok('/rest/bug_modal/product_info' => form => {product => $name}) $t->get_ok('/rest/bug_modal/product_info?product=No.Such%20Product') ->json_is('/error' => 1) ->json_like('/message' => qr/No\.Such Product/, 'unknown product'); +$t->get_ok( + '/rest/bug_modal/product_info' => form => {product => [$name, $name]}) + ->json_is('/code' => 50, 'product_info refuses more than one product'); # edit, cc $t->get_ok("/rest/bug_modal/edit/$bug_id" => \%auth) @@ -174,6 +177,9 @@ $t->get_ok( ->json_has('/groups', 'fields for the same product'); $t->get_ok("/rest/bug_modal/new_product/$bug_id" => \%auth) ->json_is('/error' => 1, 'product is required'); +$t->get_ok("/rest/bug_modal/new_product/$bug_id" => \%auth => form => + {product => [$name, $name]}) + ->json_is('/code' => 50, 'new_product refuses more than one product'); # edit, cc and new_product on a bug the caller can't see foreach my $path (qw(edit cc new_product)) { diff --git a/extensions/MyDashboard/lib/API/V1/MyDashboard.pm b/extensions/MyDashboard/lib/API/V1/MyDashboard.pm index 5475179fdc..2855c6d768 100644 --- a/extensions/MyDashboard/lib/API/V1/MyDashboard.pm +++ b/extensions/MyDashboard/lib/API/V1/MyDashboard.pm @@ -82,7 +82,7 @@ sub run_last_changes { if (!$user->is_insider) { $last_comment_sql .= " AND isprivate = 0"; } - $last_comment_sql .= " LIMIT 1"; + $last_comment_sql .= " ORDER BY bug_when DESC, comment_id DESC LIMIT 1"; my $last_comment_sth = $dbh->prepare($last_comment_sql); my $last_changes = {}; @@ -102,8 +102,7 @@ sub run_last_changes { $datetime->set_time_zone($user->timezone); $last_changes->{when} = $datetime->strftime('%Y-%m-%d %T %Z'); } - my $last_comment_id - = $dbh->selectrow_array($last_comment_sth, undef, $params->{bug_id}, + my $last_comment_id = $dbh->selectrow_array($last_comment_sth, undef, $bug->id, $params->{changeddate_api}); if ($last_comment_id) { @@ -111,7 +110,7 @@ sub run_last_changes { my $comment = Bugzilla::Comment->new($last_comment_id); my $text = $comment->body_full; my $html - = Bugzilla->params->{use_markdown} + = $comment->is_markdown && Bugzilla->params->{use_markdown} ? Bugzilla->markdown->render_html($text, $bug) : Bugzilla::Template::quoteUrls($text, $bug); $last_changes->{comment_html} = $html; diff --git a/extensions/MyDashboard/t/bmo/mydashboard-api.t b/extensions/MyDashboard/t/bmo/mydashboard-api.t index 036aa1bbe9..80a464ca87 100644 --- a/extensions/MyDashboard/t/bmo/mydashboard-api.t +++ b/extensions/MyDashboard/t/bmo/mydashboard-api.t @@ -23,6 +23,7 @@ use Bugzilla; BEGIN { Bugzilla->extensions } use Bugzilla::Constants; use Bugzilla::Bug; +use Bugzilla::Config qw(SetParam write_params); use Bugzilla::Group; use Bugzilla::Product; use Bugzilla::User; @@ -87,6 +88,30 @@ Bugzilla->dbh->do( 'UPDATE longdescs SET isprivate = 1 WHERE bug_id = ? AND bug_when = ?', undef, $bug->id, $latest); +# A bug with two comments after its creation, to get the latest one. Not +# assigned to the user, so it stays out of the assignedbugs query below, whose +# first bug must be $bug. +my $two = Bugzilla::Bug->create({ + %fields, + assigned_to => $admin->login, + comment => 'description', + alias => "mydashboard-api-$$" +}); + +for my $n (1, 2) { + my $when = datetime_from($two->creation_ts)->add(seconds => 2 * $n); + my $obj = Bugzilla::Bug->new($two->id); + $obj->add_comment("comment number $n"); + $obj->update($when->strftime('%Y-%m-%d %T')); +} + +# A bug whose last comment is plain text, not written in Markdown. +my $plain = Bugzilla::Bug->create( + {%fields, assigned_to => $admin->login, comment => 'description'}); +$plain->add_comment('a *plain* comment', {is_markdown => 0}); +$plain->update( + datetime_from($plain->creation_ts)->add(seconds => 2)->strftime('%Y-%m-%d %T')); + # A bug in a group the user isn't in, not assigned to them. my $group = Bugzilla::Group->create({ name => "mydashboard-api-$$", @@ -152,6 +177,43 @@ $t->get_ok('/rest/mydashboard/run_last_changes' => \%auth => form => ->json_like('/results/0/last_changes/comment_html' => qr/a newer comment/) ->json_is('/results/0/last_changes/email' => $admin->login) ->json_has('/results/0/last_changes/when'); +$t->get_ok('/rest/mydashboard/run_last_changes' => \%auth => form => + {bug_id => $two->id, changeddate_api => $two->creation_ts}) + ->status_is(200) + ->json_like( + '/results/0/last_changes/comment_html' => qr/comment number 2/, + 'the latest comment, not the first one after the date' + ); +$t->get_ok('/rest/mydashboard/run_last_changes' => \%auth => form => + {bug_id => "mydashboard-api-$$", changeddate_api => $two->creation_ts}) + ->status_is(200) + ->json_like( + '/results/0/last_changes/comment_html' => qr/comment number 2/, + 'a bug alias finds the comment too' + ); + +# Markdown is only used for comments written in Markdown. The app reads params +# from the database, so set it there, and put it back afterwards. Only once it +# was read, as END also runs when the test skips or dies before that. +my $use_markdown = Bugzilla->params->{use_markdown}; + +END { + if (defined $use_markdown) { + SetParam('use_markdown', $use_markdown); + write_params(); + } +} + +SetParam('use_markdown', 1); +write_params(); +$t->get_ok('/rest/mydashboard/run_last_changes' => \%auth => form => + {bug_id => $plain->id, changeddate_api => $plain->creation_ts}) + ->status_is(200) + ->json_like( + '/results/0/last_changes/comment_html' => qr/a \*plain\* comment/, + 'a plain text comment is not rendered as Markdown' + ); + $t->get_ok('/rest/mydashboard/run_last_changes?bug_id=999999999' => \%auth) ->json_is('/error' => 1, 'unknown bug'); $t->get_ok('/rest/mydashboard/run_last_changes' => \%auth => form => diff --git a/extensions/Review/lib/API/V1/Review.pm b/extensions/Review/lib/API/V1/Review.pm index 77eddf9d29..881cf73d5e 100644 --- a/extensions/Review/lib/API/V1/Review.pm +++ b/extensions/Review/lib/API/V1/Review.pm @@ -215,6 +215,9 @@ sub flag_activity { } } + # Refuse a search on the date range alone, which returns the whole table. + ThrowUserError('flag_activity_parameters_required') if !%match_criteria; + ThrowCodeError('param_required', {param => 'limit', function => 'Review.flag_activity()'}) if defined $params->{offset} && !defined $params->{limit}; @@ -251,11 +254,6 @@ sub flag_activity { $match_criteria{WHERE} = {'date(flag_when) BETWEEN ? AND ?' => [$after, $before]}; - # Throw error if no other parameters have been passed other than limit and offset - if (!grep(!/^(LIMIT|OFFSET)$/, keys %match_criteria)) { - ThrowUserError('flag_activity_parameters_required'); - } - my $matches = Bugzilla::FlagActivity->match(\%match_criteria); my $user = Bugzilla->user; $user->visible_bugs([map { $_->bug_id } @$matches]); diff --git a/extensions/Review/t/bmo/review-api.t b/extensions/Review/t/bmo/review-api.t index db6478ab70..f251c20952 100644 --- a/extensions/Review/t/bmo/review-api.t +++ b/extensions/Review/t/bmo/review-api.t @@ -157,9 +157,16 @@ SKIP: { } $t->get_ok('/rest/review/flag_activity/requestee/nobody-here@bmo.tld') ->json_is('/error' => 1, 'unknown requestee'); -$t->get_ok('/rest/review/flag_activity/requestee/') - ->status_is(200) - ->json_hasnt('/error', 'an empty requestee is ignored, not a 404'); +$t->get_ok('/rest/review/flag_activity/requestee/')->status_is(400)->json_like( + '/message' => qr/without any search terms/, + 'an empty requestee alone is refused' +); +$t->get_ok('/rest/review/flag_activity?limit=5&after=2000-01-01') + ->status_is(400) + ->json_like( + '/message' => qr/without any search terms/, + 'limit and a date range alone are refused' + ); $t->get_ok('/rest/review/flag_activity?bug_id=1&offset=5') ->json_is('/error' => 1, 'offset needs a limit');