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
1 file
+ 6
3
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
attr_reader :username_or_id,
def initialize(username_or_id)
@username_or_id = username_or_id
@@ -37,7 +36,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?
find_by_id
else
find_by_username
@@ -47,10 +46,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?
find_by_id!
else
find_by_username!
end
end
def input_is_id?
@username_or_id =~ /^\d+$/
end
end
Loading