Class: User

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

Constant Summary collapse

ROLES =
%w{Owner Admin Member}.freeze

Constants included from Houston::Props

Houston::Props::VALID_PROP_NAME

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Houston::Props

#get_prop, #props, #update_prop!, #update_props!, valid_prop_name!, valid_prop_name?

Methods included from Retirement

#retire!, #retired?, #unretire!

Class Method Details

.create_from_ldap_entry(attributes, entry) ⇒ Object



132
133
134
135
136
137
138
139
# File 'app/models/user.rb', line 132

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

.find_by_email_address(email_address) ⇒ Object



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

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

.find_for_ldap_authentication(attributes, entry) ⇒ Object



123
124
125
126
127
128
129
130
# File 'app/models/user.rb', line 123

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.config.authentication_strategy_configuration[:field]][0].to_s
  end
  user
end

.find_ldap_entry(ldap_connection, auth_key_value) ⇒ Object

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



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

def self.find_ldap_entry(ldap_connection, auth_key_value)
  filter = Net::LDAP::Filter.eq(Houston.config.authentication_strategy_configuration[:field], auth_key_value)
  ldap_connection.ldap.search(filter: filter).first
end

.with_email_address(*email_addresses) ⇒ Object



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

def self.with_email_address(*email_addresses)
  email_addresses = email_addresses.flatten.compact
  return none if email_addresses.none?
  where ["email_addresses && ARRAY[?]", email_addresses.map(&:downcase)]
end

.with_primary_email(email) ⇒ Object



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

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

Instance Method Details

#alias_emailsObject



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

def alias_emails
  email_addresses - [email]
end

#alias_emails=(value) ⇒ Object



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

def alias_emails=(value)
  self.email_addresses = [email] + Array.wrap(value).reject(&:blank?)
end

#developer?Boolean

Returns:

  • (Boolean)


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

def developer?
  puts "DEPRECATED: User#developer? will be removed"
  legacy_role == "Developer"
end

#email=(value) ⇒ Object



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

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

#email_addressesObject



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

def email_addresses
  (super || []).reject(&:blank?)
end

#followed_projectsObject



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

def followed_projects
  Role.where(user: self).to_projects.unretired
end

#follows?(project) ⇒ Boolean

Returns:

  • (Boolean)


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

def follows?(project)
  Role.where(user: self).to_projects.member?(project)
end

#nameObject



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

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

#tester?Boolean

Returns:

  • (Boolean)


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

def tester?
  puts "DEPRECATED: User#tester? will be removed"
  legacy_role == "Tester"
end

#unfuddle_idObject

Raises:

  • (NotImplementedError)


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

def unfuddle_id
  raise NotImplementedError, "This feature has been deprecated; use props[\"unfuddle.id\"]"
end

#unfuddle_id=(value) ⇒ Object

Raises:

  • (NotImplementedError)


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

def unfuddle_id=(value)
  raise NotImplementedError, "This feature has been deprecated; use props[\"unfuddle.id\"]"
end

#view_optionsObject

Raises:

  • (NotImplementedError)


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

def view_options
  raise NotImplementedError, "This feature has been deprecated; use props"
end

#view_options=(value) ⇒ Object

Raises:

  • (NotImplementedError)


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

def view_options=(value)
  raise NotImplementedError, "This feature has been deprecated; use props"
end