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
2 files
+ 40
4
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -7,8 +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
attr_reader :username_or_id,
def initialize(username_or_id)
@username_or_id = username_or_id
end
@@ -37,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 @username_or_id =~ /^\d+$/
if input_is_id?(@username_or_id)
find_by_id
else
find_by_username
@@ -47,10 +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 @username_or_id =~ /^\d+$/
if input_is_id?(@username_or_id)
find_by_id!
else
find_by_username!
end
end
def input_is_id?(input)
input.is_a?(Numeric) || input =~ /^\d+$/
end
end
Loading