Class: User

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Retirement

#retire!, #retired?, #unretire!

Class Method Details

.administratorsObject



51
52
53
# File 'app/models/user.rb', line 51

def self.administrators
  where(administrator: true)
end

.create_from_ldap_entry(attributes, entry) ⇒ Object



137
138
139
140
141
142
143
144
# File 'app/models/user.rb', line 137

def self.create_from_ldap_entry(attributes, entry)
  create!(
    email: entry.mail.first.downcase,
    username: entry[Houston::TMI::FIELD_USED_FOR_LDAP_LOGIN][0].to_s,
    password: attributes[:password],
    first_name: entry.givenname.first,
    last_name: entry.sn.first )
end

.find_by_email_address(email_address) ⇒ Object



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

def self.find_by_email_address(email_address)
  with_email_address(email_address).first
end

.find_for_ldap_authentication(attributes, entry) ⇒ Object



128
129
130
131
132
133
134
135
# File 'app/models/user.rb', line 128

def self.find_for_ldap_authentication(attributes, entry)
  email = entry.mail.first.downcase
  user = where(email: email).first
  if user && user.username.nil?
    user.update_column :username, entry[Houston::TMI::FIELD_USED_FOR_LDAP_LOGIN][0].to_s
  end
  user
end

.find_ldap_entry(ldap_connection, auth_key_value) ⇒ Object

LDAP Overrides ————————————————————————- #



123
124
125
126
# File 'app/models/user.rb', line 123

def self.find_ldap_entry(ldap_connection, auth_key_value)
  filter = Net::LDAP::Filter.eq(Houston::TMI::FIELD_USED_FOR_LDAP_LOGIN, auth_key_value)
  ldap_connection.ldap.search(filter: filter).first
end

.participantsObject



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

def self.participants
  Role.participants.to_users
end

.with_email_address(*email_addresses) ⇒ Object



65
66
67
68
69
70
# File 'app/models/user.rb', line 65

def self.with_email_address(*email_addresses)
  email_addresses = email_addresses.flatten.compact
  return none if email_addresses.none?
  values = email_addresses.map { |email| connection.quote(email.downcase) }.join(",")
  where("ARRAY[\"email_addresses\"] && ARRAY[#{values}]")
end

.with_primary_email(email) ⇒ Object



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

def self.with_primary_email(email)
  email = email.downcase if email
  where(email: email)
end

.with_view_option(option, value) ⇒ Object



76
77
78
# File 'app/models/user.rb', line 76

def self.with_view_option(option, value)
  where(["view_options->? = ?", option, value])
end

Instance Method Details

#alias_emailsObject



92
93
94
# File 'app/models/user.rb', line 92

def alias_emails
  email_addresses - [email]
end

#alias_emails=(value) ⇒ Object



96
97
98
# File 'app/models/user.rb', line 96

def alias_emails=(value)
  self.email_addresses = [email] + Array.wrap(value)
end

#email=(value) ⇒ Object



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

def email=(value)
  value = value.downcase if value
  super(value)
  self.email_addresses = [email] + alias_emails
end

#email_addressesObject



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

def email_addresses
  super || []
end

#followed_projectsObject



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

def followed_projects
  roles.to_projects.unretired
end

#follows?(project) ⇒ Boolean

Returns:

  • (Boolean)


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

def follows?(project)
  roles.to_projects.member?(project)
end

#nameObject



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

def name
  "#{first_name} #{last_name}"
end

#view_optionsObject



114
115
116
# File 'app/models/user.rb', line 114

def view_options
  super || {}
end