Skip to content

Commit

Permalink
Add chatops display condition and review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ravishankar15 authored and matiasb committed Dec 10, 2024
1 parent 13beb29 commit 81a7f46
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion engine/apps/mattermost/models/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions engine/apps/mattermost/tests/models/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions engine/apps/mattermost/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const ExpandedIntegrationRouteDisplay: React.FC<ExpandedIntegrationRouteD
escalationChainStore,
alertReceiveChannelStore,
grafanaTeamStore,
mattermostChannelStore,
} = store;

const channelFilter = alertReceiveChannelStore.channelFilters[channelFilterId];
Expand All @@ -125,7 +126,7 @@ export const ExpandedIntegrationRouteDisplay: React.FC<ExpandedIntegrationRouteD
useEffect(() => {
setIsLoading(true);
(async () => {
await Promise.all([escalationChainStore.updateItems(), telegramChannelStore.updateTelegramChannels()]);
await Promise.all([escalationChainStore.updateItems(), telegramChannelStore.updateTelegramChannels(), mattermostChannelStore.updateItems()]);
setIsLoading(false);
})();
}, []);
Expand Down
4 changes: 3 additions & 1 deletion grafana-plugin/src/pages/integration/Integration.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }> {
Expand Down

0 comments on commit 81a7f46

Please sign in to comment.