From 0638a60211770c1ce91e0c114965606e3b4b164f Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Fri, 20 Nov 2026 22:58:30 +0100 Subject: [PATCH 1/8] Bug 2095730 - Return the latest comment in MyDashboard run_last_changes The last comment query had LIMIT 1 but no ORDER BY, so it returned any comment after changeddate_api, usually the oldest one. Order by date and comment id, newest first. --- extensions/MyDashboard/lib/API/V1/MyDashboard.pm | 2 +- extensions/MyDashboard/t/bmo/mydashboard-api.t | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/extensions/MyDashboard/lib/API/V1/MyDashboard.pm b/extensions/MyDashboard/lib/API/V1/MyDashboard.pm index 5475179fdc..60f8c08598 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 = {}; diff --git a/extensions/MyDashboard/t/bmo/mydashboard-api.t b/extensions/MyDashboard/t/bmo/mydashboard-api.t index 036aa1bbe9..972248fda4 100644 --- a/extensions/MyDashboard/t/bmo/mydashboard-api.t +++ b/extensions/MyDashboard/t/bmo/mydashboard-api.t @@ -87,6 +87,15 @@ 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. +my $two = Bugzilla::Bug->create({%fields, comment => 'description'}); +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 in a group the user isn't in, not assigned to them. my $group = Bugzilla::Group->create({ name => "mydashboard-api-$$", @@ -152,6 +161,13 @@ $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?bug_id=999999999' => \%auth) ->json_is('/error' => 1, 'unknown bug'); $t->get_ok('/rest/mydashboard/run_last_changes' => \%auth => form => From 830cb0dbc4b68b181346011395dd059ee373990e Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Fri, 20 Nov 2026 23:08:23 +0100 Subject: [PATCH 2/8] Bug 2095730 - Find the last comment of a bug given by its alias in MyDashboard run_last_changes The last comment query was bound to the bug_id param as given, so with a bug alias it looked for bug_id = '' and never found a comment. Bind the id of the bug it already loaded. --- extensions/MyDashboard/lib/API/V1/MyDashboard.pm | 3 +-- extensions/MyDashboard/t/bmo/mydashboard-api.t | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/MyDashboard/lib/API/V1/MyDashboard.pm b/extensions/MyDashboard/lib/API/V1/MyDashboard.pm index 60f8c08598..4ed7f85d5c 100644 --- a/extensions/MyDashboard/lib/API/V1/MyDashboard.pm +++ b/extensions/MyDashboard/lib/API/V1/MyDashboard.pm @@ -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) { diff --git a/extensions/MyDashboard/t/bmo/mydashboard-api.t b/extensions/MyDashboard/t/bmo/mydashboard-api.t index 972248fda4..174a9812f1 100644 --- a/extensions/MyDashboard/t/bmo/mydashboard-api.t +++ b/extensions/MyDashboard/t/bmo/mydashboard-api.t @@ -88,7 +88,8 @@ Bugzilla->dbh->do( undef, $bug->id, $latest); # A bug with two comments after its creation, to get the latest one. -my $two = Bugzilla::Bug->create({%fields, comment => 'description'}); +my $two = Bugzilla::Bug->create( + {%fields, 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); @@ -168,6 +169,13 @@ $t->get_ok('/rest/mydashboard/run_last_changes' => \%auth => form => '/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' + ); $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 => From a49b34fb1b6bcaf20849c82327c6151b21e5bd5b Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Fri, 20 Nov 2026 23:19:44 +0100 Subject: [PATCH 3/8] Bug 2095730 - Render only Markdown comments as Markdown in MyDashboard run_last_changes With use_markdown on, every last comment was rendered as Markdown, including plain text ones, which then showed formatting they never had. Check the comment's is_markdown flag too, as EditComments does. --- .../MyDashboard/lib/API/V1/MyDashboard.pm | 2 +- .../MyDashboard/t/bmo/mydashboard-api.t | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/extensions/MyDashboard/lib/API/V1/MyDashboard.pm b/extensions/MyDashboard/lib/API/V1/MyDashboard.pm index 4ed7f85d5c..2855c6d768 100644 --- a/extensions/MyDashboard/lib/API/V1/MyDashboard.pm +++ b/extensions/MyDashboard/lib/API/V1/MyDashboard.pm @@ -110,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 174a9812f1..d73d3683fa 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; @@ -97,6 +98,12 @@ for my $n (1, 2) { $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, 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-$$", @@ -176,6 +183,21 @@ $t->get_ok('/rest/mydashboard/run_last_changes' => \%auth => form => '/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. +my $use_markdown = Bugzilla->params->{use_markdown}; +END { 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 => From 11274dd709eb66960fda702264737b0cbc3ff7b7 Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Mon, 23 Nov 2026 15:58:50 +0100 Subject: [PATCH 4/8] Bug 2095730 - Refuse a Review flag_activity search without any criteria The flag_activity_parameters_required check ran after the date range was added to the match criteria, so it never fired, and a request with no criteria returned the whole table for the last 30 days. Run it before the date range, limit and offset are added. --- docs/en/md/api/core/v1/flag-activity.md | 8 +++++--- extensions/Review/lib/API/V1/Review.pm | 8 +++----- extensions/Review/t/bmo/review-api.t | 11 ++++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) 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/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..cd9c3340a3 100644 --- a/extensions/Review/t/bmo/review-api.t +++ b/extensions/Review/t/bmo/review-api.t @@ -157,9 +157,14 @@ 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/')->json_like( + '/message' => qr/without any search terms/, + 'an empty requestee is ignored, not a 404' +); +$t->get_ok('/rest/review/flag_activity?limit=5&after=2000-01-01')->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'); From bc83554b6b87476f4020da14b22478303e69a81c Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Mon, 23 Nov 2026 16:07:22 +0100 Subject: [PATCH 5/8] Bug 2095730 - Refuse more than one product in BugModal product_info and new_product The legacy REST layer passed a repeated ?product= as a list, which product_info refused. Mojo keeps only the last value, so that check, also added to new_product in the migration, never fired and the request silently used the last product. Read product as a list param and refuse more than one value --- extensions/BugModal/lib/API/V1/BugModal.pm | 18 +++++++++--------- extensions/BugModal/t/bmo/bug-modal-api.t | 6 ++++++ 2 files changed, 15 insertions(+), 9 deletions(-) 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)) { From 7332cb1e3ec7776ae1615e90b4e6e6b9607222a8 Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Tue, 24 Nov 2026 20:34:10 +0100 Subject: [PATCH 6/8] Bug 2095730 - Test - Assign the new MyDashboard fixtures to another user The two bugs added for run_last_changes were assigned to the test user, so they also came back in its assignedbugs query, sorted by last change, newest first. Created a second later than the first bug, either one would come first there and fail the check that the first bug is listed first. Assign them to the admin, as the hidden bug already is. --- extensions/MyDashboard/t/bmo/mydashboard-api.t | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/extensions/MyDashboard/t/bmo/mydashboard-api.t b/extensions/MyDashboard/t/bmo/mydashboard-api.t index d73d3683fa..f9b70ea7da 100644 --- a/extensions/MyDashboard/t/bmo/mydashboard-api.t +++ b/extensions/MyDashboard/t/bmo/mydashboard-api.t @@ -88,9 +88,16 @@ 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. -my $two = Bugzilla::Bug->create( - {%fields, comment => 'description', alias => "mydashboard-api-$$"}); +# 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); @@ -99,7 +106,8 @@ for my $n (1, 2) { } # A bug whose last comment is plain text, not written in Markdown. -my $plain = Bugzilla::Bug->create({%fields, comment => 'description'}); +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')); From 94e80c0cf39993408d17fe3306ee5fed2613d806 Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Tue, 24 Nov 2026 21:07:23 +0100 Subject: [PATCH 7/8] Bug 2095730 - Test - Restore use_markdown only once the MyDashboard test has read it The END block that puts use_markdown back is registered at compile time, so it also ran when the test skipped or died before reading it, and then wrote an empty use_markdown to the shared test database, turning Markdown off for the test files run after it. Only restore it once it was read. --- extensions/MyDashboard/t/bmo/mydashboard-api.t | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/extensions/MyDashboard/t/bmo/mydashboard-api.t b/extensions/MyDashboard/t/bmo/mydashboard-api.t index f9b70ea7da..80a464ca87 100644 --- a/extensions/MyDashboard/t/bmo/mydashboard-api.t +++ b/extensions/MyDashboard/t/bmo/mydashboard-api.t @@ -193,9 +193,17 @@ $t->get_ok('/rest/mydashboard/run_last_changes' => \%auth => form => ); # 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. +# 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 { SetParam('use_markdown', $use_markdown); write_params() } + +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 => From 4c0fa22113474320753a3a1de6e61132b8358a24 Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Tue, 24 Nov 2026 21:16:34 +0100 Subject: [PATCH 8/8] Bug 2095730 - Test - Check the status of the refused Review flag_activity searches The empty requestee test kept its old name, which said it was ignored while it now checks that it is refused, and neither refused search checked its status, so a 500 with the same message would have passed. Rename it and expect a 400 on both. --- extensions/Review/t/bmo/review-api.t | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/extensions/Review/t/bmo/review-api.t b/extensions/Review/t/bmo/review-api.t index cd9c3340a3..f251c20952 100644 --- a/extensions/Review/t/bmo/review-api.t +++ b/extensions/Review/t/bmo/review-api.t @@ -157,14 +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/')->json_like( +$t->get_ok('/rest/review/flag_activity/requestee/')->status_is(400)->json_like( '/message' => qr/without any search terms/, - 'an empty requestee is ignored, not a 404' + 'an empty requestee alone is refused' ); -$t->get_ok('/rest/review/flag_activity?limit=5&after=2000-01-01')->json_like( +$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');