mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
import: Fix the import of authentication_methods BitField.
The ordering of bits that fix_realm_authentication_bitfield was making was incorrect, it needs to be reversed.
This commit is contained in:
committed by
Tim Abbott
parent
3df8dd4b38
commit
d5b450c1e0
@@ -588,9 +588,14 @@ def fix_bitfield_keys(data: TableData, table: TableName, field_name: Field) -> N
|
||||
|
||||
|
||||
def fix_realm_authentication_bitfield(data: TableData, table: TableName, field_name: Field) -> None:
|
||||
"""Used to fixup the authentication_methods bitfield to be a string"""
|
||||
"""Used to fixup the authentication_methods bitfield to be an integer."""
|
||||
for item in data[table]:
|
||||
values_as_bitstring = "".join("1" if field[1] else "0" for field in item[field_name])
|
||||
# The ordering of bits here is important for the imported value
|
||||
# to end up as expected.
|
||||
charlist = ["1" if field[1] else "0" for field in item[field_name]]
|
||||
charlist.reverse()
|
||||
|
||||
values_as_bitstring = "".join(charlist)
|
||||
values_as_int = int(values_as_bitstring, 2)
|
||||
item[field_name] = values_as_int
|
||||
|
||||
|
||||
@@ -24,7 +24,10 @@ from zerver.actions.reactions import check_add_reaction, do_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
|
||||
from zerver.actions.realm_settings import do_change_realm_plan_type
|
||||
from zerver.actions.realm_settings import (
|
||||
do_change_realm_plan_type,
|
||||
do_set_realm_authentication_methods,
|
||||
)
|
||||
from zerver.actions.user_activity import do_update_user_activity, do_update_user_activity_interval
|
||||
from zerver.actions.user_topics import do_mute_topic
|
||||
from zerver.actions.users import do_deactivate_user
|
||||
@@ -688,6 +691,18 @@ class RealmImportExportTest(ExportFile):
|
||||
|
||||
# Deactivate a user to ensure such a case is covered.
|
||||
do_deactivate_user(self.example_user("aaron"), acting_user=None)
|
||||
|
||||
# Change some authentication_methods so that some are enabled and some disabled
|
||||
# for this to be properly tested, as opposed to some special case
|
||||
# with e.g. everything enabled.
|
||||
authentication_methods = original_realm.authentication_methods_dict()
|
||||
authentication_methods["Email"] = False
|
||||
authentication_methods["Dev"] = True
|
||||
|
||||
do_set_realm_authentication_methods(
|
||||
original_realm, authentication_methods, acting_user=None
|
||||
)
|
||||
|
||||
# data to test import of huddles
|
||||
huddle = [
|
||||
self.example_user("hamlet"),
|
||||
@@ -919,6 +934,11 @@ class RealmImportExportTest(ExportFile):
|
||||
for imported_realm_emoji in all_imported_realm_emoji:
|
||||
self.assertNotEqual(imported_realm_emoji.author, None)
|
||||
|
||||
self.assertEqual(
|
||||
original_realm.authentication_methods_dict(),
|
||||
imported_realm.authentication_methods_dict(),
|
||||
)
|
||||
|
||||
def get_realm_getters(self) -> List[Callable[[Realm], object]]:
|
||||
names = set()
|
||||
getters: List[Callable[[Realm], object]] = []
|
||||
|
||||
Reference in New Issue
Block a user