Skip to content

armgit / zulip

Public Imported from GitHub
0

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.py
index 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 = None
diff --git a/zerver/management/commands/export.py b/zerver/management/commands/export.py
index ac2196d78b8..20dd19e7ed4 100644
--- a/zerver/management/commands/export.py
+++ b/zerver/management/commands/export.py
@@ -5,12 +5,13 @@ from typing import Any
from django.conf import settings
from django.core.management.base import CommandError
+from django.utils.timezone import now as timezone_now
from typing_extensions import override
from zerver.actions.realm_settings import do_deactivate_realm
from zerver.lib.export import export_realm_wrapper
from zerver.lib.management import ZulipBaseCommand
-from zerver.models import Message, Reaction, UserProfile
+from zerver.models import Message, Reaction, RealmAuditLog, UserProfile
class 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 parsing
export_realm_wrapper(
realm=realm,