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
This commit is contained in:
parent
3a3263102a
commit
0316af7f6b
|
@ -54,7 +54,7 @@ class MyController < ApplicationController
|
||||||
@pref = @user.pref
|
@pref = @user.pref
|
||||||
if request.post?
|
if request.post?
|
||||||
@user.attributes = params[:user]
|
@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.attributes = params[:pref]
|
||||||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
||||||
if @user.save
|
if @user.save
|
||||||
|
@ -66,12 +66,14 @@ class MyController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@notification_options = [[l(:label_user_mail_option_all), 'all'],
|
@notification_options = User::MAIL_NOTIFICATION_OPTIONS
|
||||||
[l(:label_user_mail_option_none), 'none']]
|
|
||||||
# Only users that belong to more than 1 project can select projects for which they are notified
|
# 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
|
# Note that @user.membership.size would fail since AR ignores
|
||||||
@notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
|
# :include association option when doing a count
|
||||||
@notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
|
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
|
end
|
||||||
|
|
||||||
# Manage user's password
|
# 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
|
# Returns the mail adresses of users that should be always notified on project events
|
||||||
def recipients
|
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
|
end
|
||||||
|
|
||||||
# Returns the users that should be notified on project events
|
# Returns the users that should be notified on project events
|
||||||
|
|
|
@ -33,6 +33,15 @@ class User < Principal
|
||||||
:username => '#{login}'
|
: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)},
|
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)}
|
:after_remove => Proc.new {|user, group| group.user_removed(user)}
|
||||||
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
|
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
|
validates_confirmation_of :password, :allow_nil => true
|
||||||
|
|
||||||
def before_create
|
def before_create
|
||||||
self.mail_notification = false
|
self.mail_notification = 'only_my_events'
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
<div class="splitcontentright">
|
<div class="splitcontentright">
|
||||||
<h3><%=l(:field_mail_notification)%></h3>
|
<h3><%=l(:field_mail_notification)%></h3>
|
||||||
<div class="box">
|
<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")}' %>
|
: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 %>
|
<% content_tag 'div', :id => 'notified-projects', :style => (@notification_option == 'selected' ? '' : 'display:none;') do %>
|
||||||
<p><% User.current.projects.each do |project| %>
|
<p><% User.current.projects.each do |project| %>
|
||||||
|
|
|
@ -725,7 +725,10 @@ en:
|
||||||
label_search_titles_only: Search titles only
|
label_search_titles_only: Search titles only
|
||||||
label_user_mail_option_all: "For any event on all my projects"
|
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_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_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_activation_by_email: account activation by email
|
||||||
label_registration_manual_activation: manual account activation
|
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
|
firstname: Robert
|
||||||
id: 4
|
id: 4
|
||||||
auth_source_id:
|
auth_source_id:
|
||||||
mail_notification: true
|
mail_notification: all
|
||||||
login: rhill
|
login: rhill
|
||||||
type: User
|
type: User
|
||||||
users_001:
|
users_001:
|
||||||
|
@ -28,7 +28,7 @@ users_001:
|
||||||
firstname: redMine
|
firstname: redMine
|
||||||
id: 1
|
id: 1
|
||||||
auth_source_id:
|
auth_source_id:
|
||||||
mail_notification: true
|
mail_notification: all
|
||||||
login: admin
|
login: admin
|
||||||
type: User
|
type: User
|
||||||
users_002:
|
users_002:
|
||||||
|
@ -44,7 +44,7 @@ users_002:
|
||||||
firstname: John
|
firstname: John
|
||||||
id: 2
|
id: 2
|
||||||
auth_source_id:
|
auth_source_id:
|
||||||
mail_notification: true
|
mail_notification: all
|
||||||
login: jsmith
|
login: jsmith
|
||||||
type: User
|
type: User
|
||||||
users_003:
|
users_003:
|
||||||
|
@ -60,7 +60,7 @@ users_003:
|
||||||
firstname: Dave
|
firstname: Dave
|
||||||
id: 3
|
id: 3
|
||||||
auth_source_id:
|
auth_source_id:
|
||||||
mail_notification: true
|
mail_notification: all
|
||||||
login: dlopper
|
login: dlopper
|
||||||
type: User
|
type: User
|
||||||
users_005:
|
users_005:
|
||||||
|
@ -77,7 +77,7 @@ users_005:
|
||||||
lastname: Lopper2
|
lastname: Lopper2
|
||||||
firstname: Dave2
|
firstname: Dave2
|
||||||
auth_source_id:
|
auth_source_id:
|
||||||
mail_notification: true
|
mail_notification: all
|
||||||
login: dlopper2
|
login: dlopper2
|
||||||
type: User
|
type: User
|
||||||
users_006:
|
users_006:
|
||||||
|
@ -93,7 +93,7 @@ users_006:
|
||||||
lastname: Anonymous
|
lastname: Anonymous
|
||||||
firstname: ''
|
firstname: ''
|
||||||
auth_source_id:
|
auth_source_id:
|
||||||
mail_notification: false
|
mail_notification: only_my_events
|
||||||
login: ''
|
login: ''
|
||||||
type: AnonymousUser
|
type: AnonymousUser
|
||||||
users_007:
|
users_007:
|
||||||
|
@ -109,7 +109,7 @@ users_007:
|
||||||
lastname: One
|
lastname: One
|
||||||
firstname: Some
|
firstname: Some
|
||||||
auth_source_id:
|
auth_source_id:
|
||||||
mail_notification: false
|
mail_notification: only_my_events
|
||||||
login: someone
|
login: someone
|
||||||
type: User
|
type: User
|
||||||
users_008:
|
users_008:
|
||||||
|
@ -125,7 +125,7 @@ users_008:
|
||||||
lastname: Misc
|
lastname: Misc
|
||||||
firstname: User
|
firstname: User
|
||||||
auth_source_id:
|
auth_source_id:
|
||||||
mail_notification: false
|
mail_notification: only_my_events
|
||||||
login: miscuser8
|
login: miscuser8
|
||||||
type: User
|
type: User
|
||||||
users_009:
|
users_009:
|
||||||
|
@ -141,7 +141,7 @@ users_009:
|
||||||
lastname: Misc
|
lastname: Misc
|
||||||
firstname: User
|
firstname: User
|
||||||
auth_source_id:
|
auth_source_id:
|
||||||
mail_notification: false
|
mail_notification: only_my_events
|
||||||
login: miscuser9
|
login: miscuser9
|
||||||
type: User
|
type: User
|
||||||
groups_010:
|
groups_010:
|
||||||
|
|
|
@ -285,7 +285,7 @@ class UserTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mail_notification_all
|
def test_mail_notification_all
|
||||||
@jsmith.mail_notification = true
|
@jsmith.mail_notification = 'all'
|
||||||
@jsmith.notified_project_ids = []
|
@jsmith.notified_project_ids = []
|
||||||
@jsmith.save
|
@jsmith.save
|
||||||
@jsmith.reload
|
@jsmith.reload
|
||||||
|
@ -293,15 +293,15 @@ class UserTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mail_notification_selected
|
def test_mail_notification_selected
|
||||||
@jsmith.mail_notification = false
|
@jsmith.mail_notification = 'selected'
|
||||||
@jsmith.notified_project_ids = [1]
|
@jsmith.notified_project_ids = [1]
|
||||||
@jsmith.save
|
@jsmith.save
|
||||||
@jsmith.reload
|
@jsmith.reload
|
||||||
assert Project.find(1).recipients.include?(@jsmith.mail)
|
assert Project.find(1).recipients.include?(@jsmith.mail)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mail_notification_none
|
def test_mail_notification_only_my_events
|
||||||
@jsmith.mail_notification = false
|
@jsmith.mail_notification = 'only_my_events'
|
||||||
@jsmith.notified_project_ids = []
|
@jsmith.notified_project_ids = []
|
||||||
@jsmith.save
|
@jsmith.save
|
||||||
@jsmith.reload
|
@jsmith.reload
|
||||||
|
|
Loading…
Reference in New Issue