mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-28 09:16:49 +01:00
8a629179a9
* Update only models * Bring in line with master and use uuid1_macless * Update models and annotation scope support * Delete test_team_model.py * Update user creation, team retrieval and fix tests * Make fixes * Rename migration * Fix migrating from master * Bring back previous company_name max_length * Use get_price_id() * Temporarily disable team member deletion * Update user joining and leaving, and billing * Improve first_name handling * Update warning * Update TestTeamUser * Fix migration * Update 0085_org_models.py * Improve bootstrapping * Move multitenancy price tests to posthog-production * Update team_user.py * Update setup_review.py * Enhance opt_slash_path * Update team.py * Fix default test email * Fix typing
33 lines
939 B
Python
33 lines
939 B
Python
from django.conf import settings
|
|
from rest_framework import exceptions, serializers, viewsets
|
|
|
|
from ee.models.hook import Hook
|
|
|
|
|
|
class HookSerializer(serializers.ModelSerializer):
|
|
def validate_event(self, event):
|
|
if event not in settings.HOOK_EVENTS:
|
|
raise exceptions.ValidationError(detail=f"Unexpected event {event}")
|
|
return event
|
|
|
|
class Meta:
|
|
model = Hook
|
|
fields = ("id", "created", "updated", "event", "target", "resource_id", "team")
|
|
read_only_fields = ("team",)
|
|
|
|
|
|
class HookViewSet(viewsets.ModelViewSet):
|
|
"""
|
|
Retrieve, create, update or destroy webhooks.
|
|
"""
|
|
|
|
model = Hook
|
|
serializer_class = HookSerializer
|
|
|
|
def get_queryset(self):
|
|
return Hook.objects.filter(user_id=self.request.user.id).order_by("-created_at")
|
|
|
|
def perform_create(self, serializer):
|
|
user = self.request.user
|
|
serializer.save(user=user, team=user.team)
|