From 08cd34e6cc545446ae4a80c9ed5c225e14121368 Mon Sep 17 00:00:00 2001 From: Fox Ellson-Taylor Date: Mon, 18 Aug 2025 16:54:54 -0500 Subject: [PATCH] expose more data to admins (#484) Co-authored-by: Echo --- .../api/admin/v1/admin_controller.rb | 43 +++++++++++++++++++ config/routes.rb | 2 + 2 files changed, 45 insertions(+) diff --git a/app/controllers/api/admin/v1/admin_controller.rb b/app/controllers/api/admin/v1/admin_controller.rb index de032b8..31f47a0 100644 --- a/app/controllers/api/admin/v1/admin_controller.rb +++ b/app/controllers/api/admin/v1/admin_controller.rb @@ -22,6 +22,48 @@ module Api } end + def get_users_by_ip + user_ip = params[:ip] + + if user_ip.blank? + render json: { error: "bro dont got the ip" }, status: :unprocessable_entity + return nil + end + + result = Heartbeat.where([ "ip_address = '%s'", user_ip ]).select(:ip_address, :user_id, :machine, :user_agent).distinct + + render json: { + users: result.map do |user| { + user_id: user.user_id, + ip_address: user.ip_address, + machine: user.machine, + user_agent: user.user_agent + } + end + } + end + + def get_users_by_machine + user_machine = params[:machine] + + if user_machine.blank? + render json: { error: "bro dont got the machine" }, status: :unprocessable_entity + return nil + end + + result = Heartbeat.where([ "machine = '%s'", user_machine ]).select(:ip_address, :user_id, :machine, :user_agent).distinct + + render json: { + users: result.map do |user| { + user_id: user.user_id, + ip_address: user.ip_address, + machine: user.machine, + user_agent: user.user_agent + } + end + } + end + def user_info user = find_user_by_id return unless user @@ -85,6 +127,7 @@ module Api { id: hb.id, time: Time.at(hb.time).utc.iso8601, + created_at: hb.created_at, project: hb.project, branch: hb.branch, category: hb.category, diff --git a/config/routes.rb b/config/routes.rb index 21e5469..a2a3632 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -163,6 +163,8 @@ Rails.application.routes.draw do namespace :v1 do get "check", to: "admin#check" get "user/info", to: "admin#user_info" + get "user/get_users_by_ip", to: "admin#get_users_by_ip" + get "user/get_users_by_machine", to: "admin#get_users_by_machine" get "user/stats", to: "admin#user_stats" get "user/projects", to: "admin#user_projects" get "user/trust_logs", to: "admin#trust_logs"