diff options
author | Frédéric Buclin <LpSolit@netscape.net> | 2016-02-24 00:43:00 +0100 |
---|---|---|
committer | Frédéric Buclin <LpSolit@netscape.net> | 2016-02-24 00:43:00 +0100 |
commit | 9f4329cfd4ccf1e3030e131299a028df4a6c30df (patch) | |
tree | dbf70060cd59dbe33685bb18e597ef0e23f7dca6 /extensions/Mageia/Extension.pm | |
parent | bb909eae7218de25805d80a442c6c59e89760df9 (diff) | |
download | bugs-9f4329cf.tar bugs-9f4329cf.tar.gz bugs-9f4329cf.tar.bz2 bugs-9f4329cf.tar.xz bugs-9f4329cf.zip |
Import Mageia extension - version 5.0
Diffstat (limited to 'extensions/Mageia/Extension.pm')
-rw-r--r-- | extensions/Mageia/Extension.pm | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/extensions/Mageia/Extension.pm b/extensions/Mageia/Extension.pm new file mode 100644 index 000000000..5580e583a --- /dev/null +++ b/extensions/Mageia/Extension.pm @@ -0,0 +1,111 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Extension::Mageia; + +use 5.10.1; +use strict; +use warnings; + +use parent qw(Bugzilla::Extension); + +use Bugzilla::Bug qw(LogActivityEntry); +use Bugzilla::Field qw(get_field_id); +use Bugzilla::User qw(); +use Bugzilla::Extension::Mageia::Util; + +use Email::Address; +use Encode qw(encode); + +# Let's match the Bugzilla version it's written for. +our $VERSION = '5.0'; + +# sysadmin-bugs@ml.mageia.org user ID = 175. +use constant SYSADMIN_USER_ID => 175; + +sub bug_end_of_create_validators { + my ($self, $args) = @_; + + # If a user enters 'validated_update' as keyword, + # automatically CC sysadmin-bugs@ml.mageia.org. + my $keywords = $args->{params}->{keywords}; + + if (grep { $_->name eq 'validated_update' } @$keywords) { + my $cc_list = $args->{params}->{cc}; + if (!grep { $_ == SYSADMIN_USER_ID } @$cc_list) { + push(@$cc_list, SYSADMIN_USER_ID); + } + } +} + +sub bug_end_of_update { + my ($self, $args) = @_; + my $bug = $args->{bug}; + my $dbh = Bugzilla->dbh; + my $user = Bugzilla->user; + + # If a user enters 'validated_update' as keyword, + # automatically CC sysadmin-bugs@ml.mageia.org. + my $new_keywords_str = $args->{changes}->{keywords}->[1]; + + if ($new_keywords_str) { + my @new_keywords = split(/[,\s]+/, $new_keywords_str); + if (grep { $_ eq 'validated_update' } @new_keywords + and !grep { $_->id == SYSADMIN_USER_ID } @{$bug->cc_users}) + { + # Safer to clear the cache and let Bugzilla regenerate them if needed. + delete $bug->{cc_users}; + delete $bug->{cc}; + $dbh->do('INSERT INTO cc (bug_id, who) VALUES (?, ?)', + undef, ($bug->id, SYSADMIN_USER_ID)); + + # We also have to update the bug history to reflect this change. + my $changed_cc = $args->{changes}->{cc}; + my $sysadmin_login = Bugzilla::User->new(SYSADMIN_USER_ID)->login; + + if ($changed_cc->[1]) { + $changed_cc->[1] .= ", $sysadmin_login"; + } + else { + $changed_cc->[1] = $sysadmin_login; + } + + my $field_id = get_field_id('cc'); + $dbh->do('DELETE FROM bugs_activity + WHERE bug_id = ? AND bug_when = ? AND fieldid = ?', + undef, ($bug->id, $args->{timestamp}, $field_id)); + + LogActivityEntry($bug->id, 'cc', $changed_cc->[0] // '', $changed_cc->[1], + $user->id, $args->{timestamp}); + } + } +} + +sub enter_bug_entrydefaultvars { + my ($self, $vars) = @_; + my $cgi = Bugzilla->cgi; + + # By default, users should get the guided form when reporting a new bug. + # Pass &normal=1 to the URL to get the official bug form. + my $format = $cgi->param('normal') ? '' : 'guided'; + $cgi->param('format', $format); +} + +sub mailer_before_send { + my ($self, $args) = @_; + my $email = $args->{email}; + + # Include the changer's name in the "From:" field. + if (my $changer = $email->header('X-Bugzilla-Who')) { + $changer = Bugzilla::User->new({ name => $changer }); + return unless $changer; + my $address = Email::Address->new($changer->name, $email->header('From')); + $email->header_set('From', encode('MIME-Header', $address->format)); + } +} + +__PACKAGE__->NAME; |