From: Kohei Yoshino Date: Tue, 18 Jun 2019 18:41:55 +0000 (-0400) Subject: Bug 1512497 - Comment editing should be listed on the bug history page and API X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=50b6208dc71be57664e52fbd469a3a3eac99090a;p=thirdparty%2Fbugzilla.git Bug 1512497 - Comment editing should be listed on the bug history page and API --- diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 6d529def6..30c9462d9 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -4493,7 +4493,7 @@ sub _bugs_in_order { # Get the activity of a bug, starting from $starttime (if given). # This routine assumes Bugzilla::Bug->check has been previously called. sub GetBugActivity { - my ($bug_id, $attach_id, $starttime, $include_comment_tags) = @_; + my ($bug_id, $attach_id, $starttime, $include_comment_activity) = @_; my $dbh = Bugzilla->dbh; # Arguments passed to the SQL query. @@ -4527,7 +4527,7 @@ sub GetBugActivity { = "SELECT DISTINCT fielddefs.name, bugs_activity.id AS activity_id, bugs_activity.attach_id, " - . $dbh->sql_date_format('bugs_activity.bug_when', '%Y.%m.%d %H:%i:%s') + . $dbh->sql_date_format('bugs_activity.bug_when', '%Y-%m-%d %H:%i:%s') . " AS bug_when, bugs_activity.removed, bugs_activity.added, profiles.login_name, bugs_activity.comment_id FROM bugs_activity @@ -4542,7 +4542,7 @@ sub GetBugActivity { $suppwhere "; if ( Bugzilla->params->{'comment_taggers_group'} - && $include_comment_tags + && $include_comment_activity && !$attach_id) { # Only includes comment tag activity for comments the user is allowed to see. @@ -4560,7 +4560,7 @@ sub GetBugActivity { NULL AS activity_id, NULL AS attach_id," . $dbh->sql_date_format('longdescs_tags_activity.bug_when', - '%Y.%m.%d %H:%i:%s') + '%Y-%m-%d %H:%i:%s') . " AS bug_when, longdescs_tags_activity.removed, longdescs_tags_activity.added, @@ -4581,6 +4581,20 @@ sub GetBugActivity { my $list = $dbh->selectall_arrayref($query, undef, @args); + Bugzilla::Hook::process( + 'get_bug_activity', + { + bug_id => $bug_id, + attach_id => $attach_id, + start_time => $starttime, + include_comment_activity => $include_comment_activity, + list => \@$list + } + ); + + # ORDER BY bug_when + @$list = sort { $a->[3] cmp $b->[3] } @$list; + my @operations; my $operation = {}; my $changes = []; diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 15c7b5446..4bd8fa0da 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -297,6 +297,40 @@ The hash of changed fields. C<< $changes->{field} = [old, new] >> =back +=head2 get_bug_activity + +This happens in L, where you can add custom bug +activity, such as comment revisions, if needed. + +Params: + +=over + +=item C + +The bug ID that the activity belongs to. + +=item C + +An optional attachment ID that filters the activity. + +=item C + +An optional time that filters the activity. + +=item C + +Whether any comment activity, including comment tags, should be included. + +=item C + +The core activity list that you can extend or modify in a hook. An list item is +an array that should contain field name, activity ID (can be undef), attach ID +(can be undef), timestamp, removed value, added value, user name and comment ID +(can be undef). + +=back + =head2 bug_check_can_change_field This hook controls what fields users are allowed to change. You can add code diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index f60b7fa36..107313db6 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -523,7 +523,7 @@ sub history { $item{id} = $self->type('int', $bug_id); my ($activity) - = Bugzilla::Bug::GetBugActivity($bug_id, undef, $params->{new_since}); + = Bugzilla::Bug::GetBugActivity($bug_id, undef, $params->{new_since}, 1); my @history; foreach my $changeset (@$activity) { @@ -1533,7 +1533,7 @@ sub _bug_to_hash { if (filter_wants $params, 'history', ['extra']) { my @result; my ($activity) - = Bugzilla::Bug::GetBugActivity($bug->id, undef, $params->{new_since}); + = Bugzilla::Bug::GetBugActivity($bug->id, undef, $params->{new_since}, 1); foreach my $changeset (@$activity) { push(@result, $self->_changeset_to_hash($changeset, $params, ['extra'], 'history')); @@ -1737,11 +1737,14 @@ sub _changeset_to_hash { my $api_field_type = $api_field_types{$field_name} || 'string'; my $api_field_name = $api_field_names{$field_name} || $field_name; my $attach_id = delete $change->{attachid}; + my $comment = delete $change->{comment}; $change->{field_name} = $self->type('string', $api_field_name); $change->{removed} = $self->type($api_field_type, $change->{removed}); $change->{added} = $self->type($api_field_type, $change->{added}); $change->{attachment_id} = $self->type('int', $attach_id) if $attach_id; + $change->{comment_id} = $self->type('int', $comment->id) if $comment; + $change->{comment_count} = $self->type('int', $comment->count) if $comment; push (@{$item->{changes}}, $change); } diff --git a/extensions/EditComments/Extension.pm b/extensions/EditComments/Extension.pm index 519224790..5fda9d870 100644 --- a/extensions/EditComments/Extension.pm +++ b/extensions/EditComments/Extension.pm @@ -262,6 +262,44 @@ sub config_modify_panels { }; } +sub get_bug_activity { + my ($self, $args) = @_; + + return unless $args->{include_comment_activity}; + + my $list = $args->{list}; + my $is_insider = Bugzilla->user->is_insider; + my $hidden_placeholder = '(Hidden by Administrator)'; + + my $edited_comment_ids + = Bugzilla->dbh->selectcol_arrayref(' + SELECT DISTINCT(c.comment_id) from longdescs_activity AS a + INNER JOIN longdescs AS c ON c.comment_id = a.comment_id AND c.bug_id = ? + ' . ($is_insider ? '' : 'AND c.isprivate = 0'), undef, $args->{bug_id}); + + foreach my $comment_id (@$edited_comment_ids) { + my $prev_rev = {}; + + foreach my $revision (@{Bugzilla::Comment->new($comment_id)->activity}) { + # Exclude original comment, because we are interested only in revisions + if ($revision->{old}) { + push(@$list, [ + 'comment_revision', + undef, + undef, + $revision->{created_time}, + $prev_rev->{is_hidden} && !$is_insider ? $hidden_placeholder : $revision->{old}, + $revision->{is_hidden} && !$is_insider ? $hidden_placeholder : $revision->{new}, + $revision->{author}->{login_name}, + $comment_id + ]); + } + + $prev_rev = $revision; + } + } +} + sub webservice { my ($self, $args) = @_; my $dispatch = $args->{dispatch};