Company deletion
Deleting a company only flags it. A Celery job purges it within about 60 seconds. Deletion starts right away and cannot be undone.
What starts a deletion
- The dashboard calls
DELETE /api/v1/provisioning/companies/{id}. - A staff member deletes the company in Django admin, alone or with the bulk action. Admin never deletes the row directly.
Both set Company.deletion_requested_at. From then on the company:
- is hidden from every company list, including Django admin;
- gets no new tokens (sign-in, refresh, personal access tokens answer 403);
- has its refresh sessions revoked.
The purge job
Celery beat runs companies.purge_deleted_companies every 60 seconds (manage.py purge_deleted_companies does the same run by hand). For each flagged company it:
- Posts
/api/v1/internal/company-deletions(fixed in code) to storage atSTORAGE_SERVICE_URL, hosting atHOSTING_SERVICE_URLand email atEMAIL_SERVICE_URL. Email is called only whenEMAIL_SERVICE_API_KEYis set. A service whose URL is unset is skipped, and each run that has companies to purge logs a warning naming it. The request carries an assertion signed with this server's JWT key: audienceshellui-company-deletion, scopecompany.delete, 60 second lifetime. Services refuse it as a user token, and refuse a user token here. A service that does not answer is asked again on the next run. - Once every service answered, deletes the company and every row tied to it. User accounts stay.
- Sends
identity.company.deletedtoDASHBOARD_WEBHOOK_URL, signed withDASHBOARD_WEBHOOK_SECRET, and retries it each run. An undelivered notice is dropped after 7 days. saas-service also notices the company is gone from the region list.
Each service then purges its own rows and files (S3 or disk) with its own Celery job, also every 60 seconds.
Production
- Run a Celery worker with beat (the Docker entrypoint does) on identity, storage, hosting, email and saas.
- Set
STORAGE_SERVICE_URL,HOSTING_SERVICE_URL,EMAIL_SERVICE_URL,DASHBOARD_WEBHOOK_URLandDASHBOARD_WEBHOOK_SECRETon each region.