comparison app/models/user.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents e248c7af89ec
children a1bdbf8a87d5
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
27 :order => %w(firstname lastname id), 27 :order => %w(firstname lastname id),
28 :setting_order => 1 28 :setting_order => 1
29 }, 29 },
30 :firstname_lastinitial => { 30 :firstname_lastinitial => {
31 :string => '#{firstname} #{lastname.to_s.chars.first}.', 31 :string => '#{firstname} #{lastname.to_s.chars.first}.',
32 :order => %w(firstname lastname id),
33 :setting_order => 2
34 },
35 :firstinitial_lastname => {
36 :string => '#{firstname.to_s.gsub(/(([[:alpha:]])[[:alpha:]]*\.?)/, \'\2.\')} #{lastname}',
32 :order => %w(firstname lastname id), 37 :order => %w(firstname lastname id),
33 :setting_order => 2 38 :setting_order => 2
34 }, 39 },
35 :firstname => { 40 :firstname => {
36 :string => '#{firstname}', 41 :string => '#{firstname}',
66 ['only_assigned', :label_user_mail_option_only_assigned], 71 ['only_assigned', :label_user_mail_option_only_assigned],
67 ['only_owner', :label_user_mail_option_only_owner], 72 ['only_owner', :label_user_mail_option_only_owner],
68 ['none', :label_user_mail_option_none] 73 ['none', :label_user_mail_option_none]
69 ] 74 ]
70 75
71 has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, 76 has_and_belongs_to_many :groups,
72 :after_remove => Proc.new {|user, group| group.user_removed(user)} 77 :join_table => "#{table_name_prefix}groups_users#{table_name_suffix}",
78 :after_add => Proc.new {|user, group| group.user_added(user)},
79 :after_remove => Proc.new {|user, group| group.user_removed(user)}
73 has_many :changesets, :dependent => :nullify 80 has_many :changesets, :dependent => :nullify
74 has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' 81 has_one :preference, :dependent => :destroy, :class_name => 'UserPreference'
75 has_one :rss_token, :class_name => 'Token', :conditions => "action='feeds'" 82 has_one :rss_token, :class_name => 'Token', :conditions => "action='feeds'"
76 has_one :api_token, :class_name => 'Token', :conditions => "action='api'" 83 has_one :api_token, :class_name => 'Token', :conditions => "action='api'"
77 belongs_to :auth_source 84 belongs_to :auth_source
305 312
306 def time_zone 313 def time_zone
307 @time_zone ||= (self.pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[self.pref.time_zone]) 314 @time_zone ||= (self.pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[self.pref.time_zone])
308 end 315 end
309 316
317 def force_default_language?
318 Setting.force_default_language_for_loggedin?
319 end
320
321 def language
322 if force_default_language?
323 Setting.default_language
324 else
325 super
326 end
327 end
328
310 def wants_comments_in_reverse_order? 329 def wants_comments_in_reverse_order?
311 self.pref[:comments_sorting] == 'desc' 330 self.pref[:comments_sorting] == 'desc'
312 end 331 end
313 332
314 # Return user's RSS key (a 40 chars long string), used to access feeds 333 # Return user's RSS key (a 40 chars long string), used to access feeds
363 end 382 end
364 383
365 # Find a user account by matching the exact login and then a case-insensitive 384 # Find a user account by matching the exact login and then a case-insensitive
366 # version. Exact matches will be given priority. 385 # version. Exact matches will be given priority.
367 def self.find_by_login(login) 386 def self.find_by_login(login)
387 login = Redmine::CodesetUtil.replace_invalid_utf8(login.to_s)
368 if login.present? 388 if login.present?
369 login = login.to_s
370 # First look for an exact match 389 # First look for an exact match
371 user = where(:login => login).all.detect {|u| u.login == login} 390 user = where(:login => login).detect {|u| u.login == login}
372 unless user 391 unless user
373 # Fail over to case-insensitive if none was found 392 # Fail over to case-insensitive if none was found
374 user = where("LOWER(login) = ?", login.downcase).first 393 user = where("LOWER(login) = ?", login.downcase).first
375 end 394 end
376 user 395 user
662 # Things that are not deleted are reassociated with the anonymous user 681 # Things that are not deleted are reassociated with the anonymous user
663 def remove_references_before_destroy 682 def remove_references_before_destroy
664 return if self.id.nil? 683 return if self.id.nil?
665 684
666 substitute = User.anonymous 685 substitute = User.anonymous
667 Attachment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] 686 Attachment.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
668 Comment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] 687 Comment.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
669 Issue.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] 688 Issue.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
670 Issue.update_all 'assigned_to_id = NULL', ['assigned_to_id = ?', id] 689 Issue.where(['assigned_to_id = ?', id]).update_all('assigned_to_id = NULL')
671 Journal.update_all ['user_id = ?', substitute.id], ['user_id = ?', id] 690 Journal.where(['user_id = ?', id]).update_all(['user_id = ?', substitute.id])
672 JournalDetail.update_all ['old_value = ?', substitute.id.to_s], ["property = 'attr' AND prop_key = 'assigned_to_id' AND old_value = ?", id.to_s] 691 JournalDetail.
673 JournalDetail.update_all ['value = ?', substitute.id.to_s], ["property = 'attr' AND prop_key = 'assigned_to_id' AND value = ?", id.to_s] 692 where(["property = 'attr' AND prop_key = 'assigned_to_id' AND old_value = ?", id.to_s]).
674 Message.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] 693 update_all(['old_value = ?', substitute.id.to_s])
675 News.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] 694 JournalDetail.
695 where(["property = 'attr' AND prop_key = 'assigned_to_id' AND value = ?", id.to_s]).
696 update_all(['value = ?', substitute.id.to_s])
697 Message.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
698 News.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
676 # Remove private queries and keep public ones 699 # Remove private queries and keep public ones
677 ::Query.delete_all ['user_id = ? AND visibility = ?', id, ::Query::VISIBILITY_PRIVATE] 700 ::Query.delete_all ['user_id = ? AND visibility = ?', id, ::Query::VISIBILITY_PRIVATE]
678 ::Query.update_all ['user_id = ?', substitute.id], ['user_id = ?', id] 701 ::Query.where(['user_id = ?', id]).update_all(['user_id = ?', substitute.id])
679 TimeEntry.update_all ['user_id = ?', substitute.id], ['user_id = ?', id] 702 TimeEntry.where(['user_id = ?', id]).update_all(['user_id = ?', substitute.id])
680 Token.delete_all ['user_id = ?', id] 703 Token.delete_all ['user_id = ?', id]
681 Watcher.delete_all ['user_id = ?', id] 704 Watcher.delete_all ['user_id = ?', id]
682 WikiContent.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] 705 WikiContent.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
683 WikiContent::Version.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] 706 WikiContent::Version.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
684 end 707 end
685 708
686 # Return password digest 709 # Return password digest
687 def self.hash_password(clear_password) 710 def self.hash_password(clear_password)
688 Digest::SHA1.hexdigest(clear_password || "") 711 Digest::SHA1.hexdigest(clear_password || "")