summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-12 14:02:39 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-12 14:02:39 +0000
commite4f319fe6122d466ac57fc18761d8ac78c981e60 (patch)
treef837b48c592de60ddc73d5d4992bd5ceff292aa1 /app
parentcde02954c84591c66c575f0d76d44c18ab6edf95 (diff)
downloadredmine-e4f319fe6122d466ac57fc18761d8ac78c981e60.tar.gz
redmine-e4f319fe6122d466ac57fc18761d8ac78c981e60.zip
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
Diffstat (limited to 'app')
-rw-r--r--app/models/user.rb31
1 files changed, 16 insertions, 15 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index b039ba0b3..f69604199 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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