Skip to content

Commit

Permalink
events for webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Eldies committed Nov 13, 2024
1 parent 23c413e commit 898c508
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions cvat/apps/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class EventScopes:
"label": ["create", "update", "delete"],
"dataset": ["export", "import"],
"function": ["call"],
"webhook": ["create", "update", "delete"],
}

@classmethod
Expand Down
4 changes: 4 additions & 0 deletions cvat/apps/events/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

from .cache import get_cache
from .event import event_scope, record_server_event
from ..webhooks.models import Webhook
from ..webhooks.serializers import WebhookReadSerializer


def project_id(instance):
Expand Down Expand Up @@ -246,6 +248,8 @@ def get_serializer(instance):
serializer = MembershipReadSerializer(instance=instance, context=context)
if isinstance(instance, Invitation):
serializer = InvitationReadSerializer(instance=instance, context=context)
if isinstance(instance, Webhook):
serializer = WebhookReadSerializer(instance=instance, context=context)

return serializer

Expand Down
4 changes: 4 additions & 0 deletions cvat/apps/events/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
Label,
)
from cvat.apps.organizations.models import Organization, Membership, Invitation
from cvat.apps.webhooks.models import Webhook

from .handlers import handle_update, handle_create, handle_delete
from .event import EventScopeChoice, event_scope


@receiver(pre_save, sender=Webhook, dispatch_uid="webhook:update_receiver")
@receiver(pre_save, sender=Membership, dispatch_uid="membership:update_receiver")
@receiver(pre_save, sender=Organization, dispatch_uid="organization:update_receiver")
@receiver(pre_save, sender=Project, dispatch_uid="project:update_receiver")
Expand Down Expand Up @@ -64,6 +66,7 @@ def resource_update(sender, *, instance, update_fields, **kwargs):
handle_update(scope=scope, instance=instance, old_instance=old_instance, **kwargs)


@receiver(post_save, sender=Webhook, dispatch_uid="webhook:create_receiver")
@receiver(post_save, sender=Membership, dispatch_uid="membership:create_receiver")
@receiver(post_save, sender=Invitation, dispatch_uid="invitation:create_receiver")
@receiver(post_save, sender=Organization, dispatch_uid="organization:create_receiver")
Expand All @@ -90,6 +93,7 @@ def resource_create(sender, instance, created, **kwargs):
handle_create(scope=scope, instance=instance, **kwargs)


@receiver(post_delete, sender=Webhook, dispatch_uid="webhook:delete_receiver")
@receiver(post_delete, sender=Membership, dispatch_uid="membership:delete_receiver")
@receiver(post_delete, sender=Invitation, dispatch_uid="invitation:delete_receiver")
@receiver(post_delete, sender=Organization, dispatch_uid="organization:delete_receiver")
Expand Down

0 comments on commit 898c508

Please sign in to comment.