Skip to content

Commit

Permalink
Fix REST hook deletion (#2893)
Browse files Browse the repository at this point in the history
* Fix REST hook deletion

* Fix hook deletion better

* Add API DELETE test
  • Loading branch information
Twixes authored Jan 8, 2021
1 parent 32e557e commit 43b0972
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 1 addition & 2 deletions ee/api/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class HookViewSet(StructuredViewSetMixin, viewsets.ModelViewSet):
Retrieve, create, update or destroy webhooks.
"""

queryset = Hook.objects.none()
serializer_class = HookSerializer
queryset = Hook.objects.all()
ordering = "-created_at"
permission_classes = [IsAuthenticated, OrganizationMemberPermissions]
serializer_class = HookSerializer
Expand Down
6 changes: 6 additions & 0 deletions ee/api/test/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ def test_create_hook_with_resource_id(self):
},
cast(dict, response.data),
)

def test_delete_hook(self):
hook_id = "abc123"
Hook.objects.create(id=hook_id, user=self.user, team=self.team, resource_id=20)
response = self.client.delete(f"/api/projects/{self.team.id}/hooks/{hook_id}")
self.assertEqual(response.status_code, 204)
5 changes: 2 additions & 3 deletions ee/tasks/hooks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import json
from typing import Optional

import requests
from celery.task import Task
from django.core.serializers.json import DjangoJSONEncoder
from rest_hooks.utils import get_hook_model


class DeliverHook(Task):
Expand All @@ -20,7 +18,8 @@ def run(self, target: str, payload: dict, hook_id: str) -> None:
)
if response.status_code == 410 and hook_id:
# Delete hook on our side if it's gone on Zapier's
Hook = get_hook_model()
from ee.models.hook import Hook

Hook.objects.filter(id=hook_id).delete()
return
if response.status_code >= 500:
Expand Down

0 comments on commit 43b0972

Please sign in to comment.