Class: User
Overview
Represents Sequencescape users, used to regulate login as well as provide tracking of who did what. While most users are internal, some are external.
Defined Under Namespace
Modules: Authentication
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
has_many_events, has_many_lab_events, has_one_event_with_family
#grant_role, #remove_role, #role?, #role_names
#compare_swipecard_code, included, #swipecard_code, #swipecard_code=, #swipecard_code?
included, #unsaved_uuid!, #uuid
#authenticated?, included
alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
extended
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
50
51
52
|
# File 'app/models/user.rb', line 50
def password
@password
end
|
Class Method Details
.all_administrators_emails ⇒ Object
returns emails of all admins
77
78
79
|
# File 'app/models/user.rb', line 77
def self.all_administrators_emails
all_administrators.uniq.pluck(:email).compact
end
|
.encrypt(password, salt) ⇒ Object
Encrypts some data with the salt.
82
83
84
|
# File 'app/models/user.rb', line 82
def self.encrypt(password, salt)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end
|
.find_with_barcode_or_swipecard_code(user_code) ⇒ Object
72
73
74
|
# File 'app/models/user.rb', line 72
def self.find_with_barcode_or_swipecard_code(user_code)
with_user_code(user_code).first
end
|
.prefix ⇒ Object
68
69
70
|
# File 'app/models/user.rb', line 68
def self.prefix
'ID'
end
|
.sequencescape ⇒ Object
86
87
88
|
# File 'app/models/user.rb', line 86
def self.sequencescape
find_or_create_by!(login: configatron.sequencescape_email, email: configatron.sequencescape_email)
end
|
Instance Method Details
#encrypt(password) ⇒ Object
Encrypts the password with the user salt
141
142
143
|
# File 'app/models/user.rb', line 141
def encrypt(password)
self.class.encrypt(password, salt)
end
|
#forget_me ⇒ Object
156
157
158
159
160
|
# File 'app/models/user.rb', line 156
def forget_me
self.remember_token_expires_at = nil
self.remember_token = nil
save(validate: false)
end
|
#interesting_studies ⇒ Object
User has a relationship by role to these studies
163
164
165
|
# File 'app/models/user.rb', line 163
def interesting_studies
Study.of_interest_to(self)
end
|
#logout_path ⇒ Object
94
95
96
|
# File 'app/models/user.rb', line 94
def logout_path
configatron.authentication == 'sanger-sso' ? configatron.sso_logout_url.to_s : '/logout'
end
|
#manager_or_administrator? ⇒ Boolean
130
131
132
|
# File 'app/models/user.rb', line 130
def manager_or_administrator?
administrator? || manager?
end
|
#name ⇒ Object
114
115
116
|
# File 'app/models/user.rb', line 114
def name
name_incomplete? ? login : "#{first_name} #{last_name}"
end
|
#name_and_login ⇒ Object
118
119
120
|
# File 'app/models/user.rb', line 118
def name_and_login
"#{first_name} #{last_name} (#{login})".strip
end
|
#name_complete? ⇒ Boolean
110
111
112
|
# File 'app/models/user.rb', line 110
def name_complete?
not name_incomplete?
end
|
#name_incomplete? ⇒ Boolean
106
107
108
|
# File 'app/models/user.rb', line 106
def name_incomplete?
first_name.blank? || last_name.blank?
end
|
#new_api_key(length = 32) ⇒ Object
134
135
136
137
138
|
# File 'app/models/user.rb', line 134
def new_api_key(length = 32)
u = Digest::SHA1.hexdigest(login)[0..12]
k = Digest::SHA1.hexdigest(Time.zone.now.to_s + rand(12_341_234).to_s)[1..length]
self.api_key = "#{u}-#{k}"
end
|
#profile_complete? ⇒ Boolean
102
103
104
|
# File 'app/models/user.rb', line 102
def profile_complete?
not profile_incomplete?
end
|
#profile_incomplete? ⇒ Boolean
98
99
100
|
# File 'app/models/user.rb', line 98
def profile_incomplete?
name_incomplete? || email.blank? || swipecard_code.blank?
end
|
#remember_me ⇒ Object
These create and unset the fields required for remembering users between browser closes
150
151
152
153
154
|
# File 'app/models/user.rb', line 150
def remember_me
self.remember_token_expires_at = 2.weeks.from_now.utc
self.remember_token = encrypt("#{email}--#{remember_token_expires_at}")
save(validate: false)
end
|
#remember_token? ⇒ Boolean
145
146
147
|
# File 'app/models/user.rb', line 145
def remember_token?
remember_token_expires_at && Time.now.utc < remember_token_expires_at
end
|
#sorted_study_names_and_ids ⇒ Object
126
127
128
|
# File 'app/models/user.rb', line 126
def sorted_study_names_and_ids
interesting_studies.alphabetical.pluck(:name, :id)
end
|
#study_and_project_roles ⇒ Object
90
91
92
|
# File 'app/models/user.rb', line 90
def study_and_project_roles
roles.where(authorizable_type: %w[Study Project])
end
|
#valid_projects ⇒ Object
122
123
124
|
# File 'app/models/user.rb', line 122
def valid_projects
projects.valid.alphabetical
end
|