Skip to content

Commit 8def2b7

Browse files
authored
Merge pull request #5336 from grafana/dev
v1.13.7
2 parents 56891f7 + 710fb8b commit 8def2b7

File tree

10 files changed

+63
-64
lines changed

10 files changed

+63
-64
lines changed

.github/workflows/expensive-e2e-tests.yml

-58
This file was deleted.

engine/apps/api/tests/test_alert_receive_channel.py

+6
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,12 @@ def test_alert_receive_channel_test_connection(
20662066
data = {
20672067
"integration": integration_config.slug,
20682068
"team": None,
2069+
"create_default_webhooks": True,
2070+
"alert_group_labels": {
2071+
"inheritable": {},
2072+
"custom": [],
2073+
"template": None,
2074+
},
20692075
}
20702076

20712077
# no test connection setup

engine/apps/api/views/alert_receive_channel.py

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
AlertReceiveChannelSerializer,
2525
AlertReceiveChannelUpdateSerializer,
2626
FilterAlertReceiveChannelSerializer,
27+
IntegrationAlertGroupLabelsSerializer,
2728
)
2829
from apps.api.serializers.alert_receive_channel_connection import (
2930
AlertReceiveChannelConnectedChannelSerializer,
@@ -309,7 +310,10 @@ def _test_connection(self, request, pk=None):
309310
# check we have all the required information
310311
serializer.is_valid(raise_exception=True)
311312
if instance is None:
313+
# pop extra fields so they are not passed to AlertReceiveChannel(**serializer.validated_data)
312314
serializer.validated_data.pop("create_default_webhooks", None)
315+
IntegrationAlertGroupLabelsSerializer.pop_alert_group_labels(serializer.validated_data)
316+
313317
# create in-memory instance to test with the (possible) unsaved data
314318
instance = AlertReceiveChannel(**serializer.validated_data)
315319
else:

engine/apps/email/inbound.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ def message(self) -> AnymailInboundMessage | None:
144144

145145
messages = [event.message for event in events if isinstance(event, AnymailInboundEvent)]
146146
if messages:
147-
logger.info(f"Received inbound email message from ESP: {esp}")
148-
return messages[0]
147+
message: AnymailInboundMessage = messages[0]
148+
logger.info(f"Received inbound email message from ESP: {esp}, is HTML: {message.html is not None}")
149+
return message
149150

150151
logger.error("Failed to parse inbound email message")
151152
return None

engine/apps/public_api/tests/test_escalation_chain.py

+41
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import httpretty
12
import pytest
23
from django.urls import reverse
34
from rest_framework import status
45
from rest_framework.test import APIClient
56

7+
from apps.api import permissions
8+
from apps.auth_token.tests.helpers import setup_service_account_api_mocks
9+
610

711
@pytest.mark.django_db
812
def test_get_escalation_chains(make_organization_and_user_with_token):
@@ -54,6 +58,43 @@ def test_create_escalation_chain(make_organization_and_user_with_token):
5458
assert response.data == expected_data
5559

5660

61+
@pytest.mark.django_db
62+
@httpretty.activate(verbose=True, allow_net_connect=False)
63+
def test_create_escalation_chain_via_service_account(
64+
make_organization,
65+
make_service_account_for_organization,
66+
make_token_for_service_account,
67+
make_team,
68+
):
69+
organization = make_organization(grafana_url="http://grafana.test")
70+
team = make_team(organization=organization)
71+
service_account = make_service_account_for_organization(organization)
72+
token_string = "glsa_token"
73+
make_token_for_service_account(service_account, token_string)
74+
75+
perms = {
76+
permissions.RBACPermission.Permissions.ESCALATION_CHAINS_WRITE.value: ["*"],
77+
}
78+
setup_service_account_api_mocks(organization.grafana_url, perms)
79+
80+
client = APIClient()
81+
url = reverse("api-public:escalation_chains-list")
82+
data = {"name": "test", "team_id": team.public_primary_key}
83+
response = client.post(
84+
url,
85+
data=data,
86+
format="json",
87+
HTTP_AUTHORIZATION=f"{token_string}",
88+
HTTP_X_GRAFANA_URL=organization.grafana_url,
89+
)
90+
if not organization.is_rbac_permissions_enabled:
91+
assert response.status_code == status.HTTP_403_FORBIDDEN
92+
else:
93+
assert response.status_code == status.HTTP_201_CREATED
94+
escalation_chain = organization.escalation_chains.get(name="test")
95+
assert escalation_chain.team == team
96+
97+
5798
@pytest.mark.django_db
5899
def test_change_name(make_organization_and_user_with_token):
59100
organization, user, token = make_organization_and_user_with_token()

engine/apps/user_management/models/service_account.py

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def pk(self):
2929
def current_team(self):
3030
return None
3131

32+
@property
33+
def available_teams(self):
34+
return self.organization.teams
35+
3236
@property
3337
def organization_id(self):
3438
return self.organization.id

engine/requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ charset-normalizer==3.3.2
1818
# requests
1919
distlib==0.3.8
2020
# via virtualenv
21-
django==4.2.16
21+
django==4.2.17
2222
# via
2323
# -c requirements.txt
2424
# django-stubs

engine/requirements.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ babel==2.12.1
22
beautifulsoup4==4.12.2
33
celery[redis]==5.3.1
44
cryptography==43.0.1
5-
django==4.2.16
5+
django==4.2.17
66
django-add-default-value==0.10.0
77
django-anymail[amazon-ses]==12.0
88
django-cors-headers==3.7.0

engine/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ deprecated==1.2.14
7575
# opentelemetry-api
7676
# opentelemetry-exporter-otlp-proto-grpc
7777
# opentelemetry-semantic-conventions
78-
django==4.2.16
78+
django==4.2.17
7979
# via
8080
# -r requirements.in
8181
# django-add-default-value

engine/tox.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ banned-modules =
2121
# --allow-hosts = allow connections to the given hostnames/IPs.
2222
# - localhost = our tests on CI use localhost as the host to connect to databases running locally in docker container
2323
# - oncall-dev-mariadb = if you're running things locally, with a MariaDB instance running, there's a good chance the hostname will be this
24-
addopts = --dist no --no-migrations --color=yes --showlocals --disable-socket --allow-hosts=localhost,oncall-dev-mariadb
24+
# pytest-socket is disabled for now as it's making tests hang on CI
25+
addopts = --dist no --no-migrations --color=yes --showlocals
2526
# https://pytest-django.readthedocs.io/en/latest/faq.html#my-tests-are-not-being-found-why
2627
python_files = tests.py test_*.py *_tests.py
2728

0 commit comments

Comments
 (0)