From e2466aae1fda4c2ce67c517074fdc4369d68b848 Mon Sep 17 00:00:00 2001 From: "travis%sedsystems.ca" <> Date: Sat, 8 Jan 2005 04:56:01 +0000 Subject: Bug 108870: Bugzilla does not set email prefs for new user until user visits userprefs.cgi Patch: travis r=mkanat a=justdave Also includes fixes for Bug 109573: New bugzilla accounts should by default have 'CC field changes' turned off, and Bug 275599: flag request email prefs not behaving correctly --- Bugzilla/BugMail.pm | 14 +--------- Bugzilla/Constants.pm | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++- Bugzilla/User.pm | 14 ---------- checksetup.pl | 49 +++++++++++++++++++++++++++++++++-- editusers.cgi | 3 ++- globals.pl | 6 +++-- userprefs.cgi | 22 ---------------- 7 files changed, 124 insertions(+), 55 deletions(-) diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm index 638b8a413..da41d4247 100644 --- a/Bugzilla/BugMail.pm +++ b/Bugzilla/BugMail.pm @@ -615,15 +615,6 @@ sub filterEmailGroup ($$$) { SendSQL("SELECT emailflags FROM profiles WHERE userid = $userid"); my $prefs = FetchOneColumn(); - # If the user's preferences are empty, it means the user has not set - # their mail preferences after the installation upgraded from a - # version of Bugzilla without email preferences to one with them. In - # this case, assume they want to receive all mail. - if (!defined($prefs) || $prefs !~ /email/) { - push(@recipients, $user); - next; - } - # Write the user's preferences into a Perl record indexed by # preference name. We pass the value "255" to the split function # because otherwise split will trim trailing null fields, causing @@ -665,10 +656,7 @@ sub filterEmailGroup ($$$) { } # If the user prefers to be included in mail about this change, - # or they haven't specified a preference for it (because they - # haven't visited the email preferences page since the preference - # was added, in which case we include them by default), add them - # to the list of recipients. + # add them to the list of recipients. foreach my $reason (@$reasons) { my $pref = "email$role$reason"; if (!exists($prefs{$pref}) || $prefs{$pref} eq 'on') { diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm index 1a9334f35..284506e15 100644 --- a/Bugzilla/Constants.pm +++ b/Bugzilla/Constants.pm @@ -25,7 +25,7 @@ # J. Paul Reed # Bradley Baetz # Christopher Aillon - +# Shane H. W. Travis package Bugzilla::Constants; use strict; @@ -51,6 +51,9 @@ use base qw(Exporter); LOGOUT_CURRENT LOGOUT_KEEP_CURRENT + DEFAULT_FLAG_EMAIL_SETTINGS + DEFAULT_EMAIL_SETTINGS + GRANT_DIRECT GRANT_DERIVED GRANT_REGEXP @@ -122,6 +125,72 @@ use constant contenttypes => "ics" => "text/calendar" , }; +use constant DEFAULT_FLAG_EMAIL_SETTINGS => + "~FlagRequestee~on" . + "~FlagRequester~on"; + +# By default, almost all bugmail is turned on, with the exception +# of CC list additions for anyone except the Assignee/Owner. +# If you want to customize the default settings for new users at +# your own site, ensure that each of the lines ends with either +# "~on" or just "~" (for off). + +use constant DEFAULT_EMAIL_SETTINGS => + "ExcludeSelf~on" . + + "~FlagRequestee~on" . + "~FlagRequester~on" . + + "~emailOwnerRemoveme~on" . + "~emailOwnerComments~on" . + "~emailOwnerAttachments~on" . + "~emailOwnerStatus~on" . + "~emailOwnerResolved~on" . + "~emailOwnerKeywords~on" . + "~emailOwnerCC~on" . + "~emailOwnerOther~on" . + "~emailOwnerUnconfirmed~on" . + + "~emailReporterRemoveme~on" . + "~emailReporterComments~on" . + "~emailReporterAttachments~on" . + "~emailReporterStatus~on" . + "~emailReporterResolved~on" . + "~emailReporterKeywords~on" . + "~emailReporterCC~" . + "~emailReporterOther~on" . + "~emailReporterUnconfirmed~on" . + + "~emailQAcontactRemoveme~on" . + "~emailQAcontactComments~on" . + "~emailQAcontactAttachments~on" . + "~emailQAcontactStatus~on" . + "~emailQAcontactResolved~on" . + "~emailQAcontactKeywords~on" . + "~emailQAcontactCC~" . + "~emailQAcontactOther~on" . + "~emailQAcontactUnconfirmed~on" . + + "~emailCClistRemoveme~on" . + "~emailCClistComments~on" . + "~emailCClistAttachments~on" . + "~emailCClistStatus~on" . + "~emailCClistResolved~on" . + "~emailCClistKeywords~on" . + "~emailCClistCC~" . + "~emailCClistOther~on" . + "~emailCClistUnconfirmed~on" . + + "~emailVoterRemoveme~on" . + "~emailVoterComments~on" . + "~emailVoterAttachments~on" . + "~emailVoterStatus~on" . + "~emailVoterResolved~on" . + "~emailVoterKeywords~on" . + "~emailVoterCC~" . + "~emailVoterOther~on" . + "~emailVoterUnconfirmed~on"; + use constant GRANT_DIRECT => 0; use constant GRANT_DERIVED => 1; use constant GRANT_REGEXP => 2; diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index e66419941..373a65655 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -858,20 +858,6 @@ sub email_prefs { my @reasons = qw(Removeme Comments Attachments Status Resolved Keywords CC Other Unconfirmed); - # If the prefs are empty, this user hasn't visited the email pane - # of userprefs.cgi since before the change to use the "emailflags" - # column, so initialize that field with the default prefs. - if (!$flags) { - # Create a default prefs string that causes the user to get all email. - $flags = "ExcludeSelf~on~FlagRequestee~on~FlagRequester~on~"; - foreach my $role (@roles) { - foreach my $reason (@reasons) { - $flags .= "email$role$reason~on~"; - } - } - chop $flags; - } - # Convert the prefs from the flags string from the database into # a Perl record. The 255 param is here because split will trim # any trailing null fields without a third param, which causes Perl diff --git a/checksetup.pl b/checksetup.pl index e352e6621..7e77af97f 100755 --- a/checksetup.pl +++ b/checksetup.pl @@ -26,6 +26,7 @@ # Jacob Steenhagen # Bradley Baetz # Tobias Burnus +# Shane H. W. Travis # Gervase Markham # Erik Stambaugh # @@ -4457,8 +4458,11 @@ if ($sth->rows == 0) { $realname = $dbh->quote($realname); $cryptedpassword = $dbh->quote($cryptedpassword); - $dbh->do("INSERT INTO profiles (login_name, realname, cryptpassword)" . - " VALUES ($login, $realname, $cryptedpassword)"); + # Set default email flags for the Admin, same as for users + my $defaultflagstring = $dbh->quote(Bugzilla::Constants::DEFAULT_EMAIL_SETTINGS); + + $dbh->do("INSERT INTO profiles (login_name, realname, cryptpassword, emailflags) " . + "VALUES ($login, $realname, $cryptedpassword, $defaultflagstring)"); } # Put the admin in each group if not already my $query = "select userid from profiles where login_name = $login"; @@ -4567,6 +4571,47 @@ if (GetFieldDef('bugs', 'short_desc')->[2]) { # if it allows nulls # Make sure groups get rederived $dbh->do("UPDATE groups SET last_changed = NOW() WHERE name = 'admin'"); +# 2004-12-29 - Flag email code is broke somewhere, and doesn't treat a lack +# of FlagRequestee/er emailflags as 'on' like it's supposed to. Easiest way +# to fix this is to make sure that everyone has these set. (bug 275599). +# While we're at it, let's make sure everyone has some emailprefs set, +# whether or not they've ever visited userprefs.cgi (bug 108870). In fact, +# do this first so that the second check gets fewer hits. +# +my $emailflags_count = 0; +$sth = $dbh->prepare("SELECT userid FROM profiles " . + "WHERE emailflags LIKE '' " . + "OR emailflags IS NULL"); +$sth->execute(); +while (my ($userid) = $sth->fetchrow_array()) { + $dbh->do("UPDATE profiles SET emailflags = " . + $dbh->quote(Bugzilla::Constants::DEFAULT_EMAIL_SETTINGS) . + "WHERE userid = $userid"); + $emailflags_count++; +} + +if ($emailflags_count) { + print "Added default email prefs to $emailflags_count users who had none.\n" unless $silent; + $emailflags_count = 0; +} + + +$sth = $dbh->prepare("SELECT userid, emailflags FROM profiles " . + "WHERE emailflags NOT LIKE '%Flagrequeste%' "); +$sth->execute(); +while (my ($userid, $emailflags) = $sth->fetchrow_array()) { + $emailflags .= Bugzilla::Constants::DEFAULT_FLAG_EMAIL_SETTINGS; + $emailflags = $dbh->quote($emailflags); + $dbh->do("UPDATE profiles SET emailflags = $emailflags " . + "WHERE userid = $userid"); + $emailflags_count++; +} + +if ($emailflags_count) { + print "Added default Flagrequester/ee email prefs to $emailflags_count users who had none.\n" unless $silent; + $emailflags_count = 0; +} + # 2003-10-24 - alt@sonic.net, bug 224208 # Support classification level and make sure there is a default classification diff --git a/editusers.cgi b/editusers.cgi index be8154d2e..7f3eef3a9 100755 --- a/editusers.cgi +++ b/editusers.cgi @@ -460,11 +460,12 @@ if ($action eq 'new') { # Add the new user SendSQL("INSERT INTO profiles ( " . "login_name, cryptpassword, realname, " . - "disabledtext" . + "emailflags, disabledtext" . " ) VALUES ( " . SqlQuote($user) . "," . SqlQuote(Crypt($password)) . "," . SqlQuote($realname) . "," . + SqlQuote(Bugzilla::Constants::DEFAULT_EMAIL_SETTINGS) . "," . SqlQuote($disabledtext) . ")" ); #+++ send e-mail away diff --git a/globals.pl b/globals.pl index 12644d506..5f599146f 100644 --- a/globals.pl +++ b/globals.pl @@ -435,13 +435,15 @@ sub InsertNewUser { my $cryptpassword = Crypt($password); + my $defaultflagstring = SqlQuote(Bugzilla::Constants::DEFAULT_EMAIL_SETTINGS); + # Insert the new user record into the database. $username = SqlQuote($username); $realname = SqlQuote($realname); $cryptpassword = SqlQuote($cryptpassword); PushGlobalSQLState(); - SendSQL("INSERT INTO profiles (login_name, realname, cryptpassword) - VALUES ($username, $realname, $cryptpassword)"); + SendSQL("INSERT INTO profiles (login_name, realname, cryptpassword, emailflags) + VALUES ($username, $realname, $cryptpassword, $defaultflagstring)"); PopGlobalSQLState(); # Return the password to the calling code so it can be included diff --git a/userprefs.cgi b/userprefs.cgi index 323c87d53..1c9cf2068 100755 --- a/userprefs.cgi +++ b/userprefs.cgi @@ -36,22 +36,10 @@ use Bugzilla::RelationSet; # Use global template variables. use vars qw($template $vars $userid); -# The default email flags leave all email on. -my $defaultflagstring = "ExcludeSelf~on~"; - my @roles = ("Owner", "Reporter", "QAcontact", "CClist", "Voter"); my @reasons = ("Removeme", "Comments", "Attachments", "Status", "Resolved", "Keywords", "CC", "Other", "Unconfirmed"); -foreach my $role (@roles) { - foreach my $reason (@reasons) { - $defaultflagstring .= "email$role$reason~on~"; - } -} - -# Remove final "~". -chop $defaultflagstring; - ############################################################################### # Each panel has two functions - panel Foo has a DoFoo, to get the data # necessary for displaying the panel, and a SaveFoo, to save the panel's @@ -161,16 +149,6 @@ sub DoEmail { my ($flagstring) = FetchSQLData(); - # If the emailflags haven't been set before, that means that this user - # hasn't been to the email pane of userprefs.cgi since the change to - # use emailflags. Create a default flagset for them, based on - # static defaults. - if (!$flagstring) { - $flagstring = $defaultflagstring; - SendSQL("UPDATE profiles SET emailflags = " . - SqlQuote($flagstring) . " WHERE userid = $userid"); - } - # The 255 param is here, because without a third param, split will # trim any trailing null fields, which causes Perl to eject lots of # warnings. Any suitably large number would do. -- cgit v1.2.3-24-g4f1b