mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
Merge pull request #67 from pablohashescobar/fix/cycle_module_issue
fix: make cycle issue and module issue responses consistent
This commit is contained in:
commit
24fcdd821d
@ -21,7 +21,7 @@ class CycleSerializer(BaseSerializer):
|
|||||||
|
|
||||||
class CycleIssueSerializer(BaseSerializer):
|
class CycleIssueSerializer(BaseSerializer):
|
||||||
|
|
||||||
issue_details = IssueStateSerializer(read_only=True, source="issue")
|
issue_detail = IssueStateSerializer(read_only=True, source="issue")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CycleIssue
|
model = CycleIssue
|
||||||
|
@ -22,6 +22,8 @@ from plane.db.models import (
|
|||||||
IssueBlocker,
|
IssueBlocker,
|
||||||
CycleIssue,
|
CycleIssue,
|
||||||
Cycle,
|
Cycle,
|
||||||
|
Module,
|
||||||
|
ModuleIssue,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -75,6 +77,11 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
write_only=True,
|
write_only=True,
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
blocks_list = serializers.ListField(
|
||||||
|
child=serializers.PrimaryKeyRelatedField(queryset=Issue.objects.all()),
|
||||||
|
write_only=True,
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Issue
|
model = Issue
|
||||||
@ -92,6 +99,7 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
blockers = validated_data.pop("blockers_list", None)
|
blockers = validated_data.pop("blockers_list", None)
|
||||||
assignees = validated_data.pop("assignees_list", None)
|
assignees = validated_data.pop("assignees_list", None)
|
||||||
labels = validated_data.pop("labels_list", None)
|
labels = validated_data.pop("labels_list", None)
|
||||||
|
blocks = validated_data.pop("blocks_list", None)
|
||||||
|
|
||||||
project = self.context["project"]
|
project = self.context["project"]
|
||||||
issue = Issue.objects.create(**validated_data, project=project)
|
issue = Issue.objects.create(**validated_data, project=project)
|
||||||
@ -144,6 +152,22 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
batch_size=10,
|
batch_size=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if blocks is not None:
|
||||||
|
IssueBlocker.objects.bulk_create(
|
||||||
|
[
|
||||||
|
IssueBlocker(
|
||||||
|
block=block,
|
||||||
|
blocked_by=issue,
|
||||||
|
project=project,
|
||||||
|
workspace=project.workspace,
|
||||||
|
created_by=issue.created_by,
|
||||||
|
updated_by=issue.updated_by,
|
||||||
|
)
|
||||||
|
for block in blocks
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
)
|
||||||
|
|
||||||
return issue
|
return issue
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
@ -151,6 +175,7 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
blockers = validated_data.pop("blockers_list", None)
|
blockers = validated_data.pop("blockers_list", None)
|
||||||
assignees = validated_data.pop("assignees_list", None)
|
assignees = validated_data.pop("assignees_list", None)
|
||||||
labels = validated_data.pop("labels_list", None)
|
labels = validated_data.pop("labels_list", None)
|
||||||
|
blocks = validated_data.pop("blocks_list", None)
|
||||||
|
|
||||||
if blockers is not None:
|
if blockers is not None:
|
||||||
IssueBlocker.objects.filter(block=instance).delete()
|
IssueBlocker.objects.filter(block=instance).delete()
|
||||||
@ -203,6 +228,23 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
batch_size=10,
|
batch_size=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if blocks is not None:
|
||||||
|
IssueBlocker.objects.filter(blocked_by=instance).delete()
|
||||||
|
IssueBlocker.objects.bulk_create(
|
||||||
|
[
|
||||||
|
IssueBlocker(
|
||||||
|
block=block,
|
||||||
|
blocked_by=instance,
|
||||||
|
project=instance.project,
|
||||||
|
workspace=instance.project.workspace,
|
||||||
|
created_by=instance.created_by,
|
||||||
|
updated_by=instance.updated_by,
|
||||||
|
)
|
||||||
|
for block in blocks
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
)
|
||||||
|
|
||||||
return super().update(instance, validated_data)
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
|
||||||
@ -342,6 +384,37 @@ class IssueCycleDetailSerializer(BaseSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleBaseSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Module
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueModuleDetailSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
module_detail = ModuleBaseSerializer(read_only=True, source="module")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ModuleIssue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class IssueSerializer(BaseSerializer):
|
class IssueSerializer(BaseSerializer):
|
||||||
project_detail = ProjectSerializer(read_only=True, source="project")
|
project_detail = ProjectSerializer(read_only=True, source="project")
|
||||||
state_detail = StateSerializer(read_only=True, source="state")
|
state_detail = StateSerializer(read_only=True, source="state")
|
||||||
@ -351,6 +424,7 @@ class IssueSerializer(BaseSerializer):
|
|||||||
blocked_issues = BlockedIssueSerializer(read_only=True, many=True)
|
blocked_issues = BlockedIssueSerializer(read_only=True, many=True)
|
||||||
blocker_issues = BlockerIssueSerializer(read_only=True, many=True)
|
blocker_issues = BlockerIssueSerializer(read_only=True, many=True)
|
||||||
issue_cycle = IssueCycleDetailSerializer(read_only=True)
|
issue_cycle = IssueCycleDetailSerializer(read_only=True)
|
||||||
|
issue_module = IssueModuleDetailSerializer(read_only=True, many=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Issue
|
model = Issue
|
||||||
|
@ -5,7 +5,7 @@ from rest_framework import serializers
|
|||||||
from .base import BaseSerializer
|
from .base import BaseSerializer
|
||||||
from .user import UserLiteSerializer
|
from .user import UserLiteSerializer
|
||||||
from .project import ProjectSerializer
|
from .project import ProjectSerializer
|
||||||
from .issue import IssueFlatSerializer
|
from .issue import IssueStateSerializer
|
||||||
|
|
||||||
from plane.db.models import User, Module, ModuleMember, ModuleIssue
|
from plane.db.models import User, Module, ModuleMember, ModuleIssue
|
||||||
|
|
||||||
@ -52,6 +52,7 @@ class ModuleWriteSerializer(BaseSerializer):
|
|||||||
for member in members
|
for member in members
|
||||||
],
|
],
|
||||||
batch_size=10,
|
batch_size=10,
|
||||||
|
ignore_conflicts=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
return module
|
return module
|
||||||
@ -59,25 +60,22 @@ class ModuleWriteSerializer(BaseSerializer):
|
|||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
|
|
||||||
members = validated_data.pop("members_list", None)
|
members = validated_data.pop("members_list", None)
|
||||||
|
|
||||||
project = self.context["project"]
|
|
||||||
|
|
||||||
module = Module.objects.create(**validated_data, project=project)
|
|
||||||
|
|
||||||
if members is not None:
|
if members is not None:
|
||||||
|
ModuleIssue.objects.filter(module=instance).delete()
|
||||||
ModuleMember.objects.bulk_create(
|
ModuleMember.objects.bulk_create(
|
||||||
[
|
[
|
||||||
ModuleMember(
|
ModuleMember(
|
||||||
module=module,
|
module=instance,
|
||||||
member=member,
|
member=member,
|
||||||
project=project,
|
project=instance.project,
|
||||||
workspace=project.workspace,
|
workspace=instance.project.workspace,
|
||||||
created_by=module.created_by,
|
created_by=instance.created_by,
|
||||||
updated_by=module.updated_by,
|
updated_by=instance.updated_by,
|
||||||
)
|
)
|
||||||
for member in members
|
for member in members
|
||||||
],
|
],
|
||||||
batch_size=10,
|
batch_size=10,
|
||||||
|
ignore_conflicts=True
|
||||||
)
|
)
|
||||||
|
|
||||||
return super().update(instance, validated_data)
|
return super().update(instance, validated_data)
|
||||||
@ -100,7 +98,7 @@ class ModuleFlatSerializer(BaseSerializer):
|
|||||||
class ModuleIssueSerializer(BaseSerializer):
|
class ModuleIssueSerializer(BaseSerializer):
|
||||||
|
|
||||||
module_detail = ModuleFlatSerializer(read_only=True, source="module")
|
module_detail = ModuleFlatSerializer(read_only=True, source="module")
|
||||||
issue_detail = IssueFlatSerializer(read_only=True, source="issue")
|
issue_detail = IssueStateSerializer(read_only=True, source="issue")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ModuleIssue
|
model = ModuleIssue
|
||||||
|
@ -37,6 +37,7 @@ from plane.db.models import (
|
|||||||
Label,
|
Label,
|
||||||
IssueBlocker,
|
IssueBlocker,
|
||||||
CycleIssue,
|
CycleIssue,
|
||||||
|
ModuleIssue
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -96,6 +97,12 @@ class IssueViewSet(BaseViewSet):
|
|||||||
queryset=CycleIssue.objects.select_related("cycle", "issue"),
|
queryset=CycleIssue.objects.select_related("cycle", "issue"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
.prefetch_related(
|
||||||
|
Prefetch(
|
||||||
|
"issue_module",
|
||||||
|
queryset=ModuleIssue.objects.select_related("module", "issue"),
|
||||||
|
),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def grouper(self, issue, group_by):
|
def grouper(self, issue, group_by):
|
||||||
@ -175,6 +182,7 @@ class UserWorkSpaceIssues(BaseAPIView):
|
|||||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class WorkSpaceIssuesEndpoint(BaseAPIView):
|
class WorkSpaceIssuesEndpoint(BaseAPIView):
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
|
@ -44,7 +44,7 @@ class ModuleViewSet(BaseViewSet):
|
|||||||
.prefetch_related("members")
|
.prefetch_related("members")
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
Prefetch(
|
Prefetch(
|
||||||
"module_issues",
|
"issue_module",
|
||||||
queryset=ModuleIssue.objects.select_related("module", "issue"),
|
queryset=ModuleIssue.objects.select_related("module", "issue"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
24
apiserver/plane/db/migrations/0014_auto_20221222_1436.py
Normal file
24
apiserver/plane/db/migrations/0014_auto_20221222_1436.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 3.2.14 on 2022-12-22 09:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('db', '0013_projectmember_default_props'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='moduleissue',
|
||||||
|
name='issue',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='issue_module', to='db.issue'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='moduleissue',
|
||||||
|
name='module',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='issue_module', to='db.module'),
|
||||||
|
),
|
||||||
|
]
|
@ -71,10 +71,10 @@ class ModuleMember(ProjectBaseModel):
|
|||||||
class ModuleIssue(ProjectBaseModel):
|
class ModuleIssue(ProjectBaseModel):
|
||||||
|
|
||||||
module = models.ForeignKey(
|
module = models.ForeignKey(
|
||||||
"db.Module", on_delete=models.CASCADE, related_name="module_issues"
|
"db.Module", on_delete=models.CASCADE, related_name="issue_module"
|
||||||
)
|
)
|
||||||
issue = models.ForeignKey(
|
issue = models.ForeignKey(
|
||||||
"db.Issue", on_delete=models.CASCADE, related_name="module_issues"
|
"db.Issue", on_delete=models.CASCADE, related_name="issue_module"
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
Loading…
Reference in New Issue
Block a user