Skip to content

Commit 08cd34e

Browse files
FoxMoss3kh0
andauthored
expose more data to admins (#484)
Co-authored-by: Echo <[email protected]>
1 parent 4683f05 commit 08cd34e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

app/controllers/api/admin/v1/admin_controller.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,48 @@ def check
2222
}
2323
end
2424

25+
def get_users_by_ip
26+
user_ip = params[:ip]
27+
28+
if user_ip.blank?
29+
render json: { error: "bro dont got the ip" }, status: :unprocessable_entity
30+
return nil
31+
end
32+
33+
result = Heartbeat.where([ "ip_address = '%s'", user_ip ]).select(:ip_address, :user_id, :machine, :user_agent).distinct
34+
35+
render json: {
36+
users: result.map do |user| {
37+
user_id: user.user_id,
38+
ip_address: user.ip_address,
39+
machine: user.machine,
40+
user_agent: user.user_agent
41+
}
42+
end
43+
}
44+
end
45+
46+
def get_users_by_machine
47+
user_machine = params[:machine]
48+
49+
if user_machine.blank?
50+
render json: { error: "bro dont got the machine" }, status: :unprocessable_entity
51+
return nil
52+
end
53+
54+
result = Heartbeat.where([ "machine = '%s'", user_machine ]).select(:ip_address, :user_id, :machine, :user_agent).distinct
55+
56+
render json: {
57+
users: result.map do |user| {
58+
user_id: user.user_id,
59+
ip_address: user.ip_address,
60+
machine: user.machine,
61+
user_agent: user.user_agent
62+
}
63+
end
64+
}
65+
end
66+
2567
def user_info
2668
user = find_user_by_id
2769
return unless user
@@ -85,6 +127,7 @@ def user_stats
85127
{
86128
id: hb.id,
87129
time: Time.at(hb.time).utc.iso8601,
130+
created_at: hb.created_at,
88131
project: hb.project,
89132
branch: hb.branch,
90133
category: hb.category,

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ def matches?(request)
163163
namespace :v1 do
164164
get "check", to: "admin#check"
165165
get "user/info", to: "admin#user_info"
166+
get "user/get_users_by_ip", to: "admin#get_users_by_ip"
167+
get "user/get_users_by_machine", to: "admin#get_users_by_machine"
166168
get "user/stats", to: "admin#user_stats"
167169
get "user/projects", to: "admin#user_projects"
168170
get "user/trust_logs", to: "admin#trust_logs"

0 commit comments

Comments
 (0)