]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1512497 - Comment editing should be listed on the bug history page and API
authorKohei Yoshino <kohei.yoshino@gmail.com>
Tue, 18 Jun 2019 18:41:55 +0000 (14:41 -0400)
committerGitHub <noreply@github.com>
Tue, 18 Jun 2019 18:41:55 +0000 (14:41 -0400)
Bugzilla/Bug.pm
Bugzilla/Hook.pm
Bugzilla/WebService/Bug.pm
extensions/EditComments/Extension.pm

index 6d529def6a5a18f16ddfd325a53a6f87b442cbf1..30c9462d9dead6a348acfc45b69242c48356f2e2 100644 (file)
@@ -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         = [];
index 15c7b5446981287a6d275c30044ae86346cf6980..4bd8fa0daf9d9b8f5bdb06907b0bd5ad99b9bde9 100644 (file)
@@ -297,6 +297,40 @@ The hash of changed fields. C<< $changes->{field} = [old, new] >>
 
 =back
 
+=head2 get_bug_activity
+
+This happens in L<Bugzilla::Bug::GetBugActivity>, where you can add custom bug
+activity, such as comment revisions, if needed.
+
+Params:
+
+=over
+
+=item C<bug_id>
+
+The bug ID that the activity belongs to.
+
+=item C<attach_id>
+
+An optional attachment ID that filters the activity.
+
+=item C<start_time>
+
+An optional time that filters the activity.
+
+=item C<include_comment_activity>
+
+Whether any comment activity, including comment tags, should be included.
+
+=item C<list>
+
+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
index f60b7fa36fa62be18ad966002038b18be0e3b101..107313db602072f369f69ed11af9e1564abb5967 100644 (file)
@@ -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);
   }
index 51922479062c59f10dbfa9f4fa4b34ca27bea1df..5fda9d870e6a0978cc65e629df7b32c2e5d3ca94 100644 (file)
@@ -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};