• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kobotoolbox / kpi / 18562672376
81%
master: 76%

Build:
Build:
LAST BUILD BRANCH: beccagraber/dev-1497-show-most-recently-created-qual-answer
DEFAULT BRANCH: master
Ran 16 Oct 2025 01:54PM UTC
Jobs 2
Files 876
Run time 2min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

16 Oct 2025 01:20PM UTC coverage: 81.282% (+0.1%) from 81.167%
18562672376

push

github

web-flow
feat(userReports): add `/api/v2/user-reports/` endpoint for superusers DEV-232 DEV-899 (#6243)

### đŸ“Ŗ Summary
Add a new superuser-only endpoint, `/api/v2/user-reports/`, to access
and filter all user usage data.

### 💭 Notes
- Created a new Django app `user_reports` 
- Used a SQL materialized view along with some Django tables to gather
and calculate all the data for the endpoint
- Our celery task `refresh_user_report_snapshots` runs every 30 minutes
and works to update the data in batches
- The endpoint is only accessible if Stripe is enabled 
- Renamed api tag "Audit logs (superusers)" to "Server logs
(superusers)" ([Zulip
thread](https://chat.kobotoolbox.org/#narrow/stream/4-Kobo-Dev/topic/API.20Documentation/near/713167))


### 📖 Description

This PR introduces a new endpoint `/api/v2/user-reports` that provides
detailed information about users, including their personal details,
metadata, organization info, subscriptions, usage statistics, and
computed balances. It supports flexible nested filtering, allowing
queries like:
```
/api/v2/user-reports/?q=username__icontains:demo
/api/v2/user-reports/?q=service_usage__total_storage_bytes__gte:1
/api/v2/user-reports/?q=service_usage__balances__submission__balance_value__gte:5000
```
To handle a large user base, the endpoint leverages a PostgreSQL
materialized view that aggregates user-related data for fast retrieval.
Since some data (like usage and submissions) lives in another database,
a periodic Celery task `refresh_user_report_snapshots` was added to
pre-compute and store this data in a new `BillingAndUsageSnapshot`
table. The materialized view references this snapshot for further
computations. A `BillingAndUsageSnapshotRun` table was also added to
track each run and safely resume interrupted jobs.


### 👀 Preview steps

1. â„šī¸ have a superuser account and multiple regular users in multiple
organizations
2. create projects, make submissions, and buy stripe subscriptions
3. checkout this branch and ru... (continued)

7057 of 11105 branches covered (63.55%)

303 of 330 new or added lines in 15 files covered. (91.82%)

27262 of 33540 relevant lines covered (81.28%)

1.6 hits per line

New Missed Lines in Diff

Lines Coverage ∆ File
1
98.46
kobo/apps/user_reports/models.py
1
97.14
kobo/apps/user_reports/views.py
2
95.24
kobo/apps/user_reports/utils/snapshot_refresh_helpers.py
2
90.91
kpi/schema_extensions/v2/user_reports/extensions.py
3
29.79
8.36% kobo/apps/stripe/utils/billing_dates.py
4
90.0
kobo/apps/user_reports/utils/billing_and_usage_calculator.py
6
84.21
kobo/apps/user_reports/seralizers.py
8
78.38
kobo/apps/user_reports/tasks.py
Jobs
ID Job ID Ran Files Coverage
1 18562672376.1 16 Oct 2025 01:54PM UTC 874
78.88
2 18562672376.2 16 Oct 2025 01:57PM UTC 876
81.25
Source Files on build 18562672376
  • Tree
  • List 876
  • Changed 6
  • Source Changed 0
  • Coverage Changed 6
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Repo
  • 5ad4774e on github
  • Prev Build on main (#18555349255)
  • Next Build on main (#18565438923)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc