diff --git a/zerver/tests/test_realm_export.py b/zerver/tests/test_realm_export.py index 1d9418de34..3d6f06e462 100644 --- a/zerver/tests/test_realm_export.py +++ b/zerver/tests/test_realm_export.py @@ -32,6 +32,7 @@ class RealmExportTest(ZulipTestCase): self.assertEqual(event['realm_id'], 1) self.assertEqual(event['user_profile_id'], 5) self.assertEqual(event['type'], 'realm_exported') + self.assertTrue(type(event['id']), int) with patch('zerver.lib.export.do_export_realm', side_effect=FileNotFoundError) as mock_export: @@ -57,6 +58,7 @@ class RealmExportTest(ZulipTestCase): self.assertEqual(event['realm_id'], 1) self.assertEqual(event['user_profile_id'], 5) self.assertEqual(event['type'], 'realm_exported') + self.assertEqual(type(event['id']), int) with patch('zerver.lib.export.do_export_realm', side_effect=FileNotFoundError) as mock_export: diff --git a/zerver/views/public_export.py b/zerver/views/public_export.py index 89f5c8b963..0044b86603 100644 --- a/zerver/views/public_export.py +++ b/zerver/views/public_export.py @@ -25,14 +25,15 @@ def public_only_realm_export(request: HttpRequest, user: UserProfile) -> HttpRes if len(limit_check) >= time_delta_limit: return json_error(_('Exceeded rate limit.')) - RealmAuditLog.objects.create(realm=realm, - event_type=event_type, - event_time=event_time) + row = RealmAuditLog.objects.create(realm=realm, + event_type=event_type, + event_time=event_time) # Using the deferred_work queue processor to avoid - # killing the process after 60s. + # killing the process after 60s event = {'type': event_type, 'time': event_time, 'realm_id': realm.id, - 'user_profile_id': user.id} + 'user_profile_id': user.id, + 'id': row.id} queue_json_publish('deferred_work', event) return json_success() diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index 5b86eb40a8..74dd2a30f5 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -43,7 +43,7 @@ from zerver.lib.db import reset_queries from zerver.lib.redis_utils import get_redis_client from zerver.context_processors import common_context from zerver.lib.outgoing_webhook import do_rest_call, get_outgoing_webhook_service_handler -from zerver.models import get_bot_services +from zerver.models import get_bot_services, RealmAuditLog from zulip_bots.lib import extract_query_without_mention from zerver.lib.bot_lib import EmbeddedBotHandler, get_bot_handler, EmbeddedBotQuitException from zerver.lib.exceptions import RateLimited @@ -620,6 +620,11 @@ class DeferredWorker(QueueProcessingWorker): delete_after_upload=True) assert public_url is not None + # TODO: This enables support for delete after access, and needs to be tested. + export_event = RealmAuditLog.objects.get(id=event['id']) + export_event.extra_data = public_url + export_event.save(update_fields=['extra_data']) + # Send a private message notification letting the user who # triggered the export know the export finished. user_profile = get_user_profile_by_id(event['user_profile_id'])