Add API endpoint that can be used to trigger an async job to export a database to a zip
Background
After #603 (closed) CoreHandler.export_workspace_applications should be able to generate a zip file containing the export of a single database/application.
The issue
We should add a new API endpoint following the pattern of our other async API endpoints like DuplicateApplicationJobType which:
- Have
/async/at the end of their path - Checks the user has the permission
ExportApplicationOperationType(a new one you should make and only give to Admins indefault_roles.py). Separately this should also be added tobackend/src/baserow/core/permission_manager.py:148 ADMIN_ONLY_OPERATIONS - calls
JobHandler().create_and_start_joband starts a newJobType - You should implement this new
JobTypeby subclassing it and adding it to thejob_type_registry - This job type should have its own Job model for storing the result (see the
DuplicateApplicationJobmodel) - You should implement a new
ActionType(not the undoable base class however just literallyActionTypewhich then. This is so this event shows up in the audit log properly. - This new ActionType should call
CoreHandler.export_workspace_applicationsand upload the resulting ZIP into the default storage with a secure name in a new sub folder just for these exports (the storage bucket can be publicly accessible so the name must be secure and non-guessable). - The URL to access this zip should be saved on the model associated with your job type and returned in its response serializer for the frontend to access later.
- When the job is cleaned up, this file must also be deleted.
- The job type must have the same
transaction_atomic_contextas theDuplicateApplicationJobType - The job type should properly pass through the
progressobject to the CoreHandler so the job's status is updated in realtime for you.
MR Size notes
You might want to split this into two MRs:
- Adds the API endpoint and all it's boilerplate, but it does nothing and responses with 200 OK
- Second MR that implements the JobType + ActionType
Edited by Nigel Gott