Class: UserIdentity

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

Constant Summary collapse

IDENTITIES =
{
  guest: 0,
  student: 1,
  staff: 2,
  lecturer: 3,
  professor: 4
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.human_identity_title(identity) ⇒ Object


47
48
49
50
51
52
53
# File 'app/models/user_identity.rb', line 47

def self.human_identity_title(identity)
  defaults = [:"activerecord.attributes.user_identity.identity_titles.#{identity}"]
  defaults << identity.to_s.humanize
  options = {}
  options[:default] = defaults
  I18n.translate(defaults.shift, options)
end

.identity_attributes_for_selectObject


43
44
45
# File 'app/models/user_identity.rb', line 43

def self.identity_attributes_for_select
  IDENTITIES.map { |k, v| [I18n.t(k, scope: :'activerecord.attributes.user_identity.identities'), k] }
end

Instance Method Details

#ensure_user_identity_has_valid_original_departmentObject


55
56
57
58
# File 'app/models/user_identity.rb', line 55

def ensure_user_identity_has_valid_original_department
  return unless department.presence && !original_department.presence
  self.original_department = department
end

#generated?Boolean

Is this a generated (by EmailPattern) identity?

Returns:


72
73
74
# File 'app/models/user_identity.rb', line 72

def generated?
  email_pattern_id.present?
end

Link manually created identiy to a user that has the corresponding verified email


61
62
63
64
65
66
67
68
69
# File 'app/models/user_identity.rb', line 61

def link_to_user
  return if email_pattern_id.present?  # don't care about generated identities
  user_email = UserEmail.confirmed.find_by(email: email)
  if user_email
    self.user = user_email.user
  else
    self.user = nil
  end
end

#primary?Boolean

Is this the primary identity of the owner?

Returns:


77
78
79
# File 'app/models/user_identity.rb', line 77

def primary?
  user.primary_identity_id == id
end