diff --git a/apiserver/plane/api/serializers/issue.py b/apiserver/plane/api/serializers/issue.py index ab61ae523..75396e9bb 100644 --- a/apiserver/plane/api/serializers/issue.py +++ b/apiserver/plane/api/serializers/issue.py @@ -96,7 +96,7 @@ class IssueSerializer(BaseSerializer): if ( data.get("state") and not State.objects.filter( - project_id=self.context.get("project_id"), pk=data.get("state") + project_id=self.context.get("project_id"), pk=data.get("state").id ).exists() ): raise serializers.ValidationError( @@ -107,7 +107,7 @@ class IssueSerializer(BaseSerializer): if ( data.get("parent") and not Issue.objects.filter( - workspace_id=self.context.get("workspace_id"), pk=data.get("parent") + workspace_id=self.context.get("workspace_id"), pk=data.get("parent").id ).exists() ): raise serializers.ValidationError( diff --git a/apiserver/plane/api/serializers/module.py b/apiserver/plane/api/serializers/module.py index 65710e8af..a96a9b54d 100644 --- a/apiserver/plane/api/serializers/module.py +++ b/apiserver/plane/api/serializers/module.py @@ -65,18 +65,18 @@ class ModuleSerializer(BaseSerializer): def create(self, validated_data): members = validated_data.pop("members", None) - project = self.context["project"] - - module = Module.objects.create(**validated_data, project=project) + project_id = self.context["project_id"] + workspace_id = self.context["workspace_id"] + module = Module.objects.create(**validated_data, project_id=project_id) if members is not None: ModuleMember.objects.bulk_create( [ ModuleMember( module=module, - member=member, - project=project, - workspace=project.workspace, + member_id=str(member), + project_id=project_id, + workspace_id=workspace_id, created_by=module.created_by, updated_by=module.updated_by, ) @@ -97,7 +97,7 @@ class ModuleSerializer(BaseSerializer): [ ModuleMember( module=instance, - member=member, + member_id=str(member), project=instance.project, workspace=instance.project.workspace, created_by=instance.created_by, diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index 41745010f..1ac8ddcff 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -221,11 +221,20 @@ class IssueAPIEndpoint(WebhookMixin, BaseAPIView): def patch(self, request, slug, project_id, pk=None): issue = Issue.objects.get(workspace__slug=slug, project_id=project_id, pk=pk) + project = Project.objects.get(pk=project_id) current_instance = json.dumps( IssueSerializer(issue).data, cls=DjangoJSONEncoder ) requested_data = json.dumps(self.request.data, cls=DjangoJSONEncoder) - serializer = IssueSerializer(issue, data=request.data, partial=True) + serializer = IssueSerializer( + issue, + data=request.data, + context={ + "project_id": project_id, + "workspace_id": project.workspace_id, + }, + partial=True, + ) if serializer.is_valid(): serializer.save() issue_activity.delay( diff --git a/apiserver/plane/api/views/module.py b/apiserver/plane/api/views/module.py index 221c7f31b..959b7ccc3 100644 --- a/apiserver/plane/api/views/module.py +++ b/apiserver/plane/api/views/module.py @@ -121,8 +121,8 @@ class ModuleAPIEndpoint(WebhookMixin, BaseAPIView): ) def post(self, request, slug, project_id): - project = Project.objects.get(workspace__slug=slug, pk=project_id) - serializer = ModuleSerializer(data=request.data, context={"project": project}) + project = Project.objects.get(pk=project_id, workspace__slug=slug) + serializer = ModuleSerializer(data=request.data, context={"project_id": project_id, "workspace_id": project.workspace_id}) if serializer.is_valid(): serializer.save() module = Module.objects.get(pk=serializer.data["id"]) @@ -132,7 +132,7 @@ class ModuleAPIEndpoint(WebhookMixin, BaseAPIView): def patch(self, request, slug, project_id, pk): module = Module.objects.get(pk=pk, project_id=project_id, workspace__slug=slug) - serializer = ModuleSerializer(module, data=request.data) + serializer = ModuleSerializer(module, data=request.data, context={"project_id": project_id}, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED)