Skip to content
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

feat(accessLogsExport): create new endpoints for access log exports TASK-1147 #5208

Closed
wants to merge 5 commits into from

Conversation

RuthShryock
Copy link
Member

@RuthShryock RuthShryock commented Oct 29, 2024

🗒️ Checklist

  1. run linter locally
  2. update all related docs (API, README, inline, etc.), if any
  3. draft PR with a title <type>(<scope>)<!>: <title> TASK-1234
  4. tag PR: at least frontend or backend unless it's global
  5. fill in the template below and delete template comments
  6. review thyself: read the diff and repro the preview as written
  7. open PR & confirm that CI passes
  8. request reviewers, if needed
  9. delete this section before merging

👷 Description for instance maintainers

Create two new endpoints for access log exports which will return the status of the export job. One endpoint is restricted for superusers and allows them to access all logs while the other endpoint is for regular users to access their own logs.

👀 Preview steps

Test /api/v2/access-logs/export

  1. Login to kpi as a super user.
  2. Make a GET request to /api/v2/access-logs/export
  3. If this is your first time accessing the endpoint, then verify you receive a 404 Not Found with this response:
{
    "error": "No export task found for this user."
} 
  1. If not, verify you receive a 200 Ok with the most status of the most recent created task:
{
    "uid": "uid string",
    "status": "complete"
}
  1. Make a POST request to /api/v2/access-logs/export and verify you receive a 202 Accepted with this response:
[
    "status: created"
]
  1. Logout and try to access the endpoint. Verify you get receive a 401 Unauthorized
    with this response:
{
    "detail": "Authentication credentials were not provided."
}
  1. Login as a regular user and access the endpoint. Verify you receive a 403 Forbidden with this response:
{
    "detail": "Only superusers can export all access logs."
}

Test /api/v2/access-logs/me/export

Follow the same testing instructions above but skip number 7 as both superusers and regular users have the same access to the endpoint.

🟢 Also verify that making a POST request on both endpoints should now generate an email with the follow format:

kpi_worker-1      | MIME-Version: 1.0
kpi_worker-1      | Content-Transfer-Encoding: 7bit
kpi_worker-1      | Subject: Access Log Report Complete
kpi_worker-1      | From: [email protected]
kpi_worker-1      | To: [email protected]
kpi_worker-1      | Date: Wed, 20 Nov 2024 19:19:09 -0000
kpi_worker-1      | Message-ID: <173213034910.27.5732010728174509928@e787dbee7512>
kpi_worker-1      | 
kpi_worker-1      | Hello root,
kpi_worker-1      | 
kpi_worker-1      | Your report is complete: http://kf.kobo.local:8080/private-media/root/exports/access_logs_export-root-view_None-2024-11-20T191909Z.csv
kpi_worker-1      | 
kpi_worker-1      | Regards,
kpi_worker-1      | KoboToolbox

Copy link

@RuthShryock RuthShryock marked this pull request as draft October 31, 2024 17:59
@RuthShryock RuthShryock self-assigned this Nov 11, 2024
@RuthShryock RuthShryock changed the title Create new endpoints for access log exports feat(accessLogsExport): create new endpoints for access log exports TASK-1147 Nov 11, 2024
@RuthShryock RuthShryock deleted the endpoints-for-access-logs-exports branch November 26, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant