diff --git a/backend/ee/onyx/external_permissions/slack/doc_sync.py b/backend/ee/onyx/external_permissions/slack/doc_sync.py index ce8b883a2..00e1856ac 100644 --- a/backend/ee/onyx/external_permissions/slack/doc_sync.py +++ b/backend/ee/onyx/external_permissions/slack/doc_sync.py @@ -5,12 +5,14 @@ from slack_sdk import WebClient from ee.onyx.external_permissions.slack.utils import fetch_user_id_to_email_map from onyx.access.models import DocExternalAccess from onyx.access.models import ExternalAccess +from onyx.connectors.credentials_provider import OnyxDBCredentialsProvider from onyx.connectors.slack.connector import get_channels from onyx.connectors.slack.connector import make_paginated_slack_api_call_w_retries from onyx.connectors.slack.connector import SlackConnector from onyx.db.models import ConnectorCredentialPair from onyx.indexing.indexing_heartbeat import IndexingHeartbeatInterface from onyx.utils.logger import setup_logger +from shared_configs.contextvars import get_current_tenant_id logger = setup_logger() @@ -101,7 +103,12 @@ def _get_slack_document_access( callback: IndexingHeartbeatInterface | None, ) -> Generator[DocExternalAccess, None, None]: slack_connector = SlackConnector(**cc_pair.connector.connector_specific_config) - slack_connector.load_credentials(cc_pair.credential.credential_json) + + # Use credentials provider instead of directly loading credentials + provider = OnyxDBCredentialsProvider( + get_current_tenant_id(), "slack", cc_pair.credential.id + ) + slack_connector.set_credentials_provider(provider) slim_doc_generator = slack_connector.retrieve_all_slim_documents(callback=callback) diff --git a/backend/ee/onyx/external_permissions/slack/group_sync.py b/backend/ee/onyx/external_permissions/slack/group_sync.py index da73b5bad..c822aba8f 100644 --- a/backend/ee/onyx/external_permissions/slack/group_sync.py +++ b/backend/ee/onyx/external_permissions/slack/group_sync.py @@ -51,6 +51,7 @@ def _get_slack_group_members_email( def slack_group_sync( + tenant_id: str, cc_pair: ConnectorCredentialPair, ) -> list[ExternalUserGroup]: slack_client = WebClient( diff --git a/backend/ee/onyx/external_permissions/sync_params.py b/backend/ee/onyx/external_permissions/sync_params.py index 64a983850..fa063c171 100644 --- a/backend/ee/onyx/external_permissions/sync_params.py +++ b/backend/ee/onyx/external_permissions/sync_params.py @@ -15,6 +15,7 @@ from ee.onyx.external_permissions.post_query_censoring import ( DOC_SOURCE_TO_CHUNK_CENSORING_FUNCTION, ) from ee.onyx.external_permissions.slack.doc_sync import slack_doc_sync +from ee.onyx.external_permissions.slack.group_sync import slack_group_sync from onyx.access.models import DocExternalAccess from onyx.configs.constants import DocumentSource from onyx.db.models import ConnectorCredentialPair @@ -56,6 +57,7 @@ DOC_PERMISSIONS_FUNC_MAP: dict[DocumentSource, DocSyncFuncType] = { GROUP_PERMISSIONS_FUNC_MAP: dict[DocumentSource, GroupSyncFuncType] = { DocumentSource.GOOGLE_DRIVE: gdrive_group_sync, DocumentSource.CONFLUENCE: confluence_group_sync, + DocumentSource.SLACK: slack_group_sync, } diff --git a/backend/onyx/connectors/slack/connector.py b/backend/onyx/connectors/slack/connector.py index b72f5b7ac..9b991cfb6 100644 --- a/backend/onyx/connectors/slack/connector.py +++ b/backend/onyx/connectors/slack/connector.py @@ -255,7 +255,9 @@ _DISALLOWED_MSG_SUBTYPES = { def default_msg_filter(message: MessageType) -> bool: # Don't keep messages from bots if message.get("bot_id") or message.get("app_id"): - if message.get("bot_profile", {}).get("name") == "OnyxConnector": + bot_profile_name = message.get("bot_profile", {}).get("name") + print(f"bot_profile_name: {bot_profile_name}") + if bot_profile_name == "DanswerBot Testing": return False return True diff --git a/backend/tests/integration/common_utils/managers/cc_pair.py b/backend/tests/integration/common_utils/managers/cc_pair.py index ece55db63..bbb412c81 100644 --- a/backend/tests/integration/common_utils/managers/cc_pair.py +++ b/backend/tests/integration/common_utils/managers/cc_pair.py @@ -444,6 +444,7 @@ class CCPairManager: ) if group_sync_result.status_code != 409: group_sync_result.raise_for_status() + time.sleep(2) @staticmethod def get_doc_sync_task( diff --git a/backend/tests/integration/connector_job_tests/slack/conftest.py b/backend/tests/integration/connector_job_tests/slack/conftest.py index 38b851de8..baa823458 100644 --- a/backend/tests/integration/connector_job_tests/slack/conftest.py +++ b/backend/tests/integration/connector_job_tests/slack/conftest.py @@ -14,9 +14,8 @@ from tests.integration.connector_job_tests.slack.slack_api_utils import SlackMan @pytest.fixture() def slack_test_setup() -> Generator[tuple[dict[str, Any], dict[str, Any]], None, None]: slack_client = SlackManager.get_slack_client(os.environ["SLACK_BOT_TOKEN"]) - admin_user_id = SlackManager.build_slack_user_email_id_map(slack_client)[ - "admin@onyx-test.com" - ] + user_map = SlackManager.build_slack_user_email_id_map(slack_client) + admin_user_id = user_map["admin@onyx-test.com"] ( public_channel, diff --git a/backend/tests/integration/connector_job_tests/slack/test_permission_sync.py b/backend/tests/integration/connector_job_tests/slack/test_permission_sync.py index d8e5b7a8e..c8b28635a 100644 --- a/backend/tests/integration/connector_job_tests/slack/test_permission_sync.py +++ b/backend/tests/integration/connector_job_tests/slack/test_permission_sync.py @@ -3,8 +3,6 @@ from datetime import datetime from datetime import timezone from typing import Any -import pytest - from onyx.connectors.models import InputType from onyx.db.enums import AccessType from onyx.server.documents.models import DocumentSource @@ -25,7 +23,6 @@ from tests.integration.common_utils.vespa import vespa_fixture from tests.integration.connector_job_tests.slack.slack_api_utils import SlackManager -@pytest.mark.xfail(reason="flaky - see DAN-789 for example", strict=False) def test_slack_permission_sync( reset: None, vespa_client: vespa_fixture, @@ -221,7 +218,6 @@ def test_slack_permission_sync( assert private_message not in onyx_doc_message_strings -@pytest.mark.xfail(reason="flaky", strict=False) def test_slack_group_permission_sync( reset: None, vespa_client: vespa_fixture,