Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix action/webhook API not accepting empty/null user #3094

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Accept empty and null user when updating webhook via API @mderynck ([#3094](https://github.com/grafana/oncall/pull/3094)))
- Fix slack notification for a shift which end is affected by a taken swap ([#3092](https://github.com/grafana/oncall/pull/3092))

## v1.3.40 (2023-08-28)
Expand Down
3 changes: 1 addition & 2 deletions engine/apps/public_api/serializers/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Meta:


class ActionUpdateSerializer(ActionCreateSerializer):
user = serializers.CharField(required=False, source="username")
user = serializers.CharField(required=False, source="username", allow_null=True, allow_blank=True)
trigger_type = WebhookTriggerTypeField(required=False)
forward_whole_payload = serializers.BooleanField(required=False, source="forward_all")

Expand All @@ -63,7 +63,6 @@ class Meta(ActionCreateSerializer.Meta):
"headers": {"required": False, "allow_null": True, "allow_blank": True},
"url": {"required": False, "allow_null": False, "allow_blank": False},
"data": {"required": False, "allow_null": True, "allow_blank": True},
"forward_whole_payload": {"required": False, "allow_null": False},
"http_method": {"required": False, "allow_null": False, "allow_blank": False},
"integration_filter": {"required": False, "allow_null": True},
}
45 changes: 37 additions & 8 deletions engine/apps/public_api/tests/test_custom_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,28 +354,59 @@ def test_create_custom_action_valid_after_render_use_all_data(make_organization_


@pytest.mark.django_db
@pytest.mark.django_db
@pytest.mark.parametrize(
"data",
[
(
{
"name": "RENAMED",
"url": "https://example.com",
}
),
(
{
"name": "RENAMED 1",
"url": "https://example.com",
"user": None,
"password": None,
"data": None,
"authorization_header": None,
"forward_whole_payload": True,
}
),
(
{
"name": "RENAMED 2",
"url": "https://example.com",
"user": "",
"password": "",
"data": "",
"authorization_header": "",
"forward_whole_payload": True,
}
),
],
)
def test_update_custom_action(
make_organization_and_user_with_token,
make_custom_webhook,
data,
):
organization, user, token = make_organization_and_user_with_token()
client = APIClient()

custom_action = make_custom_webhook(organization=organization)

url = reverse("api-public:actions-detail", kwargs={"pk": custom_action.public_primary_key})

data = {
"name": "RENAMED",
}

assert custom_action.name != data["name"]

response = client.put(url, data=data, format="json", HTTP_AUTHORIZATION=f"{token}")
custom_action.refresh_from_db()

expected_result = {
"id": custom_action.public_primary_key,
"name": data["name"],
"name": custom_action.name,
"team_id": None,
"url": custom_action.url,
"data": custom_action.data,
Expand All @@ -392,8 +423,6 @@ def test_update_custom_action(
}

assert response.status_code == status.HTTP_200_OK
custom_action.refresh_from_db()
assert custom_action.name == expected_result["name"]
assert response.data == expected_result


Expand Down
3 changes: 1 addition & 2 deletions engine/apps/public_api/views/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import ModelViewSet

from apps.api.serializers.webhook import WebhookSerializer
from apps.auth_token.auth import ApiTokenAuthentication
from apps.public_api.serializers.action import ActionCreateSerializer, ActionUpdateSerializer
from apps.public_api.throttlers.user_throttle import UserThrottle
Expand All @@ -19,7 +18,7 @@ class ActionView(RateLimitHeadersMixin, PublicPrimaryKeyMixin, UpdateSerializerM
pagination_class = FiftyPageSizePaginator
throttle_classes = [UserThrottle]

model = WebhookSerializer
model = Webhook
serializer_class = ActionCreateSerializer
update_serializer_class = ActionUpdateSerializer

Expand Down