Validates user's mail_notification and turn options into strings (the attribute type).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4494 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2010-12-12 14:02:39 +00:00
parent cde02954c8
commit e4f319fe61
2 changed files with 33 additions and 31 deletions
+16 -15
View File
@@ -35,13 +35,13 @@ class User < Principal
}
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]
]
['all', :label_user_mail_option_all],
['selected', :label_user_mail_option_selected],
['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],
['none', :label_user_mail_option_none]
]
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)}
@@ -73,6 +73,7 @@ class User < Principal
validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true
validates_length_of :mail, :maximum => 60, :allow_nil => true
validates_confirmation_of :password, :allow_nil => true
validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true
def before_create
self.mail_notification = Setting.default_notification_option if self.mail_notification.blank?
@@ -265,7 +266,7 @@ class User < Principal
# Note that @user.membership.size would fail since AR ignores
# :include association option when doing a count
if memberships.length < 1
MAIL_NOTIFICATION_OPTIONS.delete_if {|option| option.first == :selected}
MAIL_NOTIFICATION_OPTIONS.delete_if {|option| option.first == 'selected'}
else
MAIL_NOTIFICATION_OPTIONS
end
@@ -411,26 +412,26 @@ class User < Principal
#
# TODO: only supports Issue events currently
def notify_about?(object)
case mail_notification.to_sym
when :all
case mail_notification
when 'all'
true
when :selected
when 'selected'
# Handled by the Project
when :none
when 'none'
false
when :only_my_events
when 'only_my_events'
if object.is_a?(Issue) && (object.author == self || object.assigned_to == self)
true
else
false
end
when :only_assigned
when 'only_assigned'
if object.is_a?(Issue) && object.assigned_to == self
true
else
false
end
when :only_owner
when 'only_owner'
if object.is_a?(Issue) && object.author == self
true
else