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::Integrations::User

#need_more_info?

Methods included from Ext::DeviseConfiguration

included

Class Method Details

.generate_passwordObject



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

Returns:

  • (Boolean)


47
48
49
# File 'app/models/user.rb', line 47

def active_for_authentication?
  super && !suspended?
end

#current_organizationObject



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

Returns:

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



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