Mercurial > hg > soundsoftware-site
comparison app/models/.svn/text-base/user.rb.svn-base @ 119:8661b858af72
* Update to Redmine trunk rev 4705
author | Chris Cannam |
---|---|
date | Thu, 13 Jan 2011 14:12:06 +0000 |
parents | 94944d00e43c |
children | cd2282d2aa55 07fa8a8b56a8 |
comparison
equal
deleted
inserted
replaced
39:150ceac17a8d | 119:8661b858af72 |
---|---|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require "digest/sha1" | 18 require "digest/sha1" |
19 | 19 |
20 class User < Principal | 20 class User < Principal |
21 | 21 include Redmine::SafeAttributes |
22 | |
22 # Account statuses | 23 # Account statuses |
23 STATUS_ANONYMOUS = 0 | 24 STATUS_ANONYMOUS = 0 |
24 STATUS_ACTIVE = 1 | 25 STATUS_ACTIVE = 1 |
25 STATUS_REGISTERED = 2 | 26 STATUS_REGISTERED = 2 |
26 STATUS_LOCKED = 3 | 27 STATUS_LOCKED = 3 |
32 :lastname_coma_firstname => '#{lastname}, #{firstname}', | 33 :lastname_coma_firstname => '#{lastname}, #{firstname}', |
33 :username => '#{login}' | 34 :username => '#{login}' |
34 } | 35 } |
35 | 36 |
36 MAIL_NOTIFICATION_OPTIONS = [ | 37 MAIL_NOTIFICATION_OPTIONS = [ |
37 [:all, :label_user_mail_option_all], | 38 ['all', :label_user_mail_option_all], |
38 [:selected, :label_user_mail_option_selected], | 39 ['selected', :label_user_mail_option_selected], |
39 [:none, :label_user_mail_option_none], | 40 ['only_my_events', :label_user_mail_option_only_my_events], |
40 [:only_my_events, :label_user_mail_option_only_my_events], | 41 ['only_assigned', :label_user_mail_option_only_assigned], |
41 [:only_assigned, :label_user_mail_option_only_assigned], | 42 ['only_owner', :label_user_mail_option_only_owner], |
42 [:only_owner, :label_user_mail_option_only_owner] | 43 ['none', :label_user_mail_option_none] |
43 ] | 44 ] |
44 | 45 |
45 has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, | 46 has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, |
46 :after_remove => Proc.new {|user, group| group.user_removed(user)} | 47 :after_remove => Proc.new {|user, group| group.user_removed(user)} |
47 has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify | 48 has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify |
48 has_many :changesets, :dependent => :nullify | 49 has_many :changesets, :dependent => :nullify |
57 acts_as_customizable | 58 acts_as_customizable |
58 | 59 |
59 attr_accessor :password, :password_confirmation | 60 attr_accessor :password, :password_confirmation |
60 attr_accessor :last_before_login_on | 61 attr_accessor :last_before_login_on |
61 # Prevents unauthorized assignments | 62 # Prevents unauthorized assignments |
62 attr_protected :login, :admin, :password, :password_confirmation, :hashed_password, :group_ids | 63 attr_protected :login, :admin, :password, :password_confirmation, :hashed_password |
63 | 64 |
64 validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } | 65 validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } |
65 validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? }, :case_sensitive => false | 66 validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? }, :case_sensitive => false |
66 validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? }, :case_sensitive => false | 67 validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? }, :case_sensitive => false |
67 # Login must contain lettres, numbers, underscores only | 68 # Login must contain lettres, numbers, underscores only |
68 validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i | 69 validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i |
69 validates_length_of :login, :maximum => 30 | 70 validates_length_of :login, :maximum => 30 |
70 validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-\.]*$/i | |
71 validates_length_of :firstname, :lastname, :maximum => 30 | 71 validates_length_of :firstname, :lastname, :maximum => 30 |
72 validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true | 72 validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true |
73 validates_length_of :mail, :maximum => 60, :allow_nil => true | 73 validates_length_of :mail, :maximum => 60, :allow_nil => true |
74 validates_confirmation_of :password, :allow_nil => true | 74 validates_confirmation_of :password, :allow_nil => true |
75 validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true | |
75 | 76 |
76 def before_create | 77 def before_create |
77 self.mail_notification = Setting.default_notification_option if self.mail_notification.blank? | 78 self.mail_notification = Setting.default_notification_option if self.mail_notification.blank? |
78 true | 79 true |
79 end | 80 end |
262 # Only users that belong to more than 1 project can select projects for which they are notified | 263 # Only users that belong to more than 1 project can select projects for which they are notified |
263 def valid_notification_options | 264 def valid_notification_options |
264 # Note that @user.membership.size would fail since AR ignores | 265 # Note that @user.membership.size would fail since AR ignores |
265 # :include association option when doing a count | 266 # :include association option when doing a count |
266 if memberships.length < 1 | 267 if memberships.length < 1 |
267 MAIL_NOTIFICATION_OPTIONS.delete_if {|option| option.first == :selected} | 268 MAIL_NOTIFICATION_OPTIONS.delete_if {|option| option.first == 'selected'} |
268 else | 269 else |
269 MAIL_NOTIFICATION_OPTIONS | 270 MAIL_NOTIFICATION_OPTIONS |
270 end | 271 end |
271 end | 272 end |
272 | 273 |
388 # Is the user allowed to do the specified action on any project? | 389 # Is the user allowed to do the specified action on any project? |
389 # See allowed_to? for the actions and valid options. | 390 # See allowed_to? for the actions and valid options. |
390 def allowed_to_globally?(action, options) | 391 def allowed_to_globally?(action, options) |
391 allowed_to?(action, nil, options.reverse_merge(:global => true)) | 392 allowed_to?(action, nil, options.reverse_merge(:global => true)) |
392 end | 393 end |
394 | |
395 safe_attributes 'login', | |
396 'firstname', | |
397 'lastname', | |
398 'mail', | |
399 'mail_notification', | |
400 'language', | |
401 'custom_field_values', | |
402 'custom_fields', | |
403 'identity_url' | |
404 | |
405 safe_attributes 'status', | |
406 'auth_source_id', | |
407 :if => lambda {|user, current_user| current_user.admin?} | |
408 | |
409 safe_attributes 'group_ids', | |
410 :if => lambda {|user, current_user| current_user.admin? && !user.new_record?} | |
393 | 411 |
394 # Utility method to help check if a user should be notified about an | 412 # Utility method to help check if a user should be notified about an |
395 # event. | 413 # event. |
396 # | 414 # |
397 # TODO: only supports Issue events currently | 415 # TODO: only supports Issue events currently |
398 def notify_about?(object) | 416 def notify_about?(object) |
399 case mail_notification.to_sym | 417 case mail_notification |
400 when :all | 418 when 'all' |
401 true | 419 true |
402 when :selected | 420 when 'selected' |
403 # Handled by the Project | 421 # Handled by the Project |
404 when :none | 422 when 'none' |
405 false | 423 false |
406 when :only_my_events | 424 when 'only_my_events' |
407 if object.is_a?(Issue) && (object.author == self || object.assigned_to == self) | 425 if object.is_a?(Issue) && (object.author == self || object.assigned_to == self) |
408 true | 426 true |
409 else | 427 else |
410 false | 428 false |
411 end | 429 end |
412 when :only_assigned | 430 when 'only_assigned' |
413 if object.is_a?(Issue) && object.assigned_to == self | 431 if object.is_a?(Issue) && object.assigned_to == self |
414 true | 432 true |
415 else | 433 else |
416 false | 434 false |
417 end | 435 end |
418 when :only_owner | 436 when 'only_owner' |
419 if object.is_a?(Issue) && object.author == self | 437 if object.is_a?(Issue) && object.author == self |
420 true | 438 true |
421 else | 439 else |
422 false | 440 false |
423 end | 441 end |