Class: User

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ User

Returns a new instance of User.


69
70
71
72
# File 'app/models/user.rb', line 69

def initialize(*args, &block)
  super
  @skip_confirmation_notification = true
end

Class Method Details

.scoped(org_code) ⇒ Object


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

def self.scoped(org_code)
  if org_code.blank?
    all
  else
    org = Organization.find_by(code: org_code)
    org ? org.users : none
  end
end

Instance Method Details

#avatar_urlObject


103
104
105
# File 'app/models/user.rb', line 103

def avatar_url
  external_avatar_url
end

#cover_photo_urlObject


107
108
109
# File 'app/models/user.rb', line 107

def cover_photo_url
  external_cover_photo_url
end

#department_codesObject


78
79
80
# File 'app/models/user.rb', line 78

def department_codes
  identities.map(&:department_code)
end

#fb_linked?Boolean

Returns:


111
112
113
# File 'app/models/user.rb', line 111

def fb_linked?
  fbemail.present?
end

#generate_uuidObject


86
87
88
89
# File 'app/models/user.rb', line 86

def generate_uuid
  return if uuid.present?
  regenerate_uuid(true)
end

#organization_codesObject


74
75
76
# File 'app/models/user.rb', line 74

def organization_codes
  identities.map(&:organization_code)
end

#regenerate_uuid(random = true) ⇒ Object


91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/user.rb', line 91

def regenerate_uuid(random = true)
  if random
    base = SecureRandom.random_bytes(16)
  else
    base = Digest::MD5.digest("#{ENV['APP_URL']}#{id}")
  end
  ary = base.unpack("NnnnnN")
  ary[2] = (ary[2] & 0x0fff) | 0x4000
  ary[3] = (ary[3] & 0x3fff) | 0x8000
  self.uuid = "%08x-%04x-%04x-%04x-%04x%08x" % ary
end

#validate_after_touchObject

Validate and save the updates after touched


116
117
118
119
120
# File 'app/models/user.rb', line 116

def validate_after_touch
  reload
  valid?
  save! if changed?
end

#verified?Boolean

Returns:


82
83
84
# File 'app/models/user.rb', line 82

def verified?
  !primary_identity_id.blank?
end