summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-09-28 18:22:00 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-09-28 18:22:00 +0000
commit0316af7f6bfa47ba1166eda3c5c7167229033a76 (patch)
treedb8d004f118674335919690a2f38b1b59782941b
parent3a3263102a7cda4be1c90168a9d32fa904d58272 (diff)
downloadredmine-0316af7f6bfa47ba1166eda3c5c7167229033a76.tar.gz
redmine-0316af7f6bfa47ba1166eda3c5c7167229033a76.zip
Converted User#mail_notification from a boolean to a string.
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
-rw-r--r--app/controllers/my_controller.rb14
-rw-r--r--app/models/project.rb2
-rw-r--r--app/models/user.rb11
-rw-r--r--app/views/my/account.rhtml2
-rw-r--r--config/locales/en.yml5
-rw-r--r--db/migrate/20100129193402_change_users_mail_notification_to_string.rb9
-rw-r--r--db/migrate/20100129193813_update_mail_notification_values.rb11
-rw-r--r--test/fixtures/users.yml20
-rw-r--r--test/unit/user_test.rb8
9 files changed, 58 insertions, 24 deletions
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index f637b49b6..e430cab0e 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -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
diff --git a/app/models/project.rb b/app/models/project.rb
index 4b0236b37..0bb67e420 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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
diff --git a/app/models/user.rb b/app/models/user.rb
index 5ae7a56d3..9fe5ff2ab 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
diff --git a/app/views/my/account.rhtml b/app/views/my/account.rhtml
index befe6be5a..b173b2b0d 100644
--- a/app/views/my/account.rhtml
+++ b/app/views/my/account.rhtml
@@ -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| %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c860f45a8..48425c4ff 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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
index 000000000..2011e8c74
--- /dev/null
+++ b/db/migrate/20100129193402_change_users_mail_notification_to_string.rb
@@ -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
index 000000000..bfe0a5952
--- /dev/null
+++ b/db/migrate/20100129193813_update_mail_notification_values.rb
@@ -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
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
index 29fc6be04..f26c09c0b 100644
--- a/test/fixtures/users.yml
+++ b/test/fixtures/users.yml
@@ -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
+
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index c263eafc0..1ecbc5927 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -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