[WEB - 1213] fix: module webhook (#4385)

* dev: fix module webhook

* dev: correct the comment

* dev: handle does not exist exception
This commit is contained in:
Nikhil 2024-05-07 15:51:08 +05:30 committed by GitHub
parent 967ad77078
commit a40517015b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 19 deletions

View File

@ -431,15 +431,15 @@ class ModuleViewSet(BaseViewSet):
def partial_update(self, request, slug, project_id, pk): def partial_update(self, request, slug, project_id, pk):
module = self.get_queryset().filter(pk=pk) module = self.get_queryset().filter(pk=pk)
current_instance = json.dumps(
ModuleSerializer(module).data, cls=DjangoJSONEncoder
)
if module.first().archived_at: if module.first().archived_at:
return Response( return Response(
{"error": "Archived module cannot be updated"}, {"error": "Archived module cannot be updated"},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
current_instance = json.dumps(
ModuleSerializer(module.first()).data, cls=DjangoJSONEncoder
)
serializer = ModuleWriteSerializer( serializer = ModuleWriteSerializer(
module.first(), data=request.data, partial=True module.first(), data=request.data, partial=True
) )

View File

@ -15,6 +15,7 @@ from django.core.mail import EmailMultiAlternatives, get_connection
from django.core.serializers.json import DjangoJSONEncoder from django.core.serializers.json import DjangoJSONEncoder
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.html import strip_tags from django.utils.html import strip_tags
from django.core.exceptions import ObjectDoesNotExist
# Module imports # Module imports
from plane.api.serializers import ( from plane.api.serializers import (
@ -422,6 +423,9 @@ def webhook_activity(
) )
return return
except Exception as e: except Exception as e:
# Return if a does not exist error occurs
if isinstance(e, ObjectDoesNotExist):
return
if settings.DEBUG: if settings.DEBUG:
print(e) print(e)
log_exception(e) log_exception(e)
@ -462,21 +466,23 @@ def model_activity(
# Loop through all keys in requested data and check the current value and requested value # Loop through all keys in requested data and check the current value and requested value
for key in requested_data: for key in requested_data:
current_value = current_instance.get(key, None) # Check if key is present in current instance or not
requested_value = requested_data.get(key, None) if key in current_instance:
if current_value != requested_value: current_value = current_instance.get(key, None)
webhook_activity.delay( requested_value = requested_data.get(key, None)
event=model_name, if current_value != requested_value:
verb="updated", webhook_activity.delay(
field=key, event=model_name,
old_value=current_value, verb="updated",
new_value=requested_value, field=key,
actor_id=actor_id, old_value=current_value,
slug=slug, new_value=requested_value,
current_site=origin, actor_id=actor_id,
event_id=model_id, slug=slug,
old_identifier=None, current_site=origin,
new_identifier=None, event_id=model_id,
) old_identifier=None,
new_identifier=None,
)
return return