@@ -6,8 +6,8 @@ class User < ActiveRecord::Base
66 # Include default devise modules. Others available are:
77 # :token_authenticatable, :confirmable,
88 # :lockable, :timeoutable and :omniauthable
9- devise :invitable , :database_authenticatable , :registerable , :recoverable ,
10- :rememberable , :trackable , :validatable , :omniauthable ,
9+ devise :invitable , :database_authenticatable , :registerable , :recoverable ,
10+ :rememberable , :trackable , :validatable , :omniauthable ,
1111 :omniauth_providers => [ :shibboleth , :orcid ]
1212
1313 ##
@@ -26,27 +26,27 @@ def filter(query)
2626 q = "%#{ query } %"
2727 conditions = t [ :title ] . matches ( q )
2828 columns = %i(
29- grant_number identifier description principal_investigator data_contact
29+ grant_number identifier description principal_investigator data_contact
3030 )
3131 columns = [ 'grant_number' , 'identifier' , 'description' , 'principal_investigator' , 'data_contact' ]
3232 columns . each { |col | conditions = conditions . or ( t [ col ] . matches ( q ) ) }
3333 self . where ( conditions )
3434 end
3535 end
36-
36+
3737 has_many :user_identifiers
3838 has_many :identifier_schemes , through : :user_identifiers
3939
4040 ##
4141 # Possibly needed for active_admin
4242 # -relies on protected_attributes gem as syntax depricated in rails 4.2
4343 #accepts_nested_attributes_for :roles
44- #attr_accessible :password_confirmation, :encrypted_password, :remember_me,
45- # :id, :email, :firstname, :last_login,:login_count, :orcid_id,
46- # :password, :shibboleth_id, :user_status_id, :surname,
47- # :user_type_id, :org_id, :skip_invitation, :other_organisation,
44+ #attr_accessible :password_confirmation, :encrypted_password, :remember_me,
45+ # :id, :email, :firstname, :last_login,:login_count, :orcid_id,
46+ # :password, :shibboleth_id, :user_status_id, :surname,
47+ # :user_type_id, :org_id, :skip_invitation, :other_organisation,
4848 # :accept_terms, :role_ids, :dmponline3, :api_token,
49- # :organisation, :language, :language_id, :org, :perms,
49+ # :organisation, :language, :language_id, :org, :perms,
5050 # :confirmed_at, :org_id
5151
5252 validates :email , email : true , allow_nil : true , uniqueness : { message : _ ( "must be unique" ) }
@@ -62,13 +62,13 @@ def filter(query)
6262 # What do they do? do they do it efficiently, and do we need them?
6363
6464 # Determines the locale set for the user or the organisation he/she belongs
65- # @return String or nil
65+ # @return String or nil
6666 def get_locale
6767 if !self . language . nil?
6868 return self . language . abbreviation
6969 elsif !self . org . nil?
7070 return self . org . get_locale
71- else
71+ else
7272 return nil
7373 end
7474 end
@@ -126,7 +126,7 @@ def org_id=(new_org_id)
126126 def organisation = ( new_org )
127127 org_id = new_org . id unless new_org . nil?
128128 end
129-
129+
130130 ##
131131 # checks if the user is a super admin
132132 # if the user has any privelege which requires them to see the super admin page
@@ -144,7 +144,7 @@ def can_super_admin?
144144 #
145145 # @return [Boolean] true if the user is an organisation admin
146146 def can_org_admin?
147- return self . can_grant_permissions? || self . can_modify_guidance? ||
147+ return self . can_grant_permissions? || self . can_modify_guidance? ||
148148 self . can_modify_templates? || self . can_modify_org_details?
149149 end
150150
@@ -223,7 +223,7 @@ def org_type
223223 return org_type
224224 end
225225=end
226-
226+
227227 ##
228228 # removes the api_token from the user
229229 # modifies the user model
@@ -254,11 +254,11 @@ def keep_or_generate_token!
254254 # --------------------------------------------------------------
255255 def self . from_omniauth ( auth )
256256 scheme = IdentifierScheme . find_by ( name : auth . provider . downcase )
257-
257+
258258 if scheme . nil?
259259 throw Exception . new ( 'Unknown OAuth provider: ' + auth . provider )
260260 else
261- joins ( :user_identifiers ) . where ( 'user_identifiers.identifier' : auth . uid ,
261+ joins ( :user_identifiers ) . where ( 'user_identifiers.identifier' : auth . uid ,
262262 'user_identifiers.identifier_scheme_id' : scheme . id ) . first
263263 end
264264 end
@@ -269,7 +269,14 @@ def self.from_omniauth(auth)
269269 def deliver_invitation ( options = { } )
270270 super ( options . merge ( subject : _ ( 'A Data Management Plan in %{application_name} has been shared with you' ) % { application_name : Rails . configuration . branding [ :application ] [ :name ] } ) )
271271 end
272-
272+ ##
273+ # Case insensitive search over User model
274+ # @param field [string] The name of the field being queried
275+ # @param val [string] The string to search for, case insensitive
276+ # @return [ActiveRecord::Relation] The result of the search
277+ def self . where_case_insensitive ( field , val )
278+ User . where ( "lower(#{ field } ) = ?" , val . downcase )
279+ end
273280
274281# TODO: Remove this, its never called.
275282 # this generates a reset password link for a given user
@@ -278,12 +285,12 @@ def deliver_invitation(options = {})
278285=begin
279286 def reset_password_link
280287 raw, enc = Devise.token_generator.generate(self.class, :reset_password_token)
281- self.reset_password_token = enc
288+ self.reset_password_token = enc
282289 self.reset_password_sent_at = Time.now.utc
283290 save(validate: false)
284291
285292 edit_user_password_path + '?reset_password_token=' + raw
286293 end
287294=end
288-
295+
289296end
0 commit comments