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.

analytics: Create a RealmAuditLog entry when subscribing test users.

Alex Vandiver505eec4bac07
diff --git a/analytics/management/commands/populate_analytics_db.py b/analytics/management/commands/populate_analytics_db.py
index bfca7b38bd5..57cdd9715c3 100644
--- a/analytics/management/commands/populate_analytics_db.py
+++ b/analytics/management/commands/populate_analytics_db.py
@@ -24,7 +24,16 @@ from zerver.lib.storage import static_path
from zerver.lib.stream_color import STREAM_ASSIGNMENT_COLORS
from zerver.lib.timestamp import floor_to_day
from zerver.lib.upload import upload_message_attachment_from_request
-from zerver.models import Client, Realm, Recipient, Stream, Subscription, UserGroup, UserProfile
+from zerver.models import (
+ Client,
+ Realm,
+ RealmAuditLog,
+ Recipient,
+ Stream,
+ Subscription,
+ UserGroup,
+ UserProfile,
+)
class Command(BaseCommand):
@@ -116,16 +125,20 @@ class Command(BaseCommand):
stream.save(update_fields=["recipient"])
# Subscribe shylock to the stream to avoid invariant failures.
- # TODO: This should use subscribe_users_to_streams from populate_db.
- subs = [
- Subscription(
- recipient=recipient,
- user_profile=shylock,
- is_user_active=shylock.is_active,
- color=STREAM_ASSIGNMENT_COLORS[0],
- ),
- ]
- Subscription.objects.bulk_create(subs)
+ Subscription.objects.create(
+ recipient=recipient,
+ user_profile=shylock,
+ is_user_active=shylock.is_active,
+ color=STREAM_ASSIGNMENT_COLORS[0],
+ )
+ RealmAuditLog.objects.create(
+ realm=realm,
+ modified_user=shylock,
+ modified_stream=stream,
+ event_last_message_id=0,
+ event_type=RealmAuditLog.SUBSCRIPTION_CREATED,
+ event_time=installation_time,
+ )
# Create an attachment in the database for set_storage_space_used_statistic.
IMAGE_FILE_PATH = static_path("images/test-images/checkbox.png")