Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Ext::DeviseConfiguration, Ext::Integrations::User
Defined in:
app/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ext::DeviseConfiguration

included

Class Method Details

.generate_passwordObject



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

Returns:

  • (Boolean)


44
45
46
# File 'app/models/user.rb', line 44

def active_for_authentication?
  super && !suspended?
end

#current_organizationObject



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

Returns:

  • (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