]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 100953: Move data/nomail into the DB and implement a UI to edit it
authorkarl.kornel%mindspeed.com <>
Sun, 30 Jul 2006 10:50:24 +0000 (10:50 +0000)
committerkarl.kornel%mindspeed.com <>
Sun, 30 Jul 2006 10:50:24 +0000 (10:50 +0000)
Patch by A. Karl Kornel <karl@kornel.name> r=wurblzap a=justdave

Bugzilla/BugMail.pm
Bugzilla/DB/Schema.pm
Bugzilla/User.pm
checksetup.pl
editusers.cgi
template/en/default/admin/users/userdata.html.tmpl
template/en/default/global/messages.html.tmpl
whine.pl
whineatnews.pl

index 1b2fb5429cc9fea5b78afbe19e12b4c60331c729..dd92cd3b432b23766c44ef5e724059560c7558b5 100644 (file)
@@ -57,20 +57,6 @@ use constant REL_NAMES => {
     REL_VOTER   , "Voter"
 };
 
-sub _read_nomail {
-    my $nomail = Bugzilla->request_cache->{bugmail_nomail};
-    return $nomail if $nomail;
-    if (open(NOMAIL, '<', bz_locations->{'datadir'} . "/nomail")) {
-        while (<NOMAIL>) {
-            $nomail->{trim($_)} = 1;
-        }
-        close(NOMAIL);
-    }
-    Bugzilla->request_cache->{bugmail_nomail} = $nomail;
-    return $nomail;
-}
-
-
 sub FormatTriple {
     my ($a, $b, $c) = (@_);
     $^A = "";
@@ -465,8 +451,7 @@ sub ProcessOneBug {
 
             # Make sure the user isn't in the nomail list, and the insider and 
             # dep checks passed.
-            my $nomail = _read_nomail();
-            if ((!$nomail->{$user->login}) &&
+            if ($user->email_enabled &&
                 $insider_ok &&
                 $dep_ok)
             {
index 5396a3d20a2da219b2e928c51c78356a996e7347..9f46708455b6a8bf3777f81c00e026436eb30150 100644 (file)
@@ -614,6 +614,8 @@ use constant ABSTRACT_SCHEMA => {
             cryptpassword  => {TYPE => 'varchar(128)'},
             realname       => {TYPE => 'varchar(255)'},
             disabledtext   => {TYPE => 'MEDIUMTEXT', NOTNULL => 1},
+            disable_mail   => {TYPE => 'BOOLEAN', NOTNULL => 1,
+                               DEFAULT => 'FALSE'},
             mybugslink     => {TYPE => 'BOOLEAN', NOTNULL => 1,
                                DEFAULT => 'TRUE'},
             refreshed_when => {TYPE => 'DATETIME', NOTNULL => 1},
index 48502326e3439751c19fa8dc8aee5e698b445775..924cb051138e9901d10b1eb9426e1e5fff59a913 100644 (file)
@@ -122,6 +122,7 @@ sub _create {
         'showmybugslink' => 0,
         'disabledtext'   => '',
         'flags'          => {},
+        'disable_mail'   => 0,
     };
     bless ($self, $class);
     return $self unless $cond && $val;
@@ -131,9 +132,9 @@ sub _create {
 
     my $dbh = Bugzilla->dbh;
 
-    my ($id, $login, $name, $disabledtext, $mybugslink) =
+    my ($id, $login, $name, $disabledtext, $mybugslink, $disable_mail) =
         $dbh->selectrow_array(qq{SELECT userid, login_name, realname,
-                                        disabledtext, mybugslink
+                                        disabledtext, mybugslink, disable_mail 
                                  FROM profiles WHERE $cond},
                                  undef, $val);
 
@@ -144,6 +145,7 @@ sub _create {
     $self->{'login'}          = $login;
     $self->{'disabledtext'}   = $disabledtext;
     $self->{'showmybugslink'} = $mybugslink;
+    $self->{'disable_mail'}   = $disable_mail;
 
     return $self;
 }
@@ -156,6 +158,8 @@ sub name { $_[0]->{name}; }
 sub disabledtext { $_[0]->{'disabledtext'}; }
 sub is_disabled { $_[0]->disabledtext ? 1 : 0; }
 sub showmybugslink { $_[0]->{showmybugslink}; }
+sub email_disabled { $_[0]->{disable_mail}; }
+sub email_enabled { !($_[0]->{disable_mail}); }
 
 sub set_authorizer {
     my ($self, $authorizer) = @_;
@@ -1339,10 +1343,11 @@ sub get_userlist {
 }
 
 sub insert_new_user {
-    my ($username, $realname, $password, $disabledtext) = (@_);
+    my ($username, $realname, $password, $disabledtext, $disable_mail) = (@_);
     my $dbh = Bugzilla->dbh;
 
     $disabledtext ||= '';
+    $disable_mail ||= 0;
 
     # If not specified, generate a new random password for the user.
     # If the password is '*', do not encrypt it; we are creating a user
@@ -1358,10 +1363,11 @@ sub insert_new_user {
     # Insert the new user record into the database.
     $dbh->do("INSERT INTO profiles 
                           (login_name, realname, cryptpassword, disabledtext,
-                           refreshed_when) 
-                   VALUES (?, ?, ?, ?, '1901-01-01 00:00:00')",
+                           refreshed_when, disable_mail
+                   VALUES (?, ?, ?, ?, '1901-01-01 00:00:00', ?)",
              undef, 
-             ($username, $realname, $cryptpassword, $disabledtext));
+             ($username, $realname, $cryptpassword, $disabledtext, 
+              $disable_mail));
 
     # Turn on all email for the new user
     my $new_userid = $dbh->bz_last_key('profiles', 'userid');
@@ -1868,6 +1874,11 @@ Params: $username (scalar, string) - The login name for the new user.
                                          If given, the user will be disabled,
                                          meaning the account will be
                                          unavailable for login.
+        $disable_mail (scalar, boolean) - Optional, defaults to 0.
+                                          If 1, bug-related mail will not be 
+                                          sent to this user; if 0, mail will
+                                          be sent depending on the user's 
+                                          email preferences.
 
 Returns: The password for this user, in plain text, so it can be included
          in an e-mail sent to the user.
index 8f1fdd16769e6abe1abb3614692f36ca3fc66009..485173fb244bdcc80152420299f6e3240a397e76 100755 (executable)
@@ -3358,6 +3358,54 @@ if (!$dbh->bz_column_info('classifications', 'sortkey')) {
 $dbh->bz_add_column('fielddefs', 'enter_bug',
     {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
 
+# 2006-07-14 karl@kornel.name - Bug 100953
+# If a nomail file exists, move its contents into the DB
+$dbh->bz_add_column('profiles', 'disable_mail',
+                    { TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE' });
+if (-e "$datadir/nomail") {
+    # We have a data/nomail file, read it in and delete it
+    my %nomail;
+    print "Found a data/nomail file.  Moving nomail entries into DB...\n";
+    open NOMAIL, '<', "$datadir/nomail";
+    while (<NOMAIL>) {
+        $nomail{trim($_)} = 1;
+    }
+    close NOMAIL;
+
+    # Go through each entry read.  If a user exists, set disable_mail.
+    my $query = $dbh->prepare('UPDATE profiles
+                                  SET disable_mail = 1
+                                WHERE userid = ?');
+    foreach my $user_to_check (keys %nomail) {
+        my $uid;
+        if ($uid = Bugzilla::User::login_to_id($user_to_check)) {
+            my $user = new Bugzilla::User($uid);
+            print "\tDisabling email for user ", $user->email, "\n";
+            $query->execute($user->id);
+            delete $nomail{$user->email};
+        }
+    }
+
+    # If there are any nomail entries remaining, move them to nomail.bad
+    # and say something to the user.
+    if (scalar(keys %nomail)) {
+        print 'The following users were listed in data/nomail, but do not ' .
+              'have an account here.  The unmatched entries have been moved ' .
+              "to $datadir/nomail.bad\n";
+        open NOMAIL_BAD, '>>', "$datadir/nomail.bad";
+        foreach my $unknown_user (keys %nomail) {
+            print "\t$unknown_user\n";
+            print NOMAIL_BAD "$unknown_user\n";
+            delete $nomail{$unknown_user};
+        }
+        close NOMAIL_BAD;
+    }
+
+    # Now that we don't need it, get rid of the nomail file.
+    unlink "$datadir/nomail";
+}
+
+
 # If you had to change the --TABLE-- definition in any way, then add your
 # differential change code *** A B O V E *** this comment.
 #
index 4d72923919c7c9091d6ff3f31c55259d4a92e0bb..1809101d6998076c70d2b30ac60f627f9f72ae24 100755 (executable)
@@ -195,6 +195,7 @@ if ($action eq 'search') {
     my $password     = $cgi->param('password');
     my $realname     = trim($cgi->param('name')         || '');
     my $disabledtext = trim($cgi->param('disabledtext') || '');
+    my $disable_mail = $cgi->param('disable_mail') =~ /^(0|1)$/ ? $1 : 0;
 
     # Lock tables during the check+creation session.
     $dbh->bz_lock_tables('profiles WRITE', 'profiles_activity WRITE',
@@ -216,7 +217,7 @@ if ($action eq 'search') {
     trick_taint($password);
     trick_taint($disabledtext);
 
-    insert_new_user($login, $realname, $password, $disabledtext);
+    insert_new_user($login, $realname, $password, $disabledtext, $disable_mail);
     my $new_user_id = $dbh->bz_last_key('profiles', 'userid');
     $dbh->bz_unlock_tables();
     userDataToVars($new_user_id);
@@ -234,6 +235,7 @@ if ($action eq 'search') {
 } elsif ($action eq 'update') {
     my $otherUser = check_user($otherUserID, $otherUserLogin);
     $otherUserID = $otherUser->id;
+    my $oldprofile = new Bugzilla::User($otherUserID);
 
     my $logoutNeeded = 0;
     my @changedFields;
@@ -255,14 +257,17 @@ if ($action eq 'search') {
                                            object => "user"});
 
     # Cleanups
-    my $loginold        = $cgi->param('loginold')        || '';
-    my $realnameold     = $cgi->param('nameold')         || '';
-    my $disabledtextold = $cgi->param('disabledtextold') || '';
+    my $loginold         = $cgi->param('loginold')         || '';
+    my $realnameold      = $cgi->param('nameold')          || '';
+    my $disabledtextold  = $cgi->param('disabledtextold')  || '';
+    my $disable_mail_old = $cgi->param('disable_mail_old') =~ /^(0|1)$/ ? 
+                           $1 : $oldprofile->email_disabled;
 
     my $login        = $cgi->param('login');
     my $password     = $cgi->param('password');
     my $realname     = trim($cgi->param('name')         || '');
     my $disabledtext = trim($cgi->param('disabledtext') || '');
+    my $disable_mail = $cgi->param('disable_mail') =~ /^(0|1)$/ ? $1 : 0;
 
     # Update profiles table entry; silently skip doing this if the user
     # is not authorized.
@@ -308,6 +313,11 @@ if ($action eq 'search') {
             push(@values, $disabledtext);
             $logoutNeeded = 1;
         }
+        if ($disable_mail != $disable_mail_old) {
+            trick_taint($disable_mail);
+            push(@changedFields, 'disable_mail');
+            push(@values, $disable_mail);
+        }
         if (@changedFields) {
             push (@values, $otherUserID);
             $logoutNeeded && Bugzilla->logout_user($otherUser);
index afb4025542af89021b4257d76c98aea4ef10cda7..be29a1b4b8de50503fa356f693c36be957f515ac 100644 (file)
       [% END %]
     </td>
   </tr>
+  <tr>
+    <th><label for="disable_mail">Bugmail Disabled:</label></th>
+    <td>
+      <input type="checkbox" name="disable_mail" id="disable_mail" value="1" 
+      [% IF otheruser.email_disabled %] checked="checked" [% END %] />
+      (This affects bugmail and whinemail, not password-reset or other 
+      non-bug-related emails)
+      [% IF editform %]
+        <input type="hidden" name="disable_mail_old"
+          [% IF otheruser.email_disabled %]
+            value="1"
+          [% ELSE %]
+            value="0" 
+          [% END %]
+        />
+      [% END %]
+    </td>
+  </tr>
   <tr>
     <th><label for="disabledtext">Disable text:</label></th>
     <td>
index 45b584bea49b5f604c60a4324817d5f334c89cbc..08321ed2c27bf585528c1140b63355f0a6dd11f8 100644 (file)
               A new password has been set.
             [% ELSIF field == 'disabledtext' %]
               The disable text has been modified.
+            [% ELSIF field == 'disable_mail' %]
+              [% IF otheruser.email_disabled %]
+                Bugmail has been disabled.
+              [% ELSE %]
+                Bugmail has been enabled.
+              [% END %]
             [% END %]
           </li>
         [% END %]
index 8e60370a3571e78fc2e1638fc418c6f879aae338..12b03fb624a07823dd3f96c8f802dce5b78e50cf 100755 (executable)
--- a/whine.pl
+++ b/whine.pl
@@ -102,14 +102,6 @@ if ($fromaddress !~ Bugzilla->params->{'emailregexp'}) {
         "The maintainer email address has not been properly set!\n";
 }
 
-# Check the nomail file for users who should not receive mail
-my %nomail;
-if (open(NOMAIL, '<', bz_locations()->{'datadir'} . "/nomail")) {
-    while (<NOMAIL>) {
-        $nomail{trim($_)} = 1;
-    }
-}
-
 # get the current date and time
 my ($now_sec, $now_minute, $now_hour, $now_day, $now_month, $now_year, 
     $now_weekday) = localtime;
@@ -373,7 +365,7 @@ sub mail {
     my $args = shift;
 
     # Don't send mail to someone on the nomail list.
-    return if $nomail{$args->{'recipient'}->{'login'}};
+    return if $args->{recipient}->email_disabled;
 
     my $msg = ''; # it's a temporary variable to hold the template output
     $args->{'alternatives'} ||= [];
index 58099076972b11533944edbd52b34a416e6ed249..42df7be556fdd992831deca265353a7455b930ae 100755 (executable)
@@ -43,6 +43,7 @@ my $query = q{SELECT bug_id, short_desc, login_name
           INNER JOIN profiles
                   ON userid = assigned_to
                WHERE (bug_status = ? OR bug_status = ?)
+                 AND disable_mail = 0
                  AND } . $dbh->sql_to_days('NOW()') . " - " .
                        $dbh->sql_to_days('delta_ts') . " > " .
                        Bugzilla->params->{'whinedays'} .