feat: add grafana_irm_enabled to GET /organization endpoint response (#5230)
# What this PR does Backend portion of https://github.com/grafana/oncall-mobile-app/issues/1021 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
This commit is contained in:
parent
4871b3a781
commit
7501304e96
2 changed files with 32 additions and 4 deletions
|
|
@ -26,6 +26,7 @@ class OrganizationSerializer(EagerLoadingMixin, serializers.ModelSerializer):
|
|||
|
||||
rbac_enabled = serializers.BooleanField(read_only=True, source="is_rbac_permissions_enabled")
|
||||
grafana_incident_enabled = serializers.BooleanField(read_only=True, source="is_grafana_incident_enabled")
|
||||
grafana_irm_enabled = serializers.BooleanField(read_only=True, source="is_grafana_irm_enabled")
|
||||
|
||||
SELECT_RELATED = ["slack_team_identity", "slack_channel"]
|
||||
|
||||
|
|
@ -39,6 +40,7 @@ class OrganizationSerializer(EagerLoadingMixin, serializers.ModelSerializer):
|
|||
"slack_channel",
|
||||
"rbac_enabled",
|
||||
"grafana_incident_enabled",
|
||||
"grafana_irm_enabled",
|
||||
"direct_paging_prefer_important_policy",
|
||||
]
|
||||
read_only_fields = [
|
||||
|
|
@ -46,6 +48,7 @@ class OrganizationSerializer(EagerLoadingMixin, serializers.ModelSerializer):
|
|||
"slack_team_identity",
|
||||
"rbac_enabled",
|
||||
"grafana_incident_enabled",
|
||||
"grafana_irm_enabled",
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,10 @@ def test_get_organization(
|
|||
|
||||
client = APIClient()
|
||||
url = reverse("api-internal:api-organization")
|
||||
expected_result = {
|
||||
response = client.get(url, format="json", **make_user_auth_headers(user, token))
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json() == {
|
||||
"pk": organization.public_primary_key,
|
||||
"name": organization.org_title,
|
||||
"stack_slug": organization.stack_slug,
|
||||
|
|
@ -44,14 +47,12 @@ def test_get_organization(
|
|||
"slack_channel": None,
|
||||
"rbac_enabled": organization.is_rbac_permissions_enabled,
|
||||
"grafana_incident_enabled": organization.is_grafana_incident_enabled,
|
||||
"grafana_irm_enabled": organization.is_grafana_irm_enabled,
|
||||
"direct_paging_prefer_important_policy": organization.direct_paging_prefer_important_policy,
|
||||
"is_resolution_note_required": False,
|
||||
"env_status": mock_env_status,
|
||||
"banner": mock_banner,
|
||||
}
|
||||
response = client.get(url, format="json", **make_user_auth_headers(user, token))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json() == expected_result
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
|
@ -70,6 +71,30 @@ def test_get_organization_rbac_enabled(make_organization_and_user_with_plugin_to
|
|||
assert response.json()["rbac_enabled"] == organization.is_rbac_permissions_enabled
|
||||
|
||||
|
||||
# NOTE: we need to patch the following because when is_grafana_irm_enabled is True, it alters how
|
||||
# API authz works. For the purpose of this test, we don't care about testing that behaviour (it's already tested),
|
||||
# just want to test the serializer essentially.
|
||||
@patch("apps.api.permissions.user_is_authorized", return_value=True)
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("is_grafana_irm_enabled", [True, False])
|
||||
def test_get_organization_grafana_irm_enabled(
|
||||
_mock_user_is_authorized,
|
||||
make_organization_and_user_with_plugin_token,
|
||||
make_user_auth_headers,
|
||||
is_grafana_irm_enabled,
|
||||
):
|
||||
organization, user, token = make_organization_and_user_with_plugin_token()
|
||||
organization.is_grafana_irm_enabled = is_grafana_irm_enabled
|
||||
organization.save()
|
||||
|
||||
client = APIClient()
|
||||
url = reverse("api-internal:api-organization")
|
||||
|
||||
response = client.get(url, format="json", **make_user_auth_headers(user, token))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["grafana_irm_enabled"] is is_grafana_irm_enabled
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_update_organization_settings(make_organization_and_user_with_plugin_token, make_user_auth_headers):
|
||||
organization, user, token = make_organization_and_user_with_plugin_token()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue