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
Methods included from Ext::DeviseConfiguration
Class Method Details
.generate_password ⇒ Object
16 17 18 |
# File 'app/models/user.rb', line 16 def self.generate_password Devise.friendly_token end |
.like(query = "") ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'app/models/user.rb', line 35 def self.like(query = "") return if query.blank? q = "%#{query}%" self.joins("LEFT OUTER JOIN 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
44 45 46 |
# File 'app/models/user.rb', line 44 def active_for_authentication? super && !suspended? end |
#current_organization ⇒ Object
27 28 29 |
# File 'app/models/user.rb', line 27 def current_organization @current_organization ||= (is_in_organization? ? memberships.first.organization : Organization.new) end |
#is_in_organization? ⇒ Boolean
23 24 25 |
# File 'app/models/user.rb', line 23 def is_in_organization? @is_in_organization ||= memberships.any? end |
#membership_in(organization) ⇒ Object
31 32 33 |
# File 'app/models/user.rb', line 31 def membership_in(organization) memberships.where(:organization_id => organization.id).limit(1).first end |