forked from github/plane
[WEB-1023] chore: page mention transactions (#4222)
* chore: null validation for old value in pages * chore: page transaction activity * chore: serialized description_html
This commit is contained in:
parent
8e764004f0
commit
68c870b791
@ -1,6 +1,7 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
@ -142,6 +143,7 @@ class PageViewSet(BaseViewSet):
|
|||||||
serializer = PageDetailSerializer(
|
serializer = PageDetailSerializer(
|
||||||
page, data=request.data, partial=True
|
page, data=request.data, partial=True
|
||||||
)
|
)
|
||||||
|
page_description = page.description_html
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
# capture the page transaction
|
# capture the page transaction
|
||||||
@ -150,11 +152,13 @@ class PageViewSet(BaseViewSet):
|
|||||||
new_value=request.data,
|
new_value=request.data,
|
||||||
old_value=json.dumps(
|
old_value=json.dumps(
|
||||||
{
|
{
|
||||||
"description_html": page.description_html,
|
"description_html": page_description,
|
||||||
}
|
},
|
||||||
|
cls=DjangoJSONEncoder,
|
||||||
),
|
),
|
||||||
page_id=pk,
|
page_id=pk,
|
||||||
)
|
)
|
||||||
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
return Response(
|
return Response(
|
||||||
serializer.errors, status=status.HTTP_400_BAD_REQUEST
|
serializer.errors, status=status.HTTP_400_BAD_REQUEST
|
||||||
|
@ -37,10 +37,10 @@ def page_transaction(new_value, old_value, page_id):
|
|||||||
page = Page.objects.get(pk=page_id)
|
page = Page.objects.get(pk=page_id)
|
||||||
new_page_mention = PageLog.objects.filter(page_id=page_id).exists()
|
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 = []
|
new_transactions = []
|
||||||
deleted_transaction_ids = set()
|
deleted_transaction_ids = set()
|
||||||
|
|
||||||
# TODO - Add "issue-embed-component", "img", "todo" components
|
# TODO - Add "issue-embed-component", "img", "todo" components
|
||||||
components = ["mention-component"]
|
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 = extract_components(new_value, component)
|
||||||
|
|
||||||
new_mentions_ids = {mention["id"] for mention in new_mentions}
|
new_mentions_ids = {mention["id"] for mention in new_mentions}
|
||||||
old_mention_ids = {mention["id"] for mention in old_mentions}
|
old_mention_ids = {mention["id"] for mention in old_mentions}
|
||||||
deleted_transaction_ids.update(old_mention_ids - new_mentions_ids)
|
deleted_transaction_ids.update(old_mention_ids - new_mentions_ids)
|
||||||
|
|
||||||
new_transactions.extend(
|
new_transactions.extend(
|
||||||
PageLog(
|
PageLog(
|
||||||
@ -68,9 +68,9 @@ def page_transaction(new_value, old_value, page_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Create new PageLog objects for new transactions
|
# 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
|
# Delete the removed transactions
|
||||||
PageLog.objects.filter(
|
PageLog.objects.filter(transaction__in=deleted_transaction_ids).delete()
|
||||||
transaction__in=deleted_transaction_ids
|
|
||||||
).delete()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user