Skip to content

Bug 2061831 - Add additional information to bugzilla comments in REST API if comment edited before - #2697

Open
dklawren wants to merge 2 commits into
mozilla-bteam:masterfrom
dklawren:2061831
Open

Bug 2061831 - Add additional information to bugzilla comments in REST API if comment edited before#2697
dklawren wants to merge 2 commits into
mozilla-bteam:masterfrom
dklawren:2061831

Conversation

@dklawren

@dklawren dklawren commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

What changed (3 files, +116 lines)

  1. Bugzilla/WebService/Bug.pm:414 — new _preload_comment_edit_info(): one grouped query over longdescs_activity per request, stashes {edit_count, last_change_time} on each comment object.
  2. Bugzilla/WebService/Bug.pm:478 — _translate_comment emits edit_count (int) and last_change_time (dateTime or null) only when that stash exists.
  3. Three call sites wired — Bug.comments bug-ids branch, Bug.comments comment-ids branch, and the comments extra field in _bug_to_hash.
  4. Docs — POD block + history entry in Bug.pm, and the field table in docs/en/rst/api/core/v1/comment.rst.
  5. New test — qa/t/rest_bug_comment_edits.t, 3 visibility tiers × both REST routes.

No schema change, no checksetup.pl run needed. Your four decisions are all encoded: edit_count/last_change_time, gated on can_edit_comments, hidden revisions counted for admins only, wired directly into core.

★ Insight ─────────────────────────────────────

  • Your test env needs zero param setup for this: edit_comments_group defaults to editbugs and edit_comments_admins_group to admin (extensions/EditComments/Extension.pm:406-418), so unprivileged / editbugs / admin in qa/config/selenium_test.conf map exactly onto the three visibility tiers.
  • Stashing on $comment->{edit_info} is safe against cross-user leakage: Bugzilla::Object::new writes to memcached from the raw $data hashref before new_from_hash (Bugzilla/Object.pm:87-96), so post-load mutations never get serialized.
  • scripts/perl-fmt.pl reflowed ~120 unrelated lines of Bug.pm (the file isn't perltidy-clean at HEAD). I reverted that and hand-matched the style, so the diff is +67/-0. Worth knowing before you run it on any large legacy file.
    ─────────────────────────────────────────────────

@dklawren
dklawren requested review from Xzzz and cgsheeh and a balanced review from Copilot August 7, 2026 20:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds REST comment edit metadata with permission-aware visibility.

Changes:

  • Preloads and serializes edit counts and timestamps.
  • Documents the new fields.
  • Adds REST integration tests for comment endpoints.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
Bugzilla/WebService/Bug.pm Adds metadata loading and serialization.
docs/en/rst/api/core/v1/comment.rst Documents new response fields.
qa/t/rest_bug_comment_edits.t Tests visibility and edit metadata.
Suppressed comments (1)

Bugzilla/WebService/Bug.pm:1650

  • _bug_to_hash is invoked once per result in get, search, and duplicate queries, so preloading here issues an additional aggregation query for every returned bug whenever comments are requested. This defeats the stated request-level batching and can substantially increase query count for bulk results; preload comment metadata across the result set before serializing individual bugs.
    $self->_preload_comment_edit_info($comments);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +123 to +124
# The bug-level route uses a separate code path, so check it too.
$t->get_ok($url . 'rest/bug/public_bug/comment' => api_headers($editbugs_key))
Comment thread Bugzilla/WebService/Bug.pm Outdated
my $comments
= $bug->comments({order => 'oldest_to_newest', after => $params->{new_since}
});
$self->_preload_comment_edit_info($comments);

@Xzzz Xzzz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No correctness, security, or leak issues found. Visibility gating, hidden-revision handling, and null-handling all check out against the actual schema and framework internals.
Checks coverage hits all three visibility tiers across all three code paths (comment-id route, bug-comment route, Bug.get).
This looks good to me, I'd approve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants