]> source.dussan.org Git - redmine.git/commitdiff
Converted User#mail_notification from a boolean to a string.
authorEric Davis <edavis@littlestreamsoftware.com>
Tue, 28 Sep 2010 18:22:00 +0000 (18:22 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Tue, 28 Sep 2010 18:22:00 +0000 (18:22 +0000)
The string will now store which type of notification option to use.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4216 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/my_controller.rb
app/models/project.rb
app/models/user.rb
app/views/my/account.rhtml
config/locales/en.yml
db/migrate/20100129193402_change_users_mail_notification_to_string.rb [new file with mode: 0644]
db/migrate/20100129193813_update_mail_notification_values.rb [new file with mode: 0644]
test/fixtures/users.yml
test/unit/user_test.rb

index f637b49b63a1c59e572a0176d70c0f95b75b1a65..e430cab0e5fc41ed73d4df538b236dc842f84199 100644 (file)
@@ -54,7 +54,7 @@ class MyController < ApplicationController
     @pref = @user.pref
     if request.post?
       @user.attributes = params[:user]
-      @user.mail_notification = (params[:notification_option] == 'all')
+      @user.mail_notification = params[:notification_option] || 'only_my_events'
       @user.pref.attributes = params[:pref]
       @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
       if @user.save
@@ -66,12 +66,14 @@ class MyController < ApplicationController
         return
       end
     end
-    @notification_options = [[l(:label_user_mail_option_all), 'all'],
-                             [l(:label_user_mail_option_none), 'none']]
+    @notification_options = User::MAIL_NOTIFICATION_OPTIONS
     # Only users that belong to more than 1 project can select projects for which they are notified
-    # Note that @user.membership.size would fail since AR ignores :include association option when doing a count
-    @notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
-    @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')    
+    # Note that @user.membership.size would fail since AR ignores
+    # :include association option when doing a count
+    if @user.memberships.length < 1
+      @notification_options.delete_if {|option| option.first == :selected}
+    end
+    @notification_option = @user.mail_notification #? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')    
   end
 
   # Manage user's password
index 4b0236b37486ffbaadf52aecdfbc34a9cc12c077..0bb67e4207cae24976e1eaf15d2c0097ffd59b78 100644 (file)
@@ -382,7 +382,7 @@ class Project < ActiveRecord::Base
   
   # Returns the mail adresses of users that should be always notified on project events
   def recipients
-    members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
+    members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user.mail}
   end
   
   # Returns the users that should be notified on project events
index 5ae7a56d308c27e65d70c359839d8eaf796b067c..9fe5ff2ab88781e73ff759fbac0dc374c3235dcb 100644 (file)
@@ -33,6 +33,15 @@ class User < Principal
     :username => '#{login}'
   }
 
+  MAIL_NOTIFICATION_OPTIONS = [
+                               [:all, :label_user_mail_option_all],
+                               [:selected, :label_user_mail_option_selected],
+                               [:none, :label_user_mail_option_none],
+                               [:only_my_events, :label_user_mail_option_only_my_events],
+                               [:only_assigned, :label_user_mail_option_only_assigned],
+                               [:only_owner, :label_user_mail_option_only_owner]
+                              ]
+
   has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
                                    :after_remove => Proc.new {|user, group| group.user_removed(user)}
   has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
@@ -65,7 +74,7 @@ class User < Principal
   validates_confirmation_of :password, :allow_nil => true
 
   def before_create
-    self.mail_notification = false
+    self.mail_notification = 'only_my_events'
     true
   end
   
index befe6be5a1aac1b989396068aecd180fe1224620..b173b2b0df13033ea3ece212ef42e627b6ca9613 100644 (file)
@@ -32,7 +32,7 @@
 <div class="splitcontentright">
 <h3><%=l(:field_mail_notification)%></h3>
 <div class="box">
-<%= select_tag 'notification_option', options_for_select(@notification_options, @notification_option),
+<%= select_tag 'notification_option', options_for_select(@notification_options.collect {|o| [l(o.last), o.first]}, @notification_option.to_sym),
                                       :onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %>
 <% content_tag 'div', :id => 'notified-projects', :style => (@notification_option == 'selected' ? '' : 'display:none;') do %>
 <p><% User.current.projects.each do |project| %>
index c860f45a8a95c2067f9d277885fe5c883ce55a23..48425c4fff1fbf590f98b01e058e256649d41bc6 100644 (file)
@@ -725,7 +725,10 @@ en:
   label_search_titles_only: Search titles only
   label_user_mail_option_all: "For any event on all my projects"
   label_user_mail_option_selected: "For any event on the selected projects only..."
-  label_user_mail_option_none: "Only for things I watch or I'm involved in"
+  label_user_mail_option_none: "No events"
+  label_user_mail_option_only_my_events: "Only for things I watch or I'm involved in"
+  label_user_mail_option_only_assigned: "Only for things I am assigned to"
+  label_user_mail_option_only_owner: "Only for things I am the owner of"
   label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
   label_registration_activation_by_email: account activation by email
   label_registration_manual_activation: manual account activation
diff --git a/db/migrate/20100129193402_change_users_mail_notification_to_string.rb b/db/migrate/20100129193402_change_users_mail_notification_to_string.rb
new file mode 100644 (file)
index 0000000..2011e8c
--- /dev/null
@@ -0,0 +1,9 @@
+class ChangeUsersMailNotificationToString < ActiveRecord::Migration
+  def self.up
+    change_column :users, :mail_notification, :string, :default => '', :null => false
+  end
+
+  def self.down
+    change_column :users, :mail_notification, :boolean, :default => true, :null => false
+  end
+end
diff --git a/db/migrate/20100129193813_update_mail_notification_values.rb b/db/migrate/20100129193813_update_mail_notification_values.rb
new file mode 100644 (file)
index 0000000..bfe0a59
--- /dev/null
@@ -0,0 +1,11 @@
+# Patch the data from a boolean change.
+class UpdateMailNotificationValues < ActiveRecord::Migration
+  def self.up
+    User.update_all("mail_notification = 'all'", "mail_notification = '1'")
+    User.update_all("mail_notification = 'only_my_events'", "mail_notification = '0'")
+  end
+
+  def self.down
+    # No-op
+  end
+end
index 29fc6be04b7d3681699c1203d05e7b7c30529f85..f26c09c0bf00c8a4b50d072b43bf2f9228ac19e6 100644 (file)
@@ -12,7 +12,7 @@ users_004:
   firstname: Robert
   id: 4
   auth_source_id: 
-  mail_notification: true
+  mail_notification: all
   login: rhill
   type: User
 users_001: 
@@ -28,7 +28,7 @@ users_001:
   firstname: redMine
   id: 1
   auth_source_id: 
-  mail_notification: true
+  mail_notification: all
   login: admin
   type: User
 users_002: 
@@ -44,7 +44,7 @@ users_002:
   firstname: John
   id: 2
   auth_source_id: 
-  mail_notification: true
+  mail_notification: all
   login: jsmith
   type: User
 users_003: 
@@ -60,7 +60,7 @@ users_003:
   firstname: Dave
   id: 3
   auth_source_id: 
-  mail_notification: true
+  mail_notification: all
   login: dlopper
   type: User
 users_005: 
@@ -77,7 +77,7 @@ users_005:
   lastname: Lopper2
   firstname: Dave2
   auth_source_id: 
-  mail_notification: true
+  mail_notification: all
   login: dlopper2
   type: User
 users_006: 
@@ -93,7 +93,7 @@ users_006:
   lastname: Anonymous
   firstname: ''
   auth_source_id: 
-  mail_notification: false
+  mail_notification: only_my_events
   login: ''
   type: AnonymousUser
 users_007: 
@@ -109,7 +109,7 @@ users_007:
   lastname: One
   firstname: Some
   auth_source_id: 
-  mail_notification: false
+  mail_notification: only_my_events
   login: someone
   type: User
 users_008: 
@@ -125,7 +125,7 @@ users_008:
   lastname: Misc
   firstname: User
   auth_source_id: 
-  mail_notification: false
+  mail_notification: only_my_events
   login: miscuser8
   type: User
 users_009: 
@@ -141,7 +141,7 @@ users_009:
   lastname: Misc
   firstname: User
   auth_source_id: 
-  mail_notification: false
+  mail_notification: only_my_events
   login: miscuser9
   type: User
 groups_010: 
@@ -153,4 +153,4 @@ groups_011:
   lastname: B Team
   type: Group
 
-  
\ No newline at end of file
+  
index c263eafc098af5c0dfdd7ffa7b7334db2ef69452..1ecbc5927b52676bcefed91a42f49efcaace4102 100644 (file)
@@ -285,7 +285,7 @@ class UserTest < ActiveSupport::TestCase
   end
   
   def test_mail_notification_all
-    @jsmith.mail_notification = true
+    @jsmith.mail_notification = 'all'
     @jsmith.notified_project_ids = []
     @jsmith.save
     @jsmith.reload
@@ -293,15 +293,15 @@ class UserTest < ActiveSupport::TestCase
   end
   
   def test_mail_notification_selected
-    @jsmith.mail_notification = false
+    @jsmith.mail_notification = 'selected'
     @jsmith.notified_project_ids = [1]
     @jsmith.save
     @jsmith.reload
     assert Project.find(1).recipients.include?(@jsmith.mail)
   end
   
-  def test_mail_notification_none
-    @jsmith.mail_notification = false
+  def test_mail_notification_only_my_events
+    @jsmith.mail_notification = 'only_my_events'
     @jsmith.notified_project_ids = []
     @jsmith.save
     @jsmith.reload