mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
slack_import: Import Slackbot as a bot instead of a user.
Slackbot should be correctly marked as a bot rather than a regular user - otherwise, it confusingly appears on the Users list and in the realm creation from Slack import flow, in the dropdown for choosing the organization owner account. Closes #34649
This commit is contained in:
committed by
Tim Abbott
parent
75da563776
commit
0d17f34ff5
@@ -333,6 +333,15 @@ def users_to_zerver_userprofile(
|
||||
zerver_customprofilefield_values,
|
||||
)
|
||||
|
||||
if is_slackbot(user):
|
||||
is_bot = True
|
||||
else:
|
||||
is_bot = user.get("is_bot", False)
|
||||
if is_bot:
|
||||
bot_type = 1
|
||||
else:
|
||||
bot_type = None
|
||||
|
||||
userprofile = UserProfile(
|
||||
full_name=get_user_full_name(user),
|
||||
is_active=not user.get("deleted", False) and not user["is_mirror_dummy"],
|
||||
@@ -341,9 +350,9 @@ def users_to_zerver_userprofile(
|
||||
email=email,
|
||||
delivery_email=email,
|
||||
avatar_source=avatar_source,
|
||||
is_bot=user.get("is_bot", False),
|
||||
is_bot=is_bot,
|
||||
role=role,
|
||||
bot_type=1 if user.get("is_bot", False) else None,
|
||||
bot_type=bot_type,
|
||||
date_joined=timestamp,
|
||||
timezone=timezone,
|
||||
last_login=timestamp,
|
||||
@@ -452,6 +461,10 @@ def process_customprofilefields(
|
||||
break
|
||||
|
||||
|
||||
def is_slackbot(user: ZerverFieldsT) -> bool:
|
||||
return get_user_full_name(user).lower() == "slackbot"
|
||||
|
||||
|
||||
def get_user_email(user: ZerverFieldsT, domain_name: str) -> str:
|
||||
if "email" in user["profile"]:
|
||||
return user["profile"]["email"]
|
||||
@@ -459,7 +472,7 @@ def get_user_email(user: ZerverFieldsT, domain_name: str) -> str:
|
||||
return Address(username=user["name"], domain=f"{user['team_domain']}.slack.com").addr_spec
|
||||
if "bot_id" in user["profile"]:
|
||||
return SlackBotEmail.get_email(user["profile"], domain_name)
|
||||
if get_user_full_name(user).lower() == "slackbot":
|
||||
if is_slackbot(user):
|
||||
return Address(username="imported-slackbot-bot", domain=domain_name).addr_spec
|
||||
raise AssertionError(f"Could not find email address for Slack user {user}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user