Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(accessLogsExport): create new endpoints TASK-1147 (#5304)
### 👷 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 200 Ok with an empty list: ```json [] ``` 1. If not, verify you receive a 200 Ok with a list of created export tasks: ```json [ { "uid": "alezKqwR8diLDQEepA83Rz4V", "status": "complete", "date_created": "2024-12-03T17:29:21.602245Z" }, { "uid": "aleyTYvQjKT4QAcFztyYNHVC", "status": "created", "date_created": "2024-12-03T00:01:32.580491Z" }, { "uid": "alebV6fWMgUARPmCBJDKQGKQ", "status": "complete", "date_created": "2024-12-02T23:59:47.426752Z" } ] ``` 1. Make a POST request to /api/v2/access-logs/export and verify you receive a 202 Accepted with this response: ```json [ "status: created" ] ``` 1. Logout and try to access the endpoint. Verify you get receive a 401 Unauthorized with this response: ```json { "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: ```json { "detail": "You do not have permission to perform this action." } ``` ### 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: webmaster@localhost kpi_worker-1 | To: test@test.com kpi_worker-1 | Date: Wed, 27 Nov 2024 19:38:29 -0000 kpi_worker-1 | Message-ID: <173273630990.23.10232391233968451994@948bfe8772ce> kpi_worker-1 | kpi_worker-1 | Hello test, kpi_worker-1 | kpi_worker-1 | Your report is complete: http://kf.kobo.local:8080/private-media/test/exports/access_logs_export-test-2024-11-27T193829Z.csv kpi_worker-1 | kpi_worker-1 | Regards, kpi_worker-1 | KoboToolbox ``` --------- Co-authored-by: Rebecca Graber <becca.graber@kobotoolbox.org>
- Loading branch information