@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
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
# 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
: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
validates_confirmation_of :password, :allow_nil => true
def before_create
- self.mail_notification = false
+ self.mail_notification = 'only_my_events'
true
end
<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| %>
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
--- /dev/null
+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
--- /dev/null
+# 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
firstname: Robert
id: 4
auth_source_id:
- mail_notification: true
+ mail_notification: all
login: rhill
type: User
users_001:
firstname: redMine
id: 1
auth_source_id:
- mail_notification: true
+ mail_notification: all
login: admin
type: User
users_002:
firstname: John
id: 2
auth_source_id:
- mail_notification: true
+ mail_notification: all
login: jsmith
type: User
users_003:
firstname: Dave
id: 3
auth_source_id:
- mail_notification: true
+ mail_notification: all
login: dlopper
type: User
users_005:
lastname: Lopper2
firstname: Dave2
auth_source_id:
- mail_notification: true
+ mail_notification: all
login: dlopper2
type: User
users_006:
lastname: Anonymous
firstname: ''
auth_source_id:
- mail_notification: false
+ mail_notification: only_my_events
login: ''
type: AnonymousUser
users_007:
lastname: One
firstname: Some
auth_source_id:
- mail_notification: false
+ mail_notification: only_my_events
login: someone
type: User
users_008:
lastname: Misc
firstname: User
auth_source_id:
- mail_notification: false
+ mail_notification: only_my_events
login: miscuser8
type: User
users_009:
lastname: Misc
firstname: User
auth_source_id:
- mail_notification: false
+ mail_notification: only_my_events
login: miscuser9
type: User
groups_010:
lastname: B Team
type: Group
-
\ No newline at end of file
+
end
def test_mail_notification_all
- @jsmith.mail_notification = true
+ @jsmith.mail_notification = 'all'
@jsmith.notified_project_ids = []
@jsmith.save
@jsmith.reload
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