mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 19:55:16 +00:00
expose more data to admins (#484)
Co-authored-by: Echo <github@3kh0.net>
This commit is contained in:
parent
4683f05505
commit
08cd34e6cc
2 changed files with 45 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue