Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/en/md/api/core/v1/flag-activity.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
18 changes: 9 additions & 9 deletions extensions/BugModal/lib/API/V1/BugModal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ sub initial_field_values {
# GET /bug_modal/product_info?product=<name>
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,
Expand Down Expand Up @@ -300,16 +300,16 @@ sub _render_comment_html {
# GET /bug_modal/new_product/<id>?product=<name>
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
Expand Down
6 changes: 6 additions & 0 deletions extensions/BugModal/t/bmo/bug-modal-api.t
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)) {
Expand Down
7 changes: 3 additions & 4 deletions extensions/MyDashboard/lib/API/V1/MyDashboard.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -102,16 +102,15 @@ 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) {

# The query above already skips private comments for non-insiders.
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;
Expand Down
62 changes: 62 additions & 0 deletions extensions/MyDashboard/t/bmo/mydashboard-api.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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-$$",
Expand Down Expand Up @@ -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 =>
Expand Down
8 changes: 3 additions & 5 deletions extensions/Review/lib/API/V1/Review.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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]);
Expand Down
13 changes: 10 additions & 3 deletions extensions/Review/t/bmo/review-api.t
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down