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
pull/351/head
Eric Davis 14 years ago
parent 3a3263102a
commit 0316af7f6b
  1. 14
      app/controllers/my_controller.rb
  2. 2
      app/models/project.rb
  3. 11
      app/models/user.rb
  4. 2
      app/views/my/account.rhtml
  5. 5
      config/locales/en.yml
  6. 9
      db/migrate/20100129193402_change_users_mail_notification_to_string.rb
  7. 11
      db/migrate/20100129193813_update_mail_notification_values.rb
  8. 20
      test/fixtures/users.yml
  9. 8
      test/unit/user_test.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

@ -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

@ -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

@ -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| %>

@ -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

@ -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

@ -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

@ -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

@ -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

Loading…
Cancel
Save