diff options
author | Frédéric Buclin <LpSolit@netscape.net> | 2017-08-02 12:59:20 +0200 |
---|---|---|
committer | Frédéric Buclin <LpSolit@netscape.net> | 2017-08-02 12:59:20 +0200 |
commit | 8d9c748a5e694fb544c082128c9756a0ca702334 (patch) | |
tree | bdbeb505e609ecba2861aa666b7f8ef157ba2c5d /extensions/Mageia/Extension.pm | |
parent | 775362d8fb630da4fbb1e3f75c45183fd0a28667 (diff) | |
download | bugs-8d9c748a5e694fb544c082128c9756a0ca702334.tar bugs-8d9c748a5e694fb544c082128c9756a0ca702334.tar.gz bugs-8d9c748a5e694fb544c082128c9756a0ca702334.tar.bz2 bugs-8d9c748a5e694fb544c082128c9756a0ca702334.tar.xz bugs-8d9c748a5e694fb544c082128c9756a0ca702334.zip |
Implement inline history
Diffstat (limited to 'extensions/Mageia/Extension.pm')
-rw-r--r-- | extensions/Mageia/Extension.pm | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/extensions/Mageia/Extension.pm b/extensions/Mageia/Extension.pm index 60ca57f00..982a3bdb7 100644 --- a/extensions/Mageia/Extension.pm +++ b/extensions/Mageia/Extension.pm @@ -17,7 +17,8 @@ use Bugzilla::Constants qw(EVT_CC REL_GLOBAL_WATCHER); use Bugzilla::Bug qw(LogActivityEntry); use Bugzilla::Field qw(get_field_id); use Bugzilla::User qw(); -use Bugzilla::Extension::Mageia::Util; +use Bugzilla::User::Setting qw(add_setting); +use Bugzilla::Extension::Mageia::Util qw(compare_datetimes); use Email::Address; use Encode qw(encode); @@ -28,6 +29,10 @@ our $VERSION = '5.0'; # sysadmin-bugs@ml.mageia.org user ID = 175. use constant SYSADMIN_USER_ID => 175; +use constant MGA_SETTINGS => { + mga_inline_history => { options => ['on', 'off'], default => 'on' }, +}; + sub bug_end_of_create_validators { my ($self, $args) = @_; @@ -110,6 +115,14 @@ sub enter_bug_entrydefaultvars { $cgi->param('format', $format); } +sub install_before_final_checks { + # A hook in Bugzilla::Install::SETTINGS() would be much cleaner. :( + my %settings = %{MGA_SETTINGS()}; + foreach my $setting (keys %settings) { + add_setting($setting, $settings{$setting}->{options}, $settings{$setting}->{default}); + } +} + sub mailer_before_send { my ($self, $args) = @_; my $email = $args->{email}; @@ -123,6 +136,43 @@ sub mailer_before_send { } } +sub template_before_process { + my ($self, $args) = @_; + _inline_history($args) if $args->{file} eq 'bug/comments.html.tmpl'; +} + +sub _inline_history { + my $args = shift; + my $user = Bugzilla->user; + return if $user->setting('mga_inline_history') eq 'off'; + # Only display the bug history in chronological order. + return if $user->setting('comment_sort_order') ne 'oldest_to_newest'; + + my $bug = $args->{vars}->{bug}; + my ($history) = $bug->get_activity(); + # Filter private comments that the user is not allowed to see. + my @comments = grep { !$_->is_private || $user->is_insider || $user->id == $_->author->id } @{ $bug->comments }; + my %h_times = map { $_->{when} => $_ } @$history; + my %c_times = map { $_->creation_ts => $_ } @comments; + my @all_times = sort { compare_datetimes($a, $b) } (keys %c_times, keys %h_times); + my $curr_comment; + + foreach my $time (@all_times) { + if ($c_times{$time}) { + $curr_comment = $c_times{$time}; + $curr_comment->{inline_history} //= []; + } + if (my $activity = $h_times{$time}) { + # If we have no visible comment to attach the activity to, then ignore it. + # This can happen if the initial comment (comment 0) is private. + next unless $curr_comment; + $activity->{after} = compare_datetimes($time, $curr_comment->creation_ts); + $activity->{who} = new Bugzilla::User({ name => $activity->{who}, cache => 1 }); + push(@{ $curr_comment->{inline_history} }, $activity); + } + } +} + sub user_wants_mail { my ($self, $args) = @_; return unless $args->{relationship} == REL_GLOBAL_WATCHER; |