Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ def index
end

def show
@user = User.find(params[:id])

if params[:id] == "me"
@user = current_api_user
else
@user = User.find(params[:id])
end
rescue ActiveRecord::RecordNotFound
render json: { error: "User not found" }, status: :not_found
end
Expand Down
12 changes: 10 additions & 2 deletions app/controllers/concerns/extension_usage_trackable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ module ExtensionUsageTrackable
private

def track_extension_usage
return unless current_user
api_key = request.headers["Authorization"]&.remove("Bearer ")

user = current_user

if api_key.present?
user = User.find_by(api_key: api_key)
end

return unless user
return unless redis_available?

project_ids = extract_extension_project_ids
Expand All @@ -17,7 +25,7 @@ def track_extension_usage
timestamp = Time.current.iso8601

payloads = project_ids.map do |project_id|
{ project_id: project_id, user_id: current_user.id, recorded_at: timestamp }.to_json
{ project_id: project_id, user_id: user.id, recorded_at: timestamp }.to_json
end

Rails.cache.redis.with do |redis|
Expand Down
Loading