Conversation
There was a problem hiding this comment.
Pull request overview
This PR restructures the User model into smaller concerns and refactors the admin “quantized visualization” endpoint to use a dedicated service object, with accompanying tests and Swagger/RSwag documentation updates.
Changes:
- Extracts
Userresponsibilities into concerns (Users::Identity,Users::AdminAndTrust,Users::Profile,Users::Authentication). - Introduces
Admin::VisualizationQuantizedQueryservice and updatesAdminController#visualization_quantizedto delegate to it. - Adds request/docs coverage for the new admin visualization endpoint and a unit test for the query service.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| test/services/admin/visualization_quantized_query_test.rb | Adds Minitest coverage for the new quantized query service. |
| swagger/v1/swagger.yaml | Documents the new admin visualization endpoint and updates username nullability. |
| spec/requests/api/admin/v1/admin_user_utils_spec.rb | Adds RSwag coverage for the new endpoint and updates schema for nullable username. |
| app/services/admin/visualization_quantized_query.rb | New service implementing quantized point selection + daily totals computation. |
| app/models/user.rb | Slims the model by including newly extracted concerns. |
| app/models/concerns/users/profile.rb | New concern containing profile/display-related methods (avatar/name/timezone parsing, etc.). |
| app/models/concerns/users/identity.rb | New concern containing identity lookup/search + username normalization/validation helpers. |
| app/models/concerns/users/authentication.rb | New concern containing token + API key rotation helpers. |
| app/models/concerns/users/admin_and_trust.rb | New concern containing trust/admin enums and related behaviors. |
| app/controllers/api/admin/v1/admin_controller.rb | Refactors visualization_quantized to call the new service and map errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Greptile SummaryThis PR refactors the Confidence Score: 5/5Safe to merge — all findings are P2 style/consistency suggestions with no blocking correctness issues. Both comments are P2: one is a concern-placement design smell (not_convicted/not_suspect) and the other is a pre-existing timezone inconsistency now surfaced in the new service. Neither breaks current behaviour in a UTC-hosted environment. Tests and Rswag specs are included for the new service. app/models/concerns/users/identity.rb (cross-concern scope placement), app/services/admin/visualization_quantized_query.rb (local-TZ date resolution) Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
U[User model] --> UI[Users::Identity\nscopes, lookup_by_identifier\nnormalize_username]
U --> UAT[Users::AdminAndTrust\ntrust_level enum\nadmin_level enum\nset_trust / set_admin_level]
U --> UP[Users::Profile\navatar_url, display_name\nformat_extension_text]
U --> UA[Users::Authentication\nrotate_api_keys!\ncreate_email_signin_token]
C[AdminController\nGET quantized] --> VQQ[Admin::VisualizationQuantizedQuery\nvalidate month\nbuild epochs\nexecute SQL\nreturn Result struct]
VQQ --> DB[(PostgreSQL\nheartbeats)]
VQQ --> RES{Result}
RES -->|success?| JSON_OK[render json: days]
RES -->|failure| JSON_ERR[render 422 error]
UI -.->|depends on trust_levels from| UAT
Prompt To Fix All With AIThis is a comment left during a code review.
Path: app/models/concerns/users/identity.rb
Line: 49-55
Comment:
**Cross-concern dependency: trust scopes belong in `AdminAndTrust`**
`not_convicted` and `not_suspect` call `trust_levels[...]`, which is a class method generated by `enum :trust_level` defined in `Users::AdminAndTrust`. Placing these scopes in `Identity` creates a hidden coupling — any future use of `Users::Identity` without `Users::AdminAndTrust` would raise `NoMethodError`. Since these scopes are semantically about trust levels, they belong in `Users::AdminAndTrust` alongside the enum definition.
```suggestion
end
if Rails.env.development?
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: app/services/admin/visualization_quantized_query.rb
Line: 61-73
Comment:
**Local timezone used for UTC epoch day boundaries**
`Time.at(epoch).to_date` and `Time.at(row["time"].to_f).to_date` both resolve dates in the **server's local timezone**, while `start_epoch`/`end_epoch` are generated with `Time.utc(...)`. On a server not running in UTC, the day-boundary epochs (e.g. 2026-01-02 00:00 UTC) would map to the previous date in a UTC− timezone, causing `daily_totals[day]` and `points_by_day[day]` lookups to miss or return data for the wrong day. Use `.utc.to_date` to stay consistent with the UTC-based epochs.
```suggestion
def build_points_by_day(rows)
rows.each_with_object({}) do |row, hash|
day = Time.at(row["time"].to_f).utc.to_date
hash[day] ||= []
hash[day] << {
time: row["time"],
lineno: row["lineno"],
cursorpos: row["cursorpos"]
}
end
end
def build_days(start_epoch, end_epoch, daily_totals, points_by_day)
(start_epoch...end_epoch).step(86_400).map do |epoch|
day = Time.at(epoch).utc.to_date
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Clean up `User` model + `AdminController..." | Re-trigger Greptile |
|
@greptileai thoughts? |
| ) if !!user | ||
|
|
||
| @user ||= begin | ||
| user ||= begin |
|
Overall this is a solid cleanup. The big wins are clear: What's working well:
One minor nit:
scope :not_convicted, -> { where.not(trust_level: trust_levels[:red]) }
scope :not_suspect, -> { where(trust_level: [ trust_levels[:blue], trust_levels[:green] ]) }One thing to double-check:
Otherwise, clean and mergeable. |
No description provided.