Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Includes:
- Ext::DeviseConfiguration, Ext::Integrations::User
- Defined in:
- app/models/user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active_for_authentication? ⇒ Boolean
- #current_organization ⇒ Object
- #is_in_organization? ⇒ Boolean
- #membership_in(organization) ⇒ Object
- #to_s ⇒ Object
Methods included from Ext::Integrations::User
Methods included from Ext::DeviseConfiguration
Class Method Details
.generate_password ⇒ Object
19 20 21 |
# File 'app/models/user.rb', line 19 def self.generate_password Devise.friendly_token end |
.like(query = "") ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/models/user.rb', line 38 def self.like(query = "") return if query.blank? q = "%#{query}%" self.joins("LEFT OUTER JOIN user_memberships m ON m.user_id = users.id") .joins("LEFT OUTER JOIN organizations o ON o.id = m.organization_id") .includes(:organizations) .where("users.email like ? or o.name like ?", q, q) end |
Instance Method Details
#active_for_authentication? ⇒ Boolean
47 48 49 |
# File 'app/models/user.rb', line 47 def active_for_authentication? super && !suspended? end |
#current_organization ⇒ Object
30 31 32 |
# File 'app/models/user.rb', line 30 def current_organization @current_organization ||= is_in_organization? ? user_memberships.first.organization : Organization.new end |
#is_in_organization? ⇒ Boolean
26 27 28 |
# File 'app/models/user.rb', line 26 def is_in_organization? @is_in_organization ||= !!(user_memberships.any? && ! user_memberships.first.organization.new_record?) end |
#membership_in(organization) ⇒ Object
34 35 36 |
# File 'app/models/user.rb', line 34 def membership_in(organization) user_memberships.where(:organization_id => organization.id).limit(1).first end |
#to_s ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/models/user.rb', line 51 def to_s if first_name.present? || last_name.present? [first_name, last_name].reject(&:blank?).join(" ") elsif email.present? email.to_s else "No Name ##{id}" end end |