Skip to content
Open
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
13 changes: 6 additions & 7 deletions app/javascript/pages/Admin/LeaderboardShadowbans.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
const redButtonClass =
"!border-red !bg-red !text-on-primary hover:!opacity-90";

type Pending =
| { kind: "ban" }
| { kind: "unban"; user: ShadowbannedUser };
type Pending = { kind: "ban" } | { kind: "unban"; user: ShadowbannedUser };

let selectedUser = $state<UserPickerResult | null>(null);
let reason = $state("");
Expand Down Expand Up @@ -147,7 +145,10 @@

<Modal
bind:open={
() => pending !== null, (v) => { if (!v) pending = null; }
() => pending !== null,
(v) => {
if (!v) pending = null;
}
}
title={pending?.kind === "unban"
? "Remove leaderboard shadowban?"
Expand Down Expand Up @@ -179,9 +180,7 @@
{#if submitting}
{pending?.kind === "unban" ? "Removing..." : "Saving..."}
{:else}
{pending?.kind === "unban"
? "Remove shadowban"
: "Confirm shadowban"}
{pending?.kind === "unban" ? "Remove shadowban" : "Confirm shadowban"}
{/if}
</Button>
</div>
Expand Down
65 changes: 0 additions & 65 deletions spec/requests/api/admin/v1/admin_timeline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,6 @@
parameter name: :slack_uids, in: :query, type: :string, description: 'Comma-separated list of Slack User IDs'

response(200, 'successful') do
schema type: :object,
properties: {
date: { type: :string, format: :date },
next_date: { type: :string, format: :date },
prev_date: { type: :string, format: :date },
users: {
type: :array,
items: {
type: :object,
properties: {
user: {
type: :object,
properties: {
id: { type: :integer },
username: { type: :string },
display_name: { type: :string, nullable: true },
slack_username: { type: :string, nullable: true },
github_username: { type: :string, nullable: true },
timezone: { type: :string, nullable: true },
avatar_url: { type: :string, nullable: true }
}
},
spans: {
type: :array,
items: {
type: :object,
properties: {
start_time: { type: :number, format: :float },
end_time: { type: :number, format: :float },
duration: { type: :number, format: :float },
files_edited: { type: :array, items: { type: :string } },
projects_edited_details: {
type: :array,
items: {
type: :object,
properties: {
name: { type: :string },
repo_url: { type: :string, nullable: true }
}
}
},
editors: { type: :array, items: { type: :string } },
languages: { type: :array, items: { type: :string } }
}
}
},
total_coded_time: { type: :number, format: :float }
}
}
},
commit_markers: {
type: :array,
items: {
type: :object,
properties: {
user_id: { type: :integer },
timestamp: { type: :number, format: :float },
additions: { type: :integer, nullable: true },
deletions: { type: :integer, nullable: true },
github_url: { type: :string, nullable: true }
}
}
}
}

let(:Authorization) { "Bearer dev-admin-api-key-12345" }
let(:date) { Time.current.to_date.to_s }
let(:user_ids) { User.first&.id.to_s }
Expand Down
92 changes: 7 additions & 85 deletions spec/requests/api/admin/v1/admin_user_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@
properties: {
id: { type: :integer },
time: { type: :number },
lineno: { type: :integer, nullable: true },
cursorpos: { type: :integer, nullable: true },
lineno: { type: :integer },
cursorpos: { type: :integer },
is_write: { type: :boolean, nullable: true },
project: { type: :string, nullable: true },
language: { type: :string, nullable: true },
Expand Down Expand Up @@ -326,87 +326,6 @@
run_test!
end

response(200, 'successful') do
schema oneOf: [
{
type: :object,
properties: {
segment: { type: :string },
limit: { type: :integer },
offset: { type: :integer },
heartbeats: {
type: :array,
items: {
type: :object,
properties: {
id: { type: :integer },
user_id: { type: :integer },
time: { type: :number },
project: { type: :string, nullable: true },
language: { type: :string, nullable: true },
entity: { type: :string, nullable: true },
branch: { type: :string, nullable: true },
category: { type: :string, nullable: true },
editor: { type: :string, nullable: true },
machine: { type: :string, nullable: true },
operating_system: { type: :string, nullable: true },
user_agent: { type: :string, nullable: true },
ip_address: { type: :string, nullable: true },
is_write: { type: :boolean, nullable: true },
lineno: { type: :integer, nullable: true },
cursorpos: { type: :integer, nullable: true },
lines: { type: :integer, nullable: true },
source_type: { type: :string, nullable: true }
}
}
},
has_more: { type: :boolean }
}
},
{
type: :object,
description: 'Returned when count_only=true',
additionalProperties: false,
required: [ 'segment', 'total_count' ],
properties: {
segment: { type: :string },
total_count: { type: :integer }
}
}
]

let(:Authorization) { "Bearer dev-admin-api-key-12345" }
let(:hb_user_doc) do
u = User.create!(username: 'hb_segment_doc_user')
EmailAddress.create!(user: u, email: 'hb-segment-doc@example.com')
u
end
before do
Heartbeat.create!(
user: hb_user_doc,
time: Time.current.to_i,
project: 'demo',
language: 'GDScript',
editor: 'Godot',
source_type: :direct_entry,
branch: 'main',
category: 'coding',
is_write: true,
user_agent: 'Godot/4.2 Godot_Super-Wakatime/2.0.0',
operating_system: 'linux',
machine: 'test-machine'
)
end
let(:segment) { 'Godot_Super-Wakatime' }
let(:user_id) { nil }
let(:start_date) { nil }
let(:end_date) { nil }
let(:limit) { 10 }
let(:offset) { 0 }
let(:count_only) { nil }
run_test!
end

response(422, 'missing segment') do
let(:Authorization) { "Bearer dev-admin-api-key-12345" }
let(:segment) { '' }
Expand Down Expand Up @@ -569,7 +488,8 @@
properties: {
user_id: { type: :integer },
username: { type: :string },
date: { type: :string, format: :date_time },
start_date: { type: :string, format: :date_time },
end_date: { type: :string, format: :date_time },
timezone: { type: :string, nullable: true },
total_heartbeats: { type: :integer },
total_duration: { type: :number },
Expand Down Expand Up @@ -793,7 +713,9 @@
type: :object,
properties: {
user_id: { type: :integer },
reason: { type: :string }
reason: { type: :string },
trust_level: { type: :string },
notes: { type: :string }
}
}

Expand Down
37 changes: 0 additions & 37 deletions spec/requests/api/admin/v1/admin_users_spec.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
require 'swagger_helper'

RSpec.describe 'Api::Admin::V1::AdminUsers', type: :request do
path '/api/admin/v1/user/info' do
get('Get user info (Admin)') do
tags 'Admin'
description 'Get detailed info about a user. Requires superadmin/admin privileges.'
security [ AdminToken: [] ]
produces 'application/json'

parameter name: :user_id, in: :query, type: :string, description: 'User ID'

response(200, 'successful') do
let(:Authorization) { "Bearer dev-admin-api-key-12345" }
let(:user_id) { '1' }
let(:date) { '2023-01-01' }
run_test!
end
end
end

path '/api/admin/v1/user/heartbeats' do
get('Get user heartbeats (Admin)') do
tags 'Admin'
description 'Get raw heartbeats for a user.'
security [ AdminToken: [] ]
produces 'application/json'

parameter name: :user_id, in: :query, type: :string, description: 'User ID'
parameter name: :date, in: :query, schema: { type: :string, format: :date }, description: 'Date (YYYY-MM-DD)'

response(200, 'successful') do
let(:Authorization) { "Bearer dev-admin-api-key-12345" }
let(:user_id) { '1' }
let(:date) { '2023-01-01' }
run_test!
end
end
end

path '/api/admin/v1/check' do
get('Check status') do
tags 'Admin'
Expand Down
18 changes: 14 additions & 4 deletions spec/requests/api/hackatime/v1/compatibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
tags 'WakaTime Compatibility'
description 'Endpoint used by WakaTime plugins to send heartbeat data to the server. This is the core endpoint for tracking time.'
consumes 'application/json'
security [ Bearer: [], ApiKeyAuth: [] ]
security [ { Bearer: [] }, { ApiKeyAuth: [] } ]

parameter name: :id, in: :path, type: :string, description: 'User ID or "current" (recommended)'
parameter name: :heartbeats, in: :body, schema: {
Expand All @@ -24,7 +24,17 @@
lineno: { type: :integer },
cursorpos: { type: :integer },
lines: { type: :integer },
category: { type: :string }
category: { type: :string },
created_at: { type: :string, format: :date_time },
dependencies: { type: :array, items: { type: :string } },
editor: { type: :string },
line_additions: { type: :integer },
line_deletions: { type: :integer },
machine: { type: :string },
operating_system: { type: :string },
project_root_count: { type: :integer },
user_agent: { type: :string },
plugin: { type: :string }
}
}
}
Expand Down Expand Up @@ -72,7 +82,7 @@
get('Get status bar today') do
tags 'WakaTime Compatibility'
description 'Returns the total coding time for today. Used by editor plugins to display the status bar widget.'
security [ Bearer: [], ApiKeyAuth: [] ]
security [ { Bearer: [] }, { ApiKeyAuth: [] } ]
produces 'application/json'

parameter name: :id, in: :path, type: :string, description: 'User ID or "current"'
Expand Down Expand Up @@ -122,7 +132,7 @@
get('Get last 7 days stats') do
tags 'WakaTime Compatibility'
description 'Returns coding statistics for the last 7 days. Used by some WakaTime dashboards.'
security [ Bearer: [], ApiKeyAuth: [] ]
security [ { Bearer: [] }, { ApiKeyAuth: [] } ]
produces 'application/json'

response(200, 'successful') do
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/api/internal/internal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
success: { type: :boolean },
status: { type: :string },
token_type: { type: :string },
owner_email: { type: :string, nullable: true },
key_name: { type: :string, nullable: true }
owner_email: { type: :string },
key_name: { type: :string }
}
run_test! do |response|
body = JSON.parse(response.body)
Expand Down
21 changes: 19 additions & 2 deletions spec/requests/api/summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
path '/api/summary' do
get('Get WakaTime-compatible summary') do
tags 'WakaTime Compatibility'
description 'Returns a summary of coding activity in a format compatible with WakaTime clients. This endpoint supports querying by date range, interval, or specific user (admin/privileged only).'
security [ Bearer: [], ApiKeyAuth: [] ]
description 'Returns a public summary of coding activity in a format compatible with WakaTime clients.'
produces 'application/json'

parameter name: :start, in: :query, schema: { type: :string, format: :date }, description: 'Start date (YYYY-MM-DD)'
parameter name: :end, in: :query, schema: { type: :string, format: :date }, description: 'End date (YYYY-MM-DD)'
parameter name: :from, in: :query, schema: { type: :string, format: :date }, required: false, description: 'Alias for start (YYYY-MM-DD)'
parameter name: :to, in: :query, schema: { type: :string, format: :date }, required: false, description: 'Alias for end (YYYY-MM-DD)'
parameter name: :range, in: :query, type: :string, required: false, description: 'Predefined range (e.g. today, yesterday, week, month). Alias for interval.'
parameter name: :interval, in: :query, type: :string, description: 'Interval (e.g. today, yesterday, week, month)'
parameter name: :project, in: :query, type: :string, description: 'Project name (optional)'
parameter name: :user_id, in: :query, type: :string, required: true, description: 'User identifier (slack_uid, username, hca_id, or numeric ID)'
Expand All @@ -22,6 +24,9 @@
let(:start) { '2023-01-01' }
let(:end) { '2023-01-31' }
let(:interval) { nil }
let(:from) { nil }
let(:to) { nil }
let(:range) { nil }
let(:project) { nil }
let(:user_id) { test_user.slack_uid }
let(:user) { nil }
Expand Down Expand Up @@ -67,6 +72,9 @@
let(:start) { '2023-01-01' }
let(:end) { '2023-01-31' }
let(:interval) { nil }
let(:from) { nil }
let(:to) { nil }
let(:range) { nil }
let(:project) { nil }
let(:user_id) { nil }
let(:user) { nil }
Expand All @@ -80,6 +88,9 @@
let(:start) { 'invalid-date' }
let(:end) { '2023-01-31' }
let(:interval) { nil }
let(:from) { nil }
let(:to) { nil }
let(:range) { nil }
let(:project) { nil }
let(:user_id) { date_test_user.slack_uid }
let(:user) { nil }
Expand All @@ -92,6 +103,9 @@
let(:start) { '2023-01-01' }
let(:end) { '2023-01-31' }
let(:interval) { nil }
let(:from) { nil }
let(:to) { nil }
let(:range) { nil }
let(:project) { nil }
let(:user_id) { 'nonexistent-user-id' }
let(:user) { nil }
Expand All @@ -105,6 +119,9 @@
let(:start) { '2023-01-01' }
let(:end) { '2023-01-31' }
let(:interval) { nil }
let(:from) { nil }
let(:to) { nil }
let(:range) { nil }
let(:project) { nil }
let(:user_id) { private_user.slack_uid }
let(:user) { nil }
Expand Down
Loading
Loading