From 68c870b7919119c08e47c29e0b01a7c49cc56316 Mon Sep 17 00:00:00 2001 From: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:18:14 +0530 Subject: [PATCH] [WEB-1023] chore: page mention transactions (#4222) * chore: null validation for old value in pages * chore: page transaction activity * chore: serialized description_html --- apiserver/plane/app/views/page/base.py | 8 ++++++-- apiserver/plane/bgtasks/page_transaction_task.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/apiserver/plane/app/views/page/base.py b/apiserver/plane/app/views/page/base.py index 4076a53b1..29dc2dbf5 100644 --- a/apiserver/plane/app/views/page/base.py +++ b/apiserver/plane/app/views/page/base.py @@ -1,6 +1,7 @@ # Python imports import json from datetime import datetime +from django.core.serializers.json import DjangoJSONEncoder # Django imports from django.db import connection @@ -142,6 +143,7 @@ class PageViewSet(BaseViewSet): serializer = PageDetailSerializer( page, data=request.data, partial=True ) + page_description = page.description_html if serializer.is_valid(): serializer.save() # capture the page transaction @@ -150,11 +152,13 @@ class PageViewSet(BaseViewSet): new_value=request.data, old_value=json.dumps( { - "description_html": page.description_html, - } + "description_html": page_description, + }, + cls=DjangoJSONEncoder, ), page_id=pk, ) + return Response(serializer.data, status=status.HTTP_200_OK) return Response( serializer.errors, status=status.HTTP_400_BAD_REQUEST diff --git a/apiserver/plane/bgtasks/page_transaction_task.py b/apiserver/plane/bgtasks/page_transaction_task.py index 57f4f644e..eceb3693e 100644 --- a/apiserver/plane/bgtasks/page_transaction_task.py +++ b/apiserver/plane/bgtasks/page_transaction_task.py @@ -37,10 +37,10 @@ def page_transaction(new_value, old_value, page_id): page = Page.objects.get(pk=page_id) new_page_mention = PageLog.objects.filter(page_id=page_id).exists() - old_value = json.loads(old_value) + old_value = json.loads(old_value) if old_value else {} new_transactions = [] - deleted_transaction_ids = set() + deleted_transaction_ids = set() # TODO - Add "issue-embed-component", "img", "todo" components components = ["mention-component"] @@ -49,8 +49,8 @@ def page_transaction(new_value, old_value, page_id): new_mentions = extract_components(new_value, component) new_mentions_ids = {mention["id"] for mention in new_mentions} - old_mention_ids = {mention["id"] for mention in old_mentions} - deleted_transaction_ids.update(old_mention_ids - new_mentions_ids) + old_mention_ids = {mention["id"] for mention in old_mentions} + deleted_transaction_ids.update(old_mention_ids - new_mentions_ids) new_transactions.extend( PageLog( @@ -68,9 +68,9 @@ def page_transaction(new_value, old_value, page_id): ) # Create new PageLog objects for new transactions - PageLog.objects.bulk_create(new_transactions, batch_size=10, ignore_conflicts=True) + PageLog.objects.bulk_create( + new_transactions, batch_size=10, ignore_conflicts=True + ) # Delete the removed transactions - PageLog.objects.filter( - transaction__in=deleted_transaction_ids - ).delete() + PageLog.objects.filter(transaction__in=deleted_transaction_ids).delete()