mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
better lookup method on apis
This commit is contained in:
@@ -166,13 +166,35 @@ class Api::V1::StatsController < ApplicationController
|
||||
if identifier == "my" && token.present?
|
||||
ApiKey.find_by(token: token)&.user
|
||||
else
|
||||
User.find_by(id: identifier) ||
|
||||
User.find_by(slack_uid: identifier) ||
|
||||
User.find_by(username: identifier)
|
||||
lookup_user(identifier)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def lookup_user(id)
|
||||
return nil if id.blank?
|
||||
|
||||
if id.match?(/^\d+$/)
|
||||
user = User.find_by(id: id)
|
||||
return user if user
|
||||
end
|
||||
|
||||
user = User.find_by(slack_uid: id)
|
||||
return user if user
|
||||
|
||||
# email lookup, but you really should not be using this cuz like wtf
|
||||
# if identifier.include?("@")
|
||||
# email_record = EmailAddress.find_by(email: identifier)
|
||||
# return email_record.user if email_record
|
||||
# end
|
||||
|
||||
user = User.find_by(username: id)
|
||||
return user if user
|
||||
|
||||
# skill issue zone
|
||||
nil
|
||||
end
|
||||
|
||||
def ensure_authenticated!
|
||||
token = request.headers["Authorization"]&.split(" ")&.last
|
||||
token ||= params[:api_key]
|
||||
|
||||
Reference in New Issue
Block a user