[WEB-2600] fix: estimate point deletion (#5762)
* chore: only delete the cascade fields * chore: logged the issue activity
This commit is contained in:
parent
7bb04003ea
commit
c92fe6191e
4 changed files with 87 additions and 23 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
import json
|
||||||
|
|
||||||
|
# Django imports
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
@ -19,6 +23,7 @@ from plane.app.serializers import (
|
||||||
EstimateReadSerializer,
|
EstimateReadSerializer,
|
||||||
)
|
)
|
||||||
from plane.utils.cache import invalidate_cache
|
from plane.utils.cache import invalidate_cache
|
||||||
|
from plane.bgtasks.issue_activities_task import issue_activity
|
||||||
|
|
||||||
|
|
||||||
def generate_random_name(length=10):
|
def generate_random_name(length=10):
|
||||||
|
|
@ -249,11 +254,66 @@ class EstimatePointEndpoint(BaseViewSet):
|
||||||
)
|
)
|
||||||
# update all the issues with the new estimate
|
# update all the issues with the new estimate
|
||||||
if new_estimate_id:
|
if new_estimate_id:
|
||||||
_ = Issue.objects.filter(
|
issues = Issue.objects.filter(
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
estimate_point_id=estimate_point_id,
|
estimate_point_id=estimate_point_id,
|
||||||
).update(estimate_point_id=new_estimate_id)
|
)
|
||||||
|
for issue in issues:
|
||||||
|
issue_activity.delay(
|
||||||
|
type="issue.activity.updated",
|
||||||
|
requested_data=json.dumps(
|
||||||
|
{
|
||||||
|
"estimate_point": (
|
||||||
|
str(new_estimate_id)
|
||||||
|
if new_estimate_id
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
actor_id=str(request.user.id),
|
||||||
|
issue_id=issue.id,
|
||||||
|
project_id=str(project_id),
|
||||||
|
current_instance=json.dumps(
|
||||||
|
{
|
||||||
|
"estimate_point": (
|
||||||
|
str(issue.estimate_point_id)
|
||||||
|
if issue.estimate_point_id
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
epoch=int(timezone.now().timestamp()),
|
||||||
|
)
|
||||||
|
issues.update(estimate_point_id=new_estimate_id)
|
||||||
|
else:
|
||||||
|
issues = Issue.objects.filter(
|
||||||
|
project_id=project_id,
|
||||||
|
workspace__slug=slug,
|
||||||
|
estimate_point_id=estimate_point_id,
|
||||||
|
)
|
||||||
|
for issue in issues:
|
||||||
|
issue_activity.delay(
|
||||||
|
type="issue.activity.updated",
|
||||||
|
requested_data=json.dumps(
|
||||||
|
{
|
||||||
|
"estimate_point": None,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
actor_id=str(request.user.id),
|
||||||
|
issue_id=issue.id,
|
||||||
|
project_id=str(project_id),
|
||||||
|
current_instance=json.dumps(
|
||||||
|
{
|
||||||
|
"estimate_point": (
|
||||||
|
str(issue.estimate_point_id)
|
||||||
|
if issue.estimate_point_id
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
epoch=int(timezone.now().timestamp()),
|
||||||
|
)
|
||||||
|
|
||||||
# delete the estimate point
|
# delete the estimate point
|
||||||
old_estimate_point = EstimatePoint.objects.filter(
|
old_estimate_point = EstimatePoint.objects.filter(
|
||||||
|
|
|
||||||
|
|
@ -413,7 +413,7 @@ class ProjectViewSet(BaseViewSet):
|
||||||
status=status.HTTP_410_GONE,
|
status=status.HTTP_410_GONE,
|
||||||
)
|
)
|
||||||
|
|
||||||
@allow_permission([ROLE.ADMIN, ROLE.MEMBER], level="WORKSPACE")
|
@allow_permission([ROLE.ADMIN])
|
||||||
def partial_update(self, request, slug, pk=None):
|
def partial_update(self, request, slug, pk=None):
|
||||||
try:
|
try:
|
||||||
workspace = Workspace.objects.get(slug=slug)
|
workspace = Workspace.objects.get(slug=slug)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import models
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
|
|
@ -18,17 +19,25 @@ def soft_delete_related_objects(
|
||||||
for field in related_fields:
|
for field in related_fields:
|
||||||
if field.one_to_many or field.one_to_one:
|
if field.one_to_many or field.one_to_one:
|
||||||
try:
|
try:
|
||||||
if field.one_to_many:
|
# Check if the field has CASCADE on delete
|
||||||
related_objects = getattr(instance, field.name).all()
|
if (
|
||||||
elif field.one_to_one:
|
hasattr(field.remote_field, "on_delete")
|
||||||
related_object = getattr(instance, field.name)
|
and field.remote_field.on_delete == models.CASCADE
|
||||||
related_objects = (
|
):
|
||||||
[related_object] if related_object is not None else []
|
if field.one_to_many:
|
||||||
)
|
related_objects = getattr(instance, field.name).all()
|
||||||
for obj in related_objects:
|
elif field.one_to_one:
|
||||||
if obj:
|
related_object = getattr(instance, field.name)
|
||||||
obj.deleted_at = timezone.now()
|
related_objects = (
|
||||||
obj.save(using=using)
|
[related_object]
|
||||||
|
if related_object is not None
|
||||||
|
else []
|
||||||
|
)
|
||||||
|
|
||||||
|
for obj in related_objects:
|
||||||
|
if obj:
|
||||||
|
obj.deleted_at = timezone.now()
|
||||||
|
obj.save(using=using)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -154,8 +163,7 @@ def hard_delete():
|
||||||
if hasattr(model, "deleted_at"):
|
if hasattr(model, "deleted_at"):
|
||||||
# Get all instances where 'deleted_at' is greater than 30 days ago
|
# Get all instances where 'deleted_at' is greater than 30 days ago
|
||||||
_ = model.all_objects.filter(
|
_ = model.all_objects.filter(
|
||||||
deleted_at__lt=timezone.now()
|
deleted_at__lt=timezone.now() - timezone.timedelta(days=days)
|
||||||
- timezone.timedelta(days=days)
|
|
||||||
).delete()
|
).delete()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -465,7 +465,7 @@ def track_estimate_points(
|
||||||
IssueActivity(
|
IssueActivity(
|
||||||
issue_id=issue_id,
|
issue_id=issue_id,
|
||||||
actor_id=actor_id,
|
actor_id=actor_id,
|
||||||
verb="updated",
|
verb="removed" if new_estimate is None else "updated",
|
||||||
old_identifier=(
|
old_identifier=(
|
||||||
current_instance.get("estimate_point")
|
current_instance.get("estimate_point")
|
||||||
if current_instance.get("estimate_point") is not None
|
if current_instance.get("estimate_point") is not None
|
||||||
|
|
@ -1700,16 +1700,12 @@ def issue_activity(
|
||||||
event=(
|
event=(
|
||||||
"issue_comment"
|
"issue_comment"
|
||||||
if activity.field == "comment"
|
if activity.field == "comment"
|
||||||
else "inbox_issue"
|
else "inbox_issue" if inbox else "issue"
|
||||||
if inbox
|
|
||||||
else "issue"
|
|
||||||
),
|
),
|
||||||
event_id=(
|
event_id=(
|
||||||
activity.issue_comment_id
|
activity.issue_comment_id
|
||||||
if activity.field == "comment"
|
if activity.field == "comment"
|
||||||
else inbox
|
else inbox if inbox else activity.issue_id
|
||||||
if inbox
|
|
||||||
else activity.issue_id
|
|
||||||
),
|
),
|
||||||
verb=activity.verb,
|
verb=activity.verb,
|
||||||
field=(
|
field=(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue