chore: changed issue relation history logs (#2192)

* chore: changed issue relation history logs

* chore: change field name
This commit is contained in:
Bavisetti Narayan 2023-09-15 13:12:28 +05:30 committed by GitHub
parent 32d945be0d
commit b274a21ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 23 deletions

View File

@ -293,12 +293,12 @@ class IssueLabelSerializer(BaseSerializer):
class IssueRelationSerializer(BaseSerializer): class IssueRelationSerializer(BaseSerializer):
related_issue_detail = IssueProjectLiteSerializer(read_only=True, source="related_issue") issue_detail = IssueProjectLiteSerializer(read_only=True, source="related_issue")
class Meta: class Meta:
model = IssueRelation model = IssueRelation
fields = [ fields = [
"related_issue_detail", "issue_detail",
"relation_type", "relation_type",
"related_issue", "related_issue",
"issue", "issue",

View File

@ -53,6 +53,7 @@ from plane.api.serializers import (
CommentReactionSerializer, CommentReactionSerializer,
IssueVoteSerializer, IssueVoteSerializer,
IssueRelationSerializer, IssueRelationSerializer,
RelatedIssueSerializer,
IssuePublicSerializer, IssuePublicSerializer,
) )
from plane.api.permissions import ( from plane.api.permissions import (
@ -2085,9 +2086,10 @@ class IssueRelationViewSet(BaseViewSet):
def create(self, request, slug, project_id, issue_id): def create(self, request, slug, project_id, issue_id):
try: try:
related_list = request.data.get("related_list", []) related_list = request.data.get("related_list", [])
relation = request.data.get("relation", None)
project = Project.objects.get(pk=project_id) project = Project.objects.get(pk=project_id)
issueRelation = IssueRelation.objects.bulk_create( issue_relation = IssueRelation.objects.bulk_create(
[ [
IssueRelation( IssueRelation(
issue_id=related_issue["issue"], issue_id=related_issue["issue"],
@ -2112,11 +2114,17 @@ class IssueRelationViewSet(BaseViewSet):
project_id=str(project_id), project_id=str(project_id),
current_instance=None, current_instance=None,
) )
return Response( if relation == "blocking":
IssueRelationSerializer(issueRelation, many=True).data, return Response(
status=status.HTTP_201_CREATED, RelatedIssueSerializer(issue_relation, many=True).data,
) status=status.HTTP_201_CREATED,
)
else:
return Response(
IssueRelationSerializer(issue_relation, many=True).data,
status=status.HTTP_201_CREATED,
)
except IntegrityError as e: except IntegrityError as e:
if "already exists" in str(e): if "already exists" in str(e):
return Response( return Response(

View File

@ -1048,6 +1048,25 @@ def create_issue_relation_activity(
) )
if current_instance is None and requested_data.get("related_list") is not None: if current_instance is None and requested_data.get("related_list") is not None:
for issue_relation in requested_data.get("related_list"): for issue_relation in requested_data.get("related_list"):
if issue_relation.get("relation_type") == "blocked_by":
relation_type = "blocking"
else:
relation_type = issue_relation.get("relation_type")
issue = Issue.objects.get(pk=issue_relation.get("issue"))
issue_activities.append(
IssueActivity(
issue_id=issue_relation.get("related_issue"),
actor=actor,
verb="created",
old_value="",
new_value=f"{project.identifier}-{issue.sequence_id}",
field=relation_type,
project=project,
workspace=project.workspace,
comment=f'added {relation_type} relation',
old_identifier=issue_relation.get("issue"),
)
)
issue = Issue.objects.get(pk=issue_relation.get("related_issue")) issue = Issue.objects.get(pk=issue_relation.get("related_issue"))
issue_activities.append( issue_activities.append(
IssueActivity( IssueActivity(
@ -1060,7 +1079,7 @@ def create_issue_relation_activity(
project=project, project=project,
workspace=project.workspace, workspace=project.workspace,
comment=f'added {issue_relation.get("relation_type")} relation', comment=f'added {issue_relation.get("relation_type")} relation',
old_identifier=issue_relation.get("issue"), old_identifier=issue_relation.get("related_issue"),
) )
) )
@ -1073,21 +1092,40 @@ def delete_issue_relation_activity(
json.loads(current_instance) if current_instance is not None else None json.loads(current_instance) if current_instance is not None else None
) )
if current_instance is not None and requested_data.get("related_list") is None: if current_instance is not None and requested_data.get("related_list") is None:
issue = Issue.objects.get(pk=current_instance.get("issue")) if current_instance.get("relation_type") == "blocked_by":
issue_activities.append( relation_type = "blocking"
IssueActivity( else:
issue_id=current_instance.get("issue"), relation_type = current_instance.get("relation_type")
actor=actor, issue = Issue.objects.get(pk=current_instance.get("issue"))
verb="deleted", issue_activities.append(
old_value=f"{project.identifier}-{issue.sequence_id}", IssueActivity(
new_value="", issue_id=current_instance.get("related_issue"),
field=f'{current_instance.get("relation_type")}', actor=actor,
project=project, verb="deleted",
workspace=project.workspace, old_value="",
comment=f'deleted the {current_instance.get("relation_type")} relation', new_value=f"{project.identifier}-{issue.sequence_id}",
old_identifier=current_instance.get("issue"), field=relation_type,
project=project,
workspace=project.workspace,
comment=f'deleted {relation_type} relation',
old_identifier=current_instance.get("issue"),
)
)
issue = Issue.objects.get(pk=current_instance.get("related_issue"))
issue_activities.append(
IssueActivity(
issue_id=current_instance.get("issue"),
actor=actor,
verb="deleted",
old_value="",
new_value=f"{project.identifier}-{issue.sequence_id}",
field=f'{current_instance.get("relation_type")}',
project=project,
workspace=project.workspace,
comment=f'deleted {current_instance.get("relation_type")} relation',
old_identifier=current_instance.get("related_issue"),
)
) )
)
def create_draft_issue_activity( def create_draft_issue_activity(

View File

@ -0,0 +1,23 @@
# Generated by Django 4.2.3 on 2023-09-15 06:55
from django.db import migrations
def update_issue_activity(apps, schema_editor):
IssueActivityModel = apps.get_model("db", "IssueActivity")
updated_issue_activity = []
for obj in IssueActivityModel.objects.all():
if obj.field == "blocks":
obj.field = "blocked_by"
updated_issue_activity.append(obj)
IssueActivityModel.objects.bulk_update(updated_issue_activity, ["field"], batch_size=100)
class Migration(migrations.Migration):
dependencies = [
('db', '0044_auto_20230913_0709'),
]
operations = [
migrations.RunPython(update_issue_activity),
]