From 05e14287f356c8f1308c339e9dbac83011940430 Mon Sep 17 00:00:00 2001 From: Gervase Markham Date: Mon, 7 Nov 2011 16:10:18 -0500 Subject: Bug 682847 - Create request flag whining extension r=dkl --- extensions/RequestWhiner/Config.pm | 33 +++++ extensions/RequestWhiner/Extension.pm | 30 ++++ extensions/RequestWhiner/bin/whineatrequests.pl | 152 +++++++++++++++++++++ extensions/RequestWhiner/lib/Constants.pm | 31 +++++ .../en/default/requestwhiner/mail.html.tmpl | 54 ++++++++ .../en/default/requestwhiner/mail.txt.tmpl | 38 ++++++ 6 files changed, 338 insertions(+) create mode 100644 extensions/RequestWhiner/Config.pm create mode 100644 extensions/RequestWhiner/Extension.pm create mode 100644 extensions/RequestWhiner/bin/whineatrequests.pl create mode 100644 extensions/RequestWhiner/lib/Constants.pm create mode 100644 extensions/RequestWhiner/template/en/default/requestwhiner/mail.html.tmpl create mode 100644 extensions/RequestWhiner/template/en/default/requestwhiner/mail.txt.tmpl (limited to 'extensions') diff --git a/extensions/RequestWhiner/Config.pm b/extensions/RequestWhiner/Config.pm new file mode 100644 index 000000000..fb08bd7af --- /dev/null +++ b/extensions/RequestWhiner/Config.pm @@ -0,0 +1,33 @@ +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the RequestWhiner Bugzilla Extension. +# +# The Initial Developer of the Original Code is Gervase Markham +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Gervase Markham + +package Bugzilla::Extension::RequestWhiner; +use strict; + +use constant NAME => 'RequestWhiner'; + +use constant REQUIRED_MODULES => [ +]; + +use constant OPTIONAL_MODULES => [ +]; + +__PACKAGE__->NAME; \ No newline at end of file diff --git a/extensions/RequestWhiner/Extension.pm b/extensions/RequestWhiner/Extension.pm new file mode 100644 index 000000000..de047e4f8 --- /dev/null +++ b/extensions/RequestWhiner/Extension.pm @@ -0,0 +1,30 @@ +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the RequestWhiner Bugzilla Extension. +# +# The Initial Developer of the Original Code is the Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Gervase Markham + +package Bugzilla::Extension::RequestWhiner; +use strict; +use base qw(Bugzilla::Extension); + +our $VERSION = '0.01'; + +# All the code is in the script in bin/. + +__PACKAGE__->NAME; diff --git a/extensions/RequestWhiner/bin/whineatrequests.pl b/extensions/RequestWhiner/bin/whineatrequests.pl new file mode 100644 index 000000000..622438b4f --- /dev/null +++ b/extensions/RequestWhiner/bin/whineatrequests.pl @@ -0,0 +1,152 @@ +#!/usr/bin/perl -wT +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): Erik Stambaugh +# Gervase Markham + +use strict; + +BEGIN { + use lib qw(lib .); + use Bugzilla; + Bugzilla->extensions; +} + +use lib qw(. lib); + +use Bugzilla; +use Bugzilla::User; +use Bugzilla::Mailer; +use Bugzilla::Extension::RequestWhiner::Constants; + +my $dbh = Bugzilla->dbh; + +my $sth_get_requests = + $dbh->prepare("SELECT profiles.login_name, + flagtypes.name, + bugs.bug_id, + bugs.short_desc, " . + $dbh->sql_to_days('NOW()') . + " - " . + $dbh->sql_to_days('flags.modification_date') . " + AS age_in_days + FROM flags + JOIN bugs ON bugs.bug_id = flags.bug_id, + flagtypes, + profiles + WHERE flags.status = '?' + AND flags.requestee_id = profiles.userid + AND flags.type_id = flagtypes.id + AND " . $dbh->sql_to_days('NOW()') . + " - " . + $dbh->sql_to_days('flags.modification_date') . + " > " . + WHINE_AFTER_DAYS . " + ORDER BY flags.modification_date"); + +$sth_get_requests->execute(); + +# Build data structure +my $requests = {}; + +while (my ($login_name, + $flag_name, + $bug_id, + $short_desc, + $age_in_days) = $sth_get_requests->fetchrow_array()) +{ + if (!defined($requests->{$login_name})) { + $requests->{$login_name} = {}; + } + + if (!defined($requests->{$login_name}->{$flag_name})) { + $requests->{$login_name}->{$flag_name} = []; + } + + push(@{ $requests->{$login_name}->{$flag_name} }, { + id => $bug_id, + summary => $short_desc, + age => $age_in_days + }); +} + +$sth_get_requests->finish(); + +foreach my $recipient (keys %$requests) { + my $user = new Bugzilla::User({ name => $recipient }); + + next if $user->email_disabled; + + mail({ + from => Bugzilla->params->{'mailfrom'}, + recipient => $user, + subject => "Outstanding Requests", + requests => $requests->{$recipient}, + threshold => WHINE_AFTER_DAYS + }); +} + +exit; + +############################################################################### +# Functions +# +# Note: this function is exactly the same as the one in whine.pl, just using +# different templates for the messages themselves. +############################################################################### +sub mail { + my $args = shift; + my $addressee = $args->{recipient}; + + my $template = + Bugzilla->template_inner($addressee->settings->{'lang'}->{'value'}); + my $msg = ''; # it's a temporary variable to hold the template output + $args->{'alternatives'} ||= []; + + # Put together the different multipart MIME segments + $template->process("requestwhiner/mail.txt.tmpl", $args, \$msg) + or die($template->error()); + push @{$args->{'alternatives'}}, + { + 'content' => $msg, + 'type' => 'text/plain', + }; + $msg = ''; + + $template->process("requestwhiner/mail.html.tmpl", $args, \$msg) + or die($template->error()); + push @{$args->{'alternatives'}}, + { + 'content' => $msg, + 'type' => 'text/html', + }; + $msg = ''; + + # Now produce a ready-to-mail MIME-encoded message + $args->{'boundary'} = "----------" . $$ . "--" . time() . "-----"; + + $template->process("whine/multipart-mime.txt.tmpl", $args, \$msg) + or die($template->error()); + + MessageToMTA($msg); + + delete $args->{'boundary'}; + delete $args->{'alternatives'}; +} diff --git a/extensions/RequestWhiner/lib/Constants.pm b/extensions/RequestWhiner/lib/Constants.pm new file mode 100644 index 000000000..0e24ae1f0 --- /dev/null +++ b/extensions/RequestWhiner/lib/Constants.pm @@ -0,0 +1,31 @@ +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the RequestWhiner Bugzilla Extension. +# +# The Initial Developer of the Original Code is the Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Gervase Markham + +package Bugzilla::Extension::RequestWhiner::Constants; +use strict; +use base qw(Exporter); +our @EXPORT = qw( + WHINE_AFTER_DAYS +); + +use constant WHINE_AFTER_DAYS => 7; + +1; diff --git a/extensions/RequestWhiner/template/en/default/requestwhiner/mail.html.tmpl b/extensions/RequestWhiner/template/en/default/requestwhiner/mail.html.tmpl new file mode 100644 index 000000000..de2c4dc6a --- /dev/null +++ b/extensions/RequestWhiner/template/en/default/requestwhiner/mail.html.tmpl @@ -0,0 +1,54 @@ +[%# The contents of this file are subject to the Mozilla Public + # License Version 1.1 (the "License"); you may not use this file + # except in compliance with the License. You may obtain a copy of + # the License at http://www.mozilla.org/MPL/ + # + # Software distributed under the License is distributed on an "AS + # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + # implied. See the License for the specific language governing + # rights and limitations under the License. + # + # The Original Code is the RequestWhiner Bugzilla Extension. + # + # The Initial Developer of the Original Code is Gervase Markham + # Portions created by the Initial Developer are Copyright (C) 2011 the + # Initial Developer. All Rights Reserved. + # + # Contributor(s): Gervase Markham + #%] + +[% PROCESS global/variables.none.tmpl %] +[% PROCESS 'global/field-descs.none.tmpl' %] + + + + + + [[% terms.Bugzilla %]] [% subject FILTER html %] + + + + +

Here are your outstanding requests older than [% threshold FILTER html%] +days:

+ +[% FOREACH request = requests.keys %] +

[% request FILTER html %]

+ + + +[% END %] + +

See all your outstanding requests.

+ +

A href="https://wiki.mozilla.org/BMO/Handling_Requests">Get guidance on handling requests.

+ + + diff --git a/extensions/RequestWhiner/template/en/default/requestwhiner/mail.txt.tmpl b/extensions/RequestWhiner/template/en/default/requestwhiner/mail.txt.tmpl new file mode 100644 index 000000000..a7cfd9668 --- /dev/null +++ b/extensions/RequestWhiner/template/en/default/requestwhiner/mail.txt.tmpl @@ -0,0 +1,38 @@ +[%# The contents of this file are subject to the Mozilla Public + # License Version 1.1 (the "License"); you may not use this file + # except in compliance with the License. You may obtain a copy of + # the License at http://www.mozilla.org/MPL/ + # + # Software distributed under the License is distributed on an "AS + # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + # implied. See the License for the specific language governing + # rights and limitations under the License. + # + # The Original Code is the RequestWhiner Bugzilla Extension. + # + # The Initial Developer of the Original Code is Gervase Markham + # Portions created by the Initial Developer are Copyright (C) 2011 the + # Initial Developer. All Rights Reserved. + # + # Contributor(s): Gervase Markham + #%] + +[% PROCESS global/variables.none.tmpl %] +[% PROCESS 'global/field-descs.none.tmpl' %] + +Here are your outstanding requests older than [% threshold %] days: + +[% FOREACH request = requests.keys %] +[%+ request +%] +[%+ "-" FILTER repeat(request.length) +%] + + [% FOREACH bug = requests.$request %] + [%+ terms.Bug +%] [%+ bug.id %]: [% bug.summary +%] ([% bug.age %] days old) + [%+ urlbase %]show_bug.cgi?id=[% bug.id +%] + [%+ END +%] +[% END %] +To see all your outstanding requests, visit: +[%+ urlbase %]request.cgi?action=queue&requestee=[% recipient.email FILTER uri %]&group=type + +For guidance on handling requests, see: +https://wiki.mozilla.org/BMO/Handling_Requests -- cgit v1.2.3-24-g4f1b