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_realm: Remove the 'react on consent message' approach.

Prakhar Pratyush65f465562f4c
diff --git a/zerver/lib/export.py b/zerver/lib/export.py
index d298960b03b..a9068bf8c00 100644
--- a/zerver/lib/export.py
+++ b/zerver/lib/export.py
@@ -74,7 +74,7 @@ from zerver.models import (
)
from zerver.models.presence import PresenceSequence
from zerver.models.realm_audit_logs import AuditLogEventType
-from zerver.models.realms import get_realm
+from zerver.models.realms import EXPORT_FULL_WITH_CONSENT, EXPORT_PUBLIC, get_realm
from zerver.models.users import get_system_bot, get_user_profile_by_id
# Custom mypy types follow:
@@ -1234,15 +1234,15 @@ def fetch_usermessages(
message_ids: set[int],
user_profile_ids: set[int],
message_filename: Path,
- consent_message_id: int | None = None,
+ export_full_with_consent: bool,
) -> list[Record]:
# UserMessage export security rule: You can export UserMessages
# for the messages you exported for the users in your realm.
user_message_query = UserMessage.objects.filter(
user_profile__realm=realm, message_id__in=message_ids
)
- if consent_message_id is not None:
- consented_user_ids = get_consented_user_ids(consent_message_id)
+ if export_full_with_consent:
+ consented_user_ids = get_consented_user_ids(realm)
user_profile_ids = consented_user_ids & user_profile_ids
user_message_chunk = []
for user_message in user_message_query:
@@ -1257,7 +1257,7 @@ def fetch_usermessages(
def export_usermessages_batch(
- input_path: Path, output_path: Path, consent_message_id: int | None = None
+ input_path: Path, output_path: Path, export_full_with_consent: bool
) -> None:
"""As part of the system for doing parallel exports, this runs on one
batch of Message objects and adds the corresponding UserMessage
@@ -1275,7 +1275,7 @@ def export_usermessages_batch(
user_profile_ids = set(input_data["zerver_userprofile_ids"])
realm = Realm.objects.get(id=input_data["realm_id"])
zerver_usermessage_data = fetch_usermessages(
- realm, message_ids, user_profile_ids, output_path, consent_message_id
+ realm, message_ids, user_profile_ids, output_path, export_full_with_consent
)
output_data: TableData = dict(
@@ -1289,10 +1289,9 @@ def export_usermessages_batch(
def export_partial_message_files(
realm: Realm,
response: TableData,
+ export_type: int,
chunk_size: int = MESSAGE_BATCH_CHUNK_SIZE,
output_dir: Path | None = None,
- public_only: bool = False,
- consent_message_id: int | None = None,
) -> set[int]:
if output_dir is None:
output_dir = tempfile.mkdtemp(prefix="zulip-export")
@@ -1325,16 +1324,16 @@ def export_partial_message_files(
)
consented_user_ids: set[int] = set()
- if consent_message_id is not None:
- consented_user_ids = get_consented_user_ids(consent_message_id)
+ if export_type == EXPORT_FULL_WITH_CONSENT:
+ consented_user_ids = get_consented_user_ids(realm)
- if public_only:
+ if export_type == EXPORT_PUBLIC:
recipient_streams = Stream.objects.filter(realm=realm, invite_only=False)
recipient_ids = Recipient.objects.filter(
type=Recipient.STREAM, type_id__in=recipient_streams
).values_list("id", flat=True)
recipient_ids_for_us = get_ids(response["zerver_recipient"]) & set(recipient_ids)
- elif consent_message_id is not None:
+ elif export_type == EXPORT_FULL_WITH_CONSENT:
public_streams = Stream.objects.filter(realm=realm, invite_only=False)
public_stream_recipient_ids = Recipient.objects.filter(
type=Recipient.STREAM, type_id__in=public_streams
@@ -1357,7 +1356,7 @@ def export_partial_message_files(
# For a full export, we have implicit consent for all users in the export.
consented_user_ids = user_ids_for_us
- if public_only:
+ if export_type == EXPORT_PUBLIC:
messages_we_received = Message.objects.filter(
# Uses index: zerver_message_realm_sender_recipient
realm_id=realm.id,
@@ -1383,7 +1382,7 @@ def export_partial_message_files(
)
message_queries.append(messages_we_received)
- if consent_message_id is not None:
+ if export_type == EXPORT_FULL_WITH_CONSENT:
# Export with member consent requires some careful handling to make sure
# we only include messages that a consenting user can access.
has_usermessage_expression = Exists(
@@ -1961,19 +1960,17 @@ def do_write_stats_file_for_realm_export(output_dir: Path) -> None:
f.write("\n")
-def get_exportable_scheduled_message_ids(
- realm: Realm, public_only: bool = False, consent_message_id: int | None = None
-) -> set[int]:
+def get_exportable_scheduled_message_ids(realm: Realm, export_type: int) -> set[int]:
"""
Scheduled messages are private to the sender, so which ones we export depends on the
public/consent/full export mode.
"""
- if public_only:
+ if export_type == EXPORT_PUBLIC:
return set()
- if consent_message_id:
- sender_ids = get_consented_user_ids(consent_message_id)
+ if export_type == EXPORT_FULL_WITH_CONSENT:
+ sender_ids = get_consented_user_ids(realm)
return set(
ScheduledMessage.objects.filter(sender_id__in=sender_ids, realm=realm).values_list(
"id", flat=True
@@ -1987,9 +1984,8 @@ def do_export_realm(
realm: Realm,
output_dir: Path,
threads: int,
+ export_type: int,
exportable_user_ids: set[int] | None = None,
- public_only: bool = False,
- consent_message_id: int | None = None,
export_as_active: bool | None = None,
) -> str:
response: TableData = {}
@@ -2004,9 +2000,7 @@ def do_export_realm(
create_soft_link(source=output_dir, in_progress=True)
- exportable_scheduled_message_ids = get_exportable_scheduled_message_ids(
- realm, public_only, consent_message_id
- )
+ exportable_scheduled_message_ids = get_exportable_scheduled_message_ids(realm, export_type)
logging.info("Exporting data from get_realm_config()...")
export_from_config(
@@ -2032,9 +2026,8 @@ def do_export_realm(
message_ids = export_partial_message_files(
realm,
response,
+ export_type=export_type,
output_dir=output_dir,
- public_only=public_only,
- consent_message_id=consent_message_id,
)
logging.info("%d messages were exported", len(message_ids))
@@ -2067,7 +2060,9 @@ def do_export_realm(
# Start parallel jobs to export the UserMessage objects.
launch_user_message_subprocesses(
- threads=threads, output_dir=output_dir, consent_message_id=consent_message_id
+ threads=threads,
+ output_dir=output_dir,
+ export_full_with_consent=export_type == EXPORT_FULL_WITH_CONSENT,
)
logging.info("Finished exporting %s", realm.string_id)
@@ -2125,7 +2120,7 @@ def create_soft_link(source: Path, in_progress: bool = True) -> None:
def launch_user_message_subprocesses(
- threads: int, output_dir: Path, consent_message_id: int | None = None
+ threads: int, output_dir: Path, export_full_with_consent: bool
) -> None:
logging.info("Launching %d PARALLEL subprocesses to export UserMessage rows", threads)
pids = {}
@@ -2137,8 +2132,8 @@ def launch_user_message_subprocesses(
f"--path={output_dir}",
f"--thread={shard_id}",
]
- if consent_message_id is not None:
- arguments.append(f"--consent-message-id={consent_message_id}")
+ if export_full_with_consent:
+ arguments.append("--export-full-with-consent")
process = subprocess.Popen(arguments)
pids[process.pid] = shard_id
@@ -2434,14 +2429,11 @@ def get_analytics_config() -> Config:
return analytics_config
-def get_consented_user_ids(consent_message_id: int) -> set[int]:
+def get_consented_user_ids(realm: Realm) -> set[int]:
return set(
- Reaction.objects.filter(
- message_id=consent_message_id,
- reaction_type="unicode_emoji",
- # outbox = 1f4e4
- emoji_code="1f4e4",
- ).values_list("user_profile", flat=True)
+ UserProfile.objects.filter(
+ realm=realm, is_active=True, is_bot=False, allow_private_data_export=True
+ ).values_list("id", flat=True)
)
@@ -2450,17 +2442,15 @@ def export_realm_wrapper(
output_dir: str,
threads: int,
upload: bool,
- public_only: bool,
+ export_type: int,
percent_callback: Callable[[Any], None] | None = None,
- consent_message_id: int | None = None,
export_as_active: bool | None = None,
) -> str | None:
tarball_path = do_export_realm(
realm=realm,
output_dir=output_dir,
threads=threads,
- public_only=public_only,
- consent_message_id=consent_message_id,
+ export_type=export_type,
export_as_active=export_as_active,
)
shutil.rmtree(output_dir)
diff --git a/zerver/management/commands/export.py b/zerver/management/commands/export.py
index 97063a8cb98..d2c8c9df3c8 100644
--- a/zerver/management/commands/export.py
+++ b/zerver/management/commands/export.py
@@ -11,8 +11,13 @@ 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, RealmAuditLog, UserProfile
+from zerver.models import RealmAuditLog
from zerver.models.realm_audit_logs import AuditLogEventType
+from zerver.models.realms import (
+ EXPORT_FULL_WITH_CONSENT,
+ EXPORT_FULL_WITHOUT_CONSENT,
+ EXPORT_PUBLIC,
+)
class Command(ZulipBaseCommand):
@@ -99,9 +104,9 @@ class Command(ZulipBaseCommand):
),
)
parser.add_argument(
- "--consent-message-id",
- type=int,
- help="ID of the message advertising users to react with thumbs up",
+ "--export-full-with-consent",
+ action="store_true",
+ help="Whether to export private data of users who consented",
)
parser.add_argument(
"--upload",
@@ -117,7 +122,7 @@ class Command(ZulipBaseCommand):
output_dir = options["output_dir"]
public_only = options["public_only"]
- consent_message_id = options["consent_message_id"]
+ export_full_with_consent = options["export_full_with_consent"]
print(f"\033[94mExporting realm\033[0m: {realm.string_id}")
@@ -125,61 +130,12 @@ class Command(ZulipBaseCommand):
if num_threads < 1:
raise CommandError("You must have at least one thread.")
- if public_only and consent_message_id is not None:
- raise CommandError("Please pass either --public-only or --consent-message-id")
+ if public_only and export_full_with_consent:
+ raise CommandError("Please pass either --public-only or --export-full-with-consennt")
if options["deactivate_realm"] and realm.deactivated:
raise CommandError(f"The realm {realm.string_id} is already deactivated. Aborting...")
- if consent_message_id is not None:
- try:
- message = Message.objects.get(id=consent_message_id)
- except Message.DoesNotExist:
- raise CommandError("Message with given ID does not exist. Aborting...")
-
- if message.last_edit_time is not None:
- raise CommandError("Message was edited. Aborting...")
-
- # Since the message might have been sent by
- # Notification Bot, we can't trivially check the realm of
- # the message through message.sender.realm. So instead we
- # check the realm of the people who reacted to the message
- # (who must all be in the message's realm).
- reactions = Reaction.objects.filter(
- message=message,
- # outbox = 1f4e4
- emoji_code="1f4e4",
- reaction_type="unicode_emoji",
- )
- for reaction in reactions:
- if reaction.user_profile.realm != realm:
- raise CommandError(
- "Users from a different realm reacted to message. Aborting..."
- )
-
- print(f"\n\033[94mMessage content:\033[0m\n{message.content}\n")
-
- user_count = (
- UserProfile.objects.filter(
- realm_id=realm.id,
- is_active=True,
- is_bot=False,
- )
- .exclude(
- # We exclude guests, because they're not a priority for
- # looking at whether most users are being exported.
- role=UserProfile.ROLE_GUEST,
- )
- .count()
- )
- print(
- f"\033[94mNumber of users that reacted outbox:\033[0m {len(reactions)} / {user_count} total non-guest users\n"
- )
-
- proceed = input("Continue? [y/N] ")
- if proceed.lower() not in ("y", "yes"):
- raise CommandError("Aborting!")
-
if output_dir is None:
output_dir = tempfile.mkdtemp(prefix="zulip-export-")
else:
@@ -221,13 +177,18 @@ class Command(ZulipBaseCommand):
)
# Allows us to trigger exports separately from command line argument parsing
+ if public_only:
+ export_type = EXPORT_PUBLIC
+ elif export_full_with_consent:
+ export_type = EXPORT_FULL_WITH_CONSENT
+ else:
+ export_type = EXPORT_FULL_WITHOUT_CONSENT
export_realm_wrapper(
realm=realm,
output_dir=output_dir,
threads=num_threads,
upload=options["upload"],
- public_only=public_only,
+ export_type=export_type,
percent_callback=percent_callback,
- consent_message_id=consent_message_id,
export_as_active=True if options["deactivate_realm"] else None,
)
diff --git a/zerver/management/commands/export_usermessage_batch.py b/zerver/management/commands/export_usermessage_batch.py
index 1b9fd2daddb..33724e1d865 100644
--- a/zerver/management/commands/export_usermessage_batch.py
+++ b/zerver/management/commands/export_usermessage_batch.py
@@ -18,9 +18,9 @@ class Command(ZulipBaseCommand):
parser.add_argument("--path", help="Path to find messages.json archives")
parser.add_argument("--thread", help="Thread ID")
parser.add_argument(
- "--consent-message-id",
- type=int,
- help="ID of the message advertising users to react with thumbs up",
+ "--export-full-with-consent",
+ action="store_true",
+ help="Whether to export private data of users who consented",
)
@override
@@ -37,7 +37,9 @@ class Command(ZulipBaseCommand):
continue
logging.info("Thread %s processing %s", options["thread"], output_path)
try:
- export_usermessages_batch(locked_path, output_path, options["consent_message_id"])
+ export_usermessages_batch(
+ locked_path, output_path, options["export_full_with_consent"]
+ )
except BaseException:
# Put the item back in the free pool when we fail
os.rename(locked_path, partial_path)
diff --git a/zerver/models/realms.py b/zerver/models/realms.py
index cdf1f6a7cba..91950000ba6 100644
--- a/zerver/models/realms.py
+++ b/zerver/models/realms.py
@@ -1280,3 +1280,14 @@ def get_fake_email_domain(realm_host: str) -> str:
)
return settings.FAKE_EMAIL_DOMAIN
+
+
+# TODO: Move this into a new ReamExport model.
+EXPORT_PUBLIC = 1
+EXPORT_FULL_WITH_CONSENT = 2
+EXPORT_FULL_WITHOUT_CONSENT = 3
+EXPORT_TYPES = [
+ EXPORT_PUBLIC,
+ EXPORT_FULL_WITH_CONSENT,
+ EXPORT_FULL_WITHOUT_CONSENT,
+]
diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py
index 63fb9512a15..123ed2815e3 100644
--- a/zerver/tests/test_import_export.py
+++ b/zerver/tests/test_import_export.py
@@ -24,7 +24,7 @@ from zerver.actions.custom_profile_fields import (
)
from zerver.actions.muted_users import do_mute_user
from zerver.actions.presence import do_update_user_presence
-from zerver.actions.reactions import check_add_reaction, do_add_reaction
+from zerver.actions.reactions import check_add_reaction
from zerver.actions.realm_emoji import check_add_realm_emoji
from zerver.actions.realm_icon import do_change_icon_source
from zerver.actions.realm_logo import do_change_logo_source
@@ -34,6 +34,7 @@ from zerver.actions.realm_settings import (
)
from zerver.actions.scheduled_messages import check_schedule_message
from zerver.actions.user_activity import do_update_user_activity_interval
+from zerver.actions.user_settings import do_change_user_setting
from zerver.actions.user_status import do_update_user_status
from zerver.actions.user_topics import do_set_user_topic_visibility_policy
from zerver.actions.users import do_deactivate_user
@@ -93,7 +94,12 @@ from zerver.models.clients import get_client
from zerver.models.groups import SystemGroups
from zerver.models.presence import PresenceSequence
from zerver.models.realm_audit_logs import AuditLogEventType
-from zerver.models.realms import get_realm
+from zerver.models.realms import (
+ EXPORT_FULL_WITH_CONSENT,
+ EXPORT_FULL_WITHOUT_CONSENT,
+ EXPORT_PUBLIC,
+ get_realm,
+)
from zerver.models.recipients import get_direct_message_group_hash
from zerver.models.streams import get_active_streams, get_stream
from zerver.models.users import get_system_bot, get_user_by_delivery_email
@@ -336,9 +342,8 @@ class RealmImportExportTest(ExportFile):
def export_realm(
self,
realm: Realm,
+ export_type: int,
exportable_user_ids: set[int] | None = None,
- consent_message_id: int | None = None,
- public_only: bool = False,
) -> None:
output_dir = make_export_output_dir()
with patch("zerver.lib.export.create_soft_link"), self.assertLogs(level="INFO"):
@@ -346,9 +351,8 @@ class RealmImportExportTest(ExportFile):
realm=realm,
output_dir=output_dir,
threads=0,
+ export_type=export_type,
exportable_user_ids=exportable_user_ids,
- consent_message_id=consent_message_id,
- public_only=public_only,
)
# This is a unique field and thus the cycle of export->import
@@ -360,22 +364,21 @@ class RealmImportExportTest(ExportFile):
export_usermessages_batch(
input_path=os.path.join(output_dir, "messages-000001.json.partial"),
output_path=os.path.join(output_dir, "messages-000001.json"),
- consent_message_id=consent_message_id,
+ export_full_with_consent=export_type == EXPORT_FULL_WITH_CONSENT,
)
def export_realm_and_create_auditlog(
self,
original_realm: Realm,
+ export_type: int = EXPORT_FULL_WITHOUT_CONSENT,
exportable_user_ids: set[int] | None = None,
- consent_message_id: int | None = None,
- public_only: bool = False,
) -> None:
RealmAuditLog.objects.create(
realm=original_realm,
event_type=AuditLogEventType.REALM_EXPORTED,
event_time=timezone_now(),
)
- self.export_realm(original_realm, exportable_user_ids, consent_message_id, public_only)
+ self.export_realm(original_realm, export_type, exportable_user_ids)
def test_export_files_from_local(self) -> None:
user = self.example_user("hamlet")
@@ -410,7 +413,7 @@ class RealmImportExportTest(ExportFile):
is_message_realm_public=True,
)
- self.export_realm_and_create_auditlog(realm, public_only=True)
+ self.export_realm_and_create_auditlog(realm, export_type=EXPORT_PUBLIC)
# The attachment row shouldn't have been exported:
self.assertEqual(read_json("attachment.json")["zerver_attachment"], [])
@@ -650,25 +653,16 @@ class RealmImportExportTest(ExportFile):
self.example_user("iago"), self.example_user("hamlet")
)
- # Send message advertising export and make users react
- self.send_stream_message(
- self.example_user("othello"),
- "Verona",
- topic_name="Export",
- content="Thumbs up for export",
- )
- message = Message.objects.last()
- assert message is not None
+ # Iago and Hamlet consented to export their private data.
consented_user_ids = [self.example_user(user).id for user in ["iago", "hamlet"]]
- do_add_reaction(
- self.example_user("iago"), message, "outbox", "1f4e4", Reaction.UNICODE_EMOJI
+ do_change_user_setting(
+ self.example_user("iago"), "allow_private_data_export", True, acting_user=None
)
- do_add_reaction(
- self.example_user("hamlet"), message, "outbox", "1f4e4", Reaction.UNICODE_EMOJI
+ do_change_user_setting(
+ self.example_user("hamlet"), "allow_private_data_export", True, acting_user=None
)
- assert message is not None
- self.export_realm_and_create_auditlog(realm, consent_message_id=message.id)
+ self.export_realm_and_create_auditlog(realm, export_type=EXPORT_FULL_WITH_CONSENT)
data = read_json("realm.json")
@@ -1009,7 +1003,7 @@ class RealmImportExportTest(ExportFile):
for f in getters:
snapshots[f.__name__] = f(original_realm)
- self.export_realm(original_realm)
+ self.export_realm(original_realm, export_type=EXPORT_FULL_WITHOUT_CONSENT)
with self.settings(BILLING_ENABLED=False), self.assertLogs(level="INFO"):
do_import_realm(get_output_dir(), "test-zulip")
diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.py
index e63f30162af..39aaebf0205 100644
--- a/zerver/tests/test_management_commands.py
+++ b/zerver/tests/test_management_commands.py
@@ -11,17 +11,16 @@ from django.conf import settings
from django.core.management import call_command, find_commands
from django.core.management.base import CommandError
from django.test import override_settings
-from django.utils.timezone import now as timezone_now
from typing_extensions import override
from confirmation.models import RealmCreationKey, generate_realm_creation_url
from zerver.actions.create_user import do_create_user
-from zerver.actions.reactions import do_add_reaction
+from zerver.actions.user_settings import do_change_user_setting
from zerver.lib.management import ZulipBaseCommand, check_config
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import most_recent_message, stdout_suppressed
-from zerver.models import Message, Reaction, Realm, Recipient, UserProfile
-from zerver.models.realms import get_realm
+from zerver.models import Realm, Recipient, UserProfile
+from zerver.models.realms import EXPORT_FULL_WITH_CONSENT, get_realm
from zerver.models.streams import get_stream
from zerver.models.users import get_user_profile_by_email
@@ -515,90 +514,29 @@ class TestDowngradeSmallRealmsBehindOnPayments(ZulipTestCase):
class TestExport(ZulipTestCase):
COMMAND_NAME = "export"
- def test_command_with_consented_message_id(self) -> None:
+ def test_command_to_export_full_with_consent(self) -> None:
realm = get_realm("zulip")
- self.send_stream_message(
- self.example_user("othello"),
- "Verona",
- topic_name="Export",
- content="Outbox emoji for export",
+ do_change_user_setting(
+ self.example_user("iago"), "allow_private_data_export", True, acting_user=None
)
- message = Message.objects.last()
- assert message is not None
- do_add_reaction(
- self.example_user("iago"), message, "outbox", "1f4e4", Reaction.UNICODE_EMOJI
- )
- do_add_reaction(
- self.example_user("hamlet"), message, "outbox", "1f4e4", Reaction.UNICODE_EMOJI
+ do_change_user_setting(
+ self.example_user("iago"), "allow_private_data_export", True, acting_user=None
)
with (
patch("zerver.management.commands.export.export_realm_wrapper") as m,
patch("builtins.print") as mock_print,
- patch("builtins.input", return_value="y") as mock_input,
):
- call_command(self.COMMAND_NAME, "-r=zulip", f"--consent-message-id={message.id}")
+ call_command(self.COMMAND_NAME, "-r=zulip", "--export-full-with-consent")
m.assert_called_once_with(
realm=realm,
- public_only=False,
- consent_message_id=message.id,
+ export_type=EXPORT_FULL_WITH_CONSENT,
threads=mock.ANY,
output_dir=mock.ANY,
percent_callback=mock.ANY,
upload=False,
export_as_active=None,
)
- mock_input.assert_called_once_with("Continue? [y/N] ")
-
- self.assertEqual(
- mock_print.mock_calls,
- [
- call("\033[94mExporting realm\033[0m: zulip"),
- call("\n\033[94mMessage content:\033[0m\nOutbox emoji for export\n"),
- call(
- "\033[94mNumber of users that reacted outbox:\033[0m 2 / 9 total non-guest users\n"
- ),
- ],
- )
-
- with (
- self.assertRaisesRegex(CommandError, "Message with given ID does not"),
- patch("builtins.print") as mock_print,
- ):
- call_command(self.COMMAND_NAME, "-r=zulip", "--consent-message-id=123456")
- self.assertEqual(
- mock_print.mock_calls,
- [
- call("\033[94mExporting realm\033[0m: zulip"),
- ],
- )
-
- message.last_edit_time = timezone_now()
- message.save()
- with (
- self.assertRaisesRegex(CommandError, "Message was edited. Aborting..."),
- patch("builtins.print") as mock_print,
- ):
- call_command(self.COMMAND_NAME, "-r=zulip", f"--consent-message-id={message.id}")
- self.assertEqual(
- mock_print.mock_calls,
- [
- call("\033[94mExporting realm\033[0m: zulip"),
- ],
- )
-
- message.last_edit_time = None
- message.save()
- do_add_reaction(
- self.mit_user("sipbtest"), message, "outbox", "1f4e4", Reaction.UNICODE_EMOJI
- )
- with (
- self.assertRaisesRegex(
- CommandError, "Users from a different realm reacted to message. Aborting..."
- ),
- patch("builtins.print") as mock_print,
- ):
- call_command(self.COMMAND_NAME, "-r=zulip", f"--consent-message-id={message.id}")
self.assertEqual(
mock_print.mock_calls,
diff --git a/zerver/tests/test_realm_export.py b/zerver/tests/test_realm_export.py
index 2e7c6e2cd35..4729ed70c03 100644
--- a/zerver/tests/test_realm_export.py
+++ b/zerver/tests/test_realm_export.py
@@ -20,6 +20,7 @@ from zerver.lib.test_helpers import (
)
from zerver.models import Realm, RealmAuditLog, UserProfile
from zerver.models.realm_audit_logs import AuditLogEventType
+from zerver.models.realms import EXPORT_PUBLIC
from zerver.views.realm_export import export_realm
@@ -60,7 +61,7 @@ class RealmExportTest(ZulipTestCase):
self.assertFalse(os.path.exists(tarball_path))
args = mock_export.call_args_list[0][1]
self.assertEqual(args["realm"], admin.realm)
- self.assertEqual(args["public_only"], True)
+ self.assertEqual(args["export_type"], EXPORT_PUBLIC)
self.assertTrue(os.path.basename(args["output_dir"]).startswith("zulip-export-"))
self.assertEqual(args["threads"], 6)
@@ -123,13 +124,12 @@ class RealmExportTest(ZulipTestCase):
realm: Realm,
output_dir: str,
threads: int,
+ export_type: int,
exportable_user_ids: set[int] | None = None,
- public_only: bool = False,
- consent_message_id: int | None = None,
export_as_active: bool | None = None,
) -> str:
self.assertEqual(realm, admin.realm)
- self.assertEqual(public_only, True)
+ self.assertEqual(export_type, EXPORT_PUBLIC)
self.assertTrue(os.path.basename(output_dir).startswith("zulip-export-"))
self.assertEqual(threads, 6)
diff --git a/zerver/worker/deferred_work.py b/zerver/worker/deferred_work.py
index 577f4935a46..9de5458b763 100644
--- a/zerver/worker/deferred_work.py
+++ b/zerver/worker/deferred_work.py
@@ -26,6 +26,7 @@ from zerver.lib.remote_server import (
from zerver.lib.soft_deactivation import reactivate_user_if_soft_deactivated
from zerver.lib.upload import handle_reupload_emojis_event
from zerver.models import Message, Realm, RealmAuditLog, Stream, UserMessage
+from zerver.models.realms import EXPORT_PUBLIC
from zerver.models.users import get_system_bot, get_user_profile_by_id
from zerver.worker.base import QueueProcessingWorker, assign_queue
@@ -158,7 +159,7 @@ class DeferredWorker(QueueProcessingWorker):
output_dir=output_dir,
threads=1 if self.threaded else 6,
upload=True,
- public_only=True,
+ export_type=EXPORT_PUBLIC,
)
except Exception:
extra_data["failed_timestamp"] = timezone_now().timestamp()