Guest User

Untitled

a guest
Dec 25th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2. self.table_name = "users_standard"
  3.  
  4. include Scopeable::Clientable, Searchable, Auditable
  5. attr_accessor :password, :password_confirmation
  6.  
  7. belongs_to :role
  8. has_many :discussion_posts, dependent: :destroy
  9. has_many :passtokens
  10. has_many :attendees
  11. has_many :authorized_ipads
  12. has_many :bookjobs
  13. with_options foreign_key: "user_id" do |user|
  14. user.has_and_belongs_to_many :questions, join_table: "questions_users"
  15. user.has_and_belongs_to_many :chatposts, join_table: "chatusers"
  16. user.has_and_belongs_to_many :permissions, join_table: "permissions_users"
  17. user.has_and_belongs_to_many :committees, join_table: "committees_users"
  18. user.has_and_belongs_to_many :bookfolders, join_table: "bookfolders_users"
  19. user.has_and_belongs_to_many :efolders, join_table: "efolders_users"
  20. user.has_and_belongs_to_many :surveys, join_table: "surveys_users"
  21. user.has_and_belongs_to_many :tasks, join_table: "tasks_users"
  22. end
  23.  
  24. with_options uniqueness: { scope: :client_id } do |user|
  25. user.validates :email, email: true, allow_blank: true
  26. user.validates :companyemail, email: true, allow_blank: true
  27. user.validates :login, presence: true
  28. end
  29. validates :firstname, :lastname, presence: true
  30. validates :password, presence: true, confirmation: { message: "does not match" }, password: true, allow_blank: true
  31.  
  32. before_save do |u|
  33. if u.password.present?
  34. self.password_hash = SecurePasswordService.new(self.password).secure
  35. self.p2 = true
  36. end
  37. end
  38.  
  39. accepts_nested_attributes_for :permissions, allow_destroy: true
  40.  
  41. delegate :title, :hostname, :forge_email_sender, :email_from, :email_new_account, :profile_update_email, :remove_email_footer, :disclaimer, :disclaimer_expiration_period, :password_change_days, :ftlogin, :user_lockout, to: :client, prefix: true
  42.  
  43. mount_uploader :photo, UserPhotoUploader
  44.  
  45. def self.active
  46. where('active = 1 and (system = 0 or system is null) and global_spawn != 1').order('lastname asc')
  47. end
  48.  
  49. def self.private_directory_list(user)
  50. joins(:committees).where('committees.id in (?)', user.committees.map(&:id))
  51. end
  52.  
  53. def endpoint_safe
  54. { user: self.attributes.with_indifferent_access.except!(:client_id) }
  55. end
  56.  
  57. def is_committee_member?(committee)
  58. (committee.is_a?(Committee) && self.committees.include?(committee)) or (!committee.is_a?(Committee) && committee.map{ |c| self.committees.include?(c) })
  59. end
  60. end
Add Comment
Please, Sign In to add comment