export: Make --deactivate-realm exports be imported as active.

This commit is contained in:
Alex Vandiver 2023-04-03 14:06:10 +00:00 committed by Tim Abbott
parent 4b0b8abc6c
commit 113a8c4782
3 changed files with 13 additions and 4 deletions

View File

@ -1833,6 +1833,7 @@ def do_export_realm(
exportable_user_ids: Optional[Set[int]] = None,
public_only: bool = False,
consent_message_id: Optional[int] = None,
export_as_active: Optional[bool] = None,
) -> str:
response: TableData = {}
@ -1877,6 +1878,10 @@ def do_export_realm(
fetch_reaction_data(response=zerver_reaction, message_ids=message_ids)
response.update(zerver_reaction)
# Override the "deactivated" flag on the realm
if export_as_active is not None:
response["zerver_realm"][0]["deactivated"] = not export_as_active
# Write realm data
export_file = os.path.join(output_dir, "realm.json")
write_table_data(output_file=export_file, data=response)
@ -2267,6 +2272,7 @@ def export_realm_wrapper(
public_only: bool,
percent_callback: Optional[Callable[[Any], None]] = None,
consent_message_id: Optional[int] = None,
export_as_active: Optional[bool] = None,
) -> Optional[str]:
tarball_path = do_export_realm(
realm=realm,
@ -2274,6 +2280,7 @@ def export_realm_wrapper(
threads=threads,
public_only=public_only,
consent_message_id=consent_message_id,
export_as_active=export_as_active,
)
shutil.rmtree(output_dir)
print(f"Tarball written to {tarball_path}")

View File

@ -60,9 +60,6 @@ class Command(ZulipBaseCommand):
* Use `./manage.py import` to import the realm
* Use `./manage.py reactivate_realm` to reactivate the realm, so
users can log in again.
* Inform the users about the things broken above.
We recommend testing by exporting without `--deactivate` first, to
@ -92,7 +89,10 @@ class Command(ZulipBaseCommand):
parser.add_argument(
"--deactivate-realm",
action="store_true",
help="Deactivate the realm immediately before exporting",
help=(
"Deactivate the realm immediately before exporting; the exported data "
"will show the realm as active"
),
)
parser.add_argument(
"--consent-message-id",
@ -212,4 +212,5 @@ class Command(ZulipBaseCommand):
public_only=public_only,
percent_callback=percent_callback,
consent_message_id=consent_message_id,
export_as_active=True if options["deactivate_realm"] else None,
)

View File

@ -541,6 +541,7 @@ class TestExport(ZulipTestCase):
output_dir=mock.ANY,
percent_callback=mock.ANY,
upload=False,
export_as_active=None,
)
mock_input.assert_called_once_with("Continue? [y/N] ")