-
-
Notifications
You must be signed in to change notification settings - Fork 202
feat(api): add /api/v2/user-reports/
endpoint for superusers DEV-232 DEV-899
#6243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… caculated fields to the seralizer, add pagination, and only allow superusers to access endpoint
…ze-queries-for-subscriptions
507182e
to
3f421d1
Compare
/user-reports/
endpoint for superusers/api/v2/user-reports/
endpoint for superusers
/api/v2/user-reports/
endpoint for superusers/api/v2/user-reports/
endpoint for superusers DEV-232 DEV-899
kobo/apps/user_reports/tasks.py
Outdated
lock_timeout = settings.CELERY_LONG_RUNNING_TASK_TIME_LIMIT + 60 | ||
lock = cache.lock(cache_key, timeout=lock_timeout) | ||
if not lock.acquire(blocking=False, blocking_timeout=0): | ||
logging.error('Task is already running') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was for debugging purpose. I'm wondering if we should keep this. It will probably flood Sentry logs for nothing. Maybe we can change it for logging.info(' Nothing to do, task is already running!)
?
What do you think?
with connection.cursor() as cursor: | ||
cursor.execute('REFRESH MATERIALIZED VIEW user_reports_userreportsmv;') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use an utility function to avoid repeating thse two lines several times?
# Refresh materialized view | ||
with connection.cursor() as cursor: | ||
cursor.execute( | ||
'REFRESH MATERIALIZED VIEW CONCURRENTLY user_reports_userreportsmv;' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably use the same helper here and in the tests.
) FILTER (WHERE sub.id IS NOT NULL), | ||
'[]'::jsonb | ||
)::text AS subscriptions | ||
FROM auth_user au |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to remove anonymous user from the list (e.g. auth_user.id != settings.ANONYMOUS_ID)
…refresh materialized view, improve logging comment
…ze-queries-for-subscriptions
🗒️ Checklist
<type>(<scope>)<!>: <title> DEV-1234
Front end
and/orBack end
orworkflow
📣 Summary
Add a new superuser-only endpoint,
/api/v2/user-reports/
, to access and filter all user usage data.💭 Notes
user_reports
refresh-user-report-snapshot
runs every 30 minutes and works to update the data in batches👀 Preview steps
user_reports
/api/v2/user-reports/
and get a 403 Forbidden errorrefresh-user-report-snapshot
/api/v2/user-reports/
and get 200 with all the users and data