Skip to content
Snippets Groups Projects

Make getting a user by the username case insensitive

Merged William George requested to merge awgeorge1/gitlab-ce:master into master
All threads resolved!
Compare and Show latest version
1 file
+ 4
6
Compare changes
  • Side-by-side
  • Inline
@@ -7,7 +7,6 @@
# times we may want to exclude blocked user. By using this finder (and extending
# it whenever necessary) we can keep this logic in one place.
class UserFinder
def initialize(username_or_id)
@username_or_id = username_or_id
end
@@ -36,7 +35,7 @@ def find_by_username!
# Tries to find a User by username or id, returning nil if none could be found.
def execute
if input_is_id?
if input_is_id?(@username_or_id)
find_by_id
else
find_by_username
@@ -46,15 +45,14 @@ def execute
# Tries to find a User by username or id, raising a `ActiveRecord::RecordNotFound` if it could
# not be found.
def execute!
if input_is_id?
if input_is_id?(@username_or_id)
find_by_id!
else
find_by_username!
end
end
def input_is_id?
@username_or_id =~ /^\d+$/
def input_is_id?(input)
input.is_a?(Numeric) || input =~ /^\d+$/
end
end
Loading