Skip to content

Commit

Permalink
mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hagen-danswer committed Sep 30, 2024
1 parent 4815820 commit fa740ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions backend/ee/danswer/external_permissions/slack/doc_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _fetch_channel_permissions(
get_private=False,
)
public_channel_ids = [
channel.get("id") for channel in public_channels.get("channels", [])
channel["id"] for channel in public_channels if "id" in channel
]
for channel_id in public_channel_ids:
channel_permissions[channel_id] = workspace_permissions
Expand All @@ -105,26 +105,29 @@ def _fetch_channel_permissions(
get_private=True,
)
private_channel_ids = [
channel.get("id") for channel in private_channels.get("channels", [])
channel["id"] for channel in private_channels if "id" in channel
]

for channel_id in private_channel_ids:
member_emails = set()
# Collect all member ids for the channel pagination calls
member_ids = []
for result in make_paginated_slack_api_call_w_retries(
slack_client.conversations_members,
channel=channel_id,
):
member_ids.extend(result.get("members", []))

# Collect all member emails for the channel
member_emails = set()
for member_id in member_ids:
member_email = user_id_to_email_map.get(member_id)

if not member_email:
# If the user is an external user, they wont get returned from the
# conversations_members call so we need to make a separate call to users_info
# and add them to the user_id_to_email_map
member_info = slack_client.users_info(user=member_id)
member_email = member_info.get("user", {}).get("email")
member_email = member_info["user"]["profile"].get("email")
if not member_email:
# If no email is found, we skip the user
continue
Expand Down
7 changes: 4 additions & 3 deletions backend/ee/danswer/external_permissions/slack/group_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ def _get_slack_group_members_email(
# If the user is an external user, they wont get returned from the
# conversations_members call so we need to make a separate call to users_info
member_info = slack_client.users_info(user=member_id)
member_email = (
member_info.get("user", {}).get("profile", {}).get("email")
)
member_email = member_info["user"]["profile"].get("email")
if not member_email:
# If no email is found, we skip the user
continue
user_id_to_email_map[member_id] = member_email
batch_add_non_web_user_if_not_exists__no_commit(
db_session, [member_email]
Expand Down

0 comments on commit fa740ec

Please sign in to comment.