summaryrefslogtreecommitdiffstats
path: root/extensions/RequestNagger
diff options
context:
space:
mode:
authorByron Jones <glob@mozilla.com>2015-05-27 08:32:13 +0200
committerByron Jones <glob@mozilla.com>2015-05-27 08:32:13 +0200
commitb03427e7ee68f39b715d921354bfc23a2e6af37a (patch)
treea4f6e3011cc013cc7f09364252b2ed93fad02b4c /extensions/RequestNagger
parent776ee55030257105efd7df2196d9aee01e8281ad (diff)
downloadbugzilla-b03427e7ee68f39b715d921354bfc23a2e6af37a.tar.gz
bugzilla-b03427e7ee68f39b715d921354bfc23a2e6af37a.tar.xz
Bug 1164850: add preferences to request nagging watching facility (reviews only, extended period, and skip encryption)
Diffstat (limited to 'extensions/RequestNagger')
-rw-r--r--extensions/RequestNagger/Extension.pm13
-rwxr-xr-xextensions/RequestNagger/bin/send-request-nags.pl7
-rw-r--r--extensions/RequestNagger/lib/Constants.pm33
-rw-r--r--extensions/RequestNagger/lib/Settings.pm61
-rw-r--r--extensions/RequestNagger/template/en/default/account/prefs/request_nagging.html.tmpl15
5 files changed, 118 insertions, 11 deletions
diff --git a/extensions/RequestNagger/Extension.pm b/extensions/RequestNagger/Extension.pm
index fa570edab..169f76b1e 100644
--- a/extensions/RequestNagger/Extension.pm
+++ b/extensions/RequestNagger/Extension.pm
@@ -14,6 +14,7 @@ use base qw(Bugzilla::Extension);
use Bugzilla::Constants;
use Bugzilla::Error;
+use Bugzilla::Extension::RequestNagger::Settings;
use Bugzilla::Flag;
use Bugzilla::Install::Filesystem;
use Bugzilla::User::Setting;
@@ -163,10 +164,6 @@ sub _defer_until {
$dbh->bz_commit_transaction();
}
-#
-# hooks
-#
-
sub object_end_of_update {
my ($self, $args) = @_;
if ($args->{object}->isa("Bugzilla::Flag") && exists $args->{changes}) {
@@ -198,6 +195,8 @@ sub user_preferences {
$user->id
) };
+ my $nag_settings = Bugzilla::Extension::RequestNagger::Settings->new($user->id);
+
if ($save) {
my $input = Bugzilla->input_params;
Bugzilla::User::match_field({ 'add_watching' => {'type' => 'multi'} });
@@ -247,10 +246,16 @@ sub user_preferences {
}
}
+ # watching settings
+ foreach my $field (Bugzilla::Extension::RequestNagger::Settings::FIELDS()) {
+ $nag_settings->set($field, $input->{$field});
+ }
+
$dbh->bz_commit_transaction();
}
$vars->{watching} = [ sort keys %watching ];
+ $vars->{settings} = $nag_settings;
my $handled = $args->{'handled'};
$$handled = 1;
diff --git a/extensions/RequestNagger/bin/send-request-nags.pl b/extensions/RequestNagger/bin/send-request-nags.pl
index 8aea0c0ab..22a4baa54 100755
--- a/extensions/RequestNagger/bin/send-request-nags.pl
+++ b/extensions/RequestNagger/bin/send-request-nags.pl
@@ -23,6 +23,7 @@ use Bugzilla::Hook;
use Bugzilla::Error;
use Bugzilla::Extension::RequestNagger::Constants;
use Bugzilla::Extension::RequestNagger::Bug;
+use Bugzilla::Extension::RequestNagger::Settings;
use Bugzilla::Mailer;
use Bugzilla::User;
use Bugzilla::Util qw(format_time);
@@ -173,11 +174,17 @@ sub _send_email {
my @reports = qw( requestee setter );
my $recipient_id = $params->{recipient_id};
my $requests = $params->{requests};
+ my $watching = $params{template} eq 'watching';
my $recipient = Bugzilla::User->new({ id => $recipient_id, cache => 1 });
my $securemail = Bugzilla::User->can('public_key');
my $has_key = $securemail && $recipient->public_key;
my $has_private_bug = 0;
+ my $settings = Bugzilla::Extension::RequestNagger::Setting->new($recipient_id);
+ if ($watching && $setting->no_encryption) {
+ $has_key = 0;
+ }
+
foreach my $target_login (keys %$requests) {
my $rh = $requests->{$target_login};
$rh->{target} = Bugzilla::User->new({ name => $target_login, cache => 1 });
diff --git a/extensions/RequestNagger/lib/Constants.pm b/extensions/RequestNagger/lib/Constants.pm
index 899336a72..66780ad63 100644
--- a/extensions/RequestNagger/lib/Constants.pm
+++ b/extensions/RequestNagger/lib/Constants.pm
@@ -147,12 +147,22 @@ sub WATCHING_REQUESTEE_NAG_SQL {
LEFT JOIN nag_defer ON nag_defer.flag_id = flags.id
INNER JOIN nag_watch ON nag_watch.nagged_id = flags.requestee_id
INNER JOIN profiles AS watcher ON watcher.userid = nag_watch.watcher_id
+ LEFT JOIN nag_settings AS reviews_only ON reviews_only.user_id = nag_watch.watcher_id
+ AND reviews_only.setting_name = 'reviews_only'
+ LEFT JOIN nag_settings AS extended_period ON extended_period.user_id = nag_watch.watcher_id
+ AND extended_period.setting_name = 'extended_period'
WHERE
- " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
- AND flags.status = '?'
+ flags.status = '?'
AND products.nag_interval != 0
- AND TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
AND watcher.disable_mail = 0
+ AND CASE WHEN COALESCE(reviews_only.setting_value, 0) = 1
+ THEN flagtypes.name = 'review'
+ ELSE " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
+ END
+ AND CASE WHEN COALESCE(extended_period.setting_value, 0) = 1
+ THEN TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval + 24
+ ELSE TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
+ END
ORDER BY
nag_watch.watcher_id,
flags.requestee_id,
@@ -187,12 +197,22 @@ sub WATCHING_SETTER_NAG_SQL {
LEFT JOIN nag_defer ON nag_defer.flag_id = flags.id
INNER JOIN nag_watch ON nag_watch.nagged_id = flags.setter_id
INNER JOIN profiles AS watcher ON watcher.userid = nag_watch.watcher_id
+ LEFT JOIN nag_settings AS reviews_only ON reviews_only.user_id = nag_watch.watcher_id
+ AND reviews_only.setting_name = 'reviews_only'
+ LEFT JOIN nag_settings AS extended_period ON extended_period.user_id = nag_watch.watcher_id
+ AND extended_period.setting_name = 'extended_period'
WHERE
- " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
- AND flags.status = '?'
+ flags.status = '?'
AND products.nag_interval != 0
- AND TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
AND watcher.disable_mail = 0
+ AND CASE WHEN COALESCE(reviews_only.setting_value, 0) = 1
+ THEN flagtypes.name = 'review'
+ ELSE " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
+ END
+ AND CASE WHEN COALESCE(extended_period.setting_value, 0) = 1
+ THEN TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval + 24
+ ELSE TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
+ END
ORDER BY
nag_watch.watcher_id,
flags.requestee_id,
@@ -200,5 +220,4 @@ sub WATCHING_SETTER_NAG_SQL {
";
}
-
1;
diff --git a/extensions/RequestNagger/lib/Settings.pm b/extensions/RequestNagger/lib/Settings.pm
new file mode 100644
index 000000000..5407eac1d
--- /dev/null
+++ b/extensions/RequestNagger/lib/Settings.pm
@@ -0,0 +1,61 @@
+# 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::RequestNagger::Settings;
+use strict;
+use warnings;
+
+use Bugzilla;
+use List::MoreUtils qw( any );
+
+use constant FIELDS => qw( reviews_only extended_period no_encryption );
+
+sub new {
+ my ($class, $user_id) = @_;
+
+ my $dbh = Bugzilla->dbh;
+ my $self = { user_id => $user_id };
+ foreach my $row (@{ $dbh->selectall_arrayref(
+ "SELECT setting_name,setting_value FROM nag_settings WHERE user_id = ?",
+ { Slice => {} },
+ $user_id
+ ) }) {
+ $self->{$row->{setting_name}} = $row->{setting_value};
+ }
+
+ return bless($self, $class);
+}
+
+sub reviews_only { exists $_[0]->{reviews_only} ? $_[0]->{reviews_only} : 0 }
+sub extended_period { exists $_[0]->{extended_period} ? $_[0]->{extended_period} : 0 }
+sub no_encryption { exists $_[0]->{no_encryption} ? $_[0]->{no_encryption} : 0 }
+
+sub set {
+ my ($self, $field, $value) = @_;
+ return unless any { $_ eq $field } FIELDS;
+ $value = $value ? 1 : 0;
+
+ my $dbh = Bugzilla->dbh;
+ if (exists $self->{$field}) {
+ $dbh->do(
+ "UPDATE nag_settings SET setting_value=? WHERE user_id=? AND setting_name=?",
+ undef,
+ $value, $self->{user_id}, $field
+ );
+ }
+ else {
+ $dbh->do(
+ "INSERT INTO nag_settings(user_id, setting_name, setting_value) VALUES (?, ?, ?)",
+ undef,
+ $self->{user_id}, $field, $value
+ );
+ }
+
+ $self->{$field} = $value;
+}
+
+1;
diff --git a/extensions/RequestNagger/template/en/default/account/prefs/request_nagging.html.tmpl b/extensions/RequestNagger/template/en/default/account/prefs/request_nagging.html.tmpl
index 34bba0064..90f753903 100644
--- a/extensions/RequestNagger/template/en/default/account/prefs/request_nagging.html.tmpl
+++ b/extensions/RequestNagger/template/en/default/account/prefs/request_nagging.html.tmpl
@@ -54,3 +54,18 @@
multiple => 5
%]
</p>
+
+<h4>User Request Reminder Watching Preferences</h4>
+
+<input type="checkbox" id="reviews_only" name="reviews_only" value="1"
+ [%= "checked" IF settings.reviews_only %]>
+<label for="reviews_only">Report on review requests only</label><br>
+
+<input type="checkbox" id="extended_period" name="extended_period" value="1"
+ [%= "checked" IF settings.extended_period %]>
+<label for="extended_period">Extend overdue period by one day</label><br>
+
+<input type="checkbox" id="no_encryption" name="no_encryption" value="1"
+ [%= "checked" IF settings.no_encryption %]>
+<label for="no_encryption">Don't encrypt email (sensitive information will be sanitised)</label><br>
+<br>