diff --git a/engine/apps/mattermost/models/channel.py b/engine/apps/mattermost/models/channel.py index 2a2c11c662..b1d86e2391 100644 --- a/engine/apps/mattermost/models/channel.py +++ b/engine/apps/mattermost/models/channel.py @@ -65,7 +65,10 @@ def get_channel_for_alert_group(cls, alert_group: AlertGroup) -> typing.Optional channel_id = alert_group.channel_filter.notification_backends[MattermostBackend.backend_id].get("channel") enabled = alert_group.channel_filter.notification_backends[MattermostBackend.backend_id].get("enabled") - if not enabled or not channel_id: + if not enabled: + return None + + if not channel_id: return default_channel channel = cls.objects.filter( diff --git a/engine/apps/mattermost/tests/models/test_channel.py b/engine/apps/mattermost/tests/models/test_channel.py index 68de2c488e..65151d5bdf 100644 --- a/engine/apps/mattermost/tests/models/test_channel.py +++ b/engine/apps/mattermost/tests/models/test_channel.py @@ -39,7 +39,6 @@ def test_get_mattermost_channel_disabled_for_route( ): organization = make_organization() alert_receive_channel = make_alert_receive_channel(organization) - default_channel = make_mattermost_channel(organization=organization, is_default_channel=True) channel = make_mattermost_channel(organization=organization) channel_filter = make_channel_filter( alert_receive_channel, @@ -50,7 +49,7 @@ def test_get_mattermost_channel_disabled_for_route( make_alert(alert_group=alert_group, raw_request_data=alert_receive_channel.config.example_payload) ch = MattermostChannel.get_channel_for_alert_group(alert_group) - assert ch.public_primary_key == default_channel.public_primary_key + assert ch is None @pytest.mark.django_db diff --git a/engine/apps/mattermost/tests/test_backend.py b/engine/apps/mattermost/tests/test_backend.py index ac65526051..67db285f8b 100644 --- a/engine/apps/mattermost/tests/test_backend.py +++ b/engine/apps/mattermost/tests/test_backend.py @@ -65,8 +65,11 @@ def test_validate_channel_filter_data_update_only_channel( @pytest.mark.parametrize( "input_data,expected_data", [ + ({}, {}), ({"enabled": True}, {"enabled": True}), ({"enabled": False}, {"enabled": False}), + ({"enabled": 1}, {"enabled": True}), + ({"enabled": 0}, {"enabled": False}), ({"channel": None, "enabled": True}, {"channel": None, "enabled": True}), ({"channel": None}, {"channel": None}), ], diff --git a/grafana-plugin/src/containers/IntegrationContainers/ExpandedIntegrationRouteDisplay/ExpandedIntegrationRouteDisplay.tsx b/grafana-plugin/src/containers/IntegrationContainers/ExpandedIntegrationRouteDisplay/ExpandedIntegrationRouteDisplay.tsx index 30455ffaf5..a970c3de67 100644 --- a/grafana-plugin/src/containers/IntegrationContainers/ExpandedIntegrationRouteDisplay/ExpandedIntegrationRouteDisplay.tsx +++ b/grafana-plugin/src/containers/IntegrationContainers/ExpandedIntegrationRouteDisplay/ExpandedIntegrationRouteDisplay.tsx @@ -100,6 +100,7 @@ export const ExpandedIntegrationRouteDisplay: React.FC { setIsLoading(true); (async () => { - await Promise.all([escalationChainStore.updateItems(), telegramChannelStore.updateTelegramChannels()]); + await Promise.all([escalationChainStore.updateItems(), telegramChannelStore.updateTelegramChannels(), mattermostChannelStore.updateItems()]); setIsLoading(false); })(); }, []); diff --git a/grafana-plugin/src/pages/integration/Integration.helper.ts b/grafana-plugin/src/pages/integration/Integration.helper.ts index 0812cc8ff5..c22f821e15 100644 --- a/grafana-plugin/src/pages/integration/Integration.helper.ts +++ b/grafana-plugin/src/pages/integration/Integration.helper.ts @@ -68,8 +68,10 @@ export const IntegrationHelper = { const hasTelegram = store.hasFeature(AppFeature.Telegram) && store.telegramChannelStore.currentTeamToTelegramChannel?.length > 0; const isMSTeamsInstalled = Boolean(store.msteamsChannelStore.currentTeamToMSTeamsChannel?.length > 0); + const connectedChannels = store.mattermostChannelStore.getSearchResult(); + const isMattermostInstalled = store.hasFeature(AppFeature.Mattermost) && Boolean(connectedChannels && connectedChannels.length) - return hasSlack || hasTelegram || isMSTeamsInstalled; + return hasSlack || hasTelegram || isMSTeamsInstalled || isMattermostInstalled; }, getChatOpsChannels(channelFilter: ChannelFilter, store: RootStore): Array<{ name: string; icon: IconName }> {