actions: Implement do_delete_user.

To have a reasonable way of creating the dummy user without duplicating
code, we need change create_user to have the optional force_id argument.
This commit is contained in:
Mateusz Mandera
2020-05-02 18:42:30 +02:00
committed by Alex Vandiver
parent d9b14b5b74
commit 47228f3a95
3 changed files with 101 additions and 4 deletions

View File

@@ -72,10 +72,15 @@ def create_user_profile(realm: Realm, email: str, password: Optional[str],
is_mirror_dummy: bool, tos_version: Optional[str],
timezone: Optional[str],
tutorial_status: str = UserProfile.TUTORIAL_WAITING,
enter_sends: bool = False) -> UserProfile:
enter_sends: bool = False,
force_id: Optional[int] = None) -> UserProfile:
now = timezone_now()
email = UserManager.normalize_email(email)
extra_kwargs = {}
if force_id is not None:
extra_kwargs['id'] = force_id
user_profile = UserProfile(is_staff=False, is_active=active,
full_name=full_name,
last_login=now, date_joined=now, realm=realm,
@@ -87,7 +92,8 @@ def create_user_profile(realm: Realm, email: str, password: Optional[str],
onboarding_steps=orjson.dumps([]).decode(),
default_language=realm.default_language,
twenty_four_hour_time=realm.default_twenty_four_hour_time,
delivery_email=email)
delivery_email=email,
**extra_kwargs)
if bot_type or not active:
password = None
if user_profile.email_address_is_realm_public():
@@ -112,7 +118,8 @@ def create_user(email: str,
default_sending_stream: Optional[Stream] = None,
default_events_register_stream: Optional[Stream] = None,
default_all_public_streams: Optional[bool] = None,
source_profile: Optional[UserProfile] = None) -> UserProfile:
source_profile: Optional[UserProfile] = None,
force_id: Optional[int] = None) -> UserProfile:
user_profile = create_user_profile(
realm,
email,
@@ -123,7 +130,8 @@ def create_user(email: str,
bot_owner,
is_mirror_dummy,
tos_version,
timezone
timezone,
force_id=force_id
)
user_profile.avatar_source = avatar_source
user_profile.timezone = timezone