Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
export: Create REALM_EXPORTED audit log for exports via shell.
Prakhar Pratyushcc793612f096
diff --git a/zerver/lib/export.py b/zerver/lib/export.pyindex 533d2a3809d..997f2cf4da4 100644--- a/zerver/lib/export.py+++ b/zerver/lib/export.py@@ -2418,9 +2418,15 @@ def export_realm_wrapper(def get_realm_exports_serialized(user: UserProfile) -> List[Dict[str, Any]]:+ # Exclude exports made via shell. 'acting_user=None', since they+ # aren't supported in the current API format.+ #+ # TODO: We should return those via the API as well, with an+ # appropriate way to express for who issued them; this requires an+ # API change.all_exports = RealmAuditLog.objects.filter(realm=user.realm, event_type=RealmAuditLog.REALM_EXPORTED- )+ ).exclude(acting_user=None)exports_dict = {}for export in all_exports:export_url = Nonediff --git a/zerver/management/commands/export.py b/zerver/management/commands/export.pyindex ac2196d78b8..20dd19e7ed4 100644--- a/zerver/management/commands/export.py+++ b/zerver/management/commands/export.py@@ -5,12 +5,13 @@ from typing import Anyfrom django.conf import settingsfrom django.core.management.base import CommandError+from django.utils.timezone import now as timezone_nowfrom typing_extensions import overridefrom zerver.actions.realm_settings import do_deactivate_realmfrom zerver.lib.export import export_realm_wrapperfrom zerver.lib.management import ZulipBaseCommand-from zerver.models import Message, Reaction, UserProfile+from zerver.models import Message, Reaction, RealmAuditLog, UserProfileclass Command(ZulipBaseCommand):@@ -206,6 +207,13 @@ class Command(ZulipBaseCommand):def percent_callback(bytes_transferred: Any) -> None:print(end=".", flush=True)+ RealmAuditLog.objects.create(+ acting_user=None,+ realm=realm,+ event_type=RealmAuditLog.REALM_EXPORTED,+ event_time=timezone_now(),+ )+# Allows us to trigger exports separately from command line argument parsingexport_realm_wrapper(realm=realm,