Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
CommonScopes
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommonScopes

included

Instance Attribute Details

#loginObject

Virtual attribute for authenticating by either username or email This is in addition to a real persisted field like 'username'


18
19
20
# File 'app/models/user.rb', line 18

def 
  @login
end

#no_send_emailObject

Virtual attribute for authenticating by either username or email This is in addition to a real persisted field like 'username'


18
19
20
# File 'app/models/user.rb', line 18

def no_send_email
  @no_send_email
end

#skip_default_roleObject

Virtual attribute for authenticating by either username or email This is in addition to a real persisted field like 'username'


18
19
20
# File 'app/models/user.rb', line 18

def skip_default_role
  @skip_default_role
end

Instance Method Details

#add_default_roleObject


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

def add_default_role
  return if self.skip_default_role == true
  role_id = self.owner == 1 ? 2 : 3
  permission = Permission.new(user_id: self.id, role_id: role_id)
  permission.save!
end

#add_to_organizationObject


52
53
54
55
56
57
58
# File 'app/models/user.rb', line 52

def add_to_organization
  if self.organization_id.nil?
    organization = Organization.new(name: self.organization_name)
    organization.save!
    self.organization_id = organization.id
  end
end

#generate_authentication_tokenObject


60
61
62
63
64
65
66
# File 'app/models/user.rb', line 60

def generate_authentication_token
  # create a longer token and check that it isn't set on some other user
  loop do
    token = Devise.friendly_token + Devise.friendly_token + Devise.friendly_token
    break token unless User.where(authentication_token: token).first
  end
end

#role?(role) ⇒ Boolean

Returns:

  • (Boolean)

41
42
43
# File 'app/models/user.rb', line 41

def role?(role)
  return !!self.roles.find_by_name(role.to_s.camelize)
end

#show_username_label_methodObject

show the user email in the admin UI instead of the user id


37
38
39
# File 'app/models/user.rb', line 37

def show_username_label_method
  self.username
end