forked from github/plane
feat: delete imported data as well when the import is deleted (#974)
This commit is contained in:
parent
b2ad071608
commit
88200a93bf
@ -28,6 +28,7 @@ from plane.db.models import (
|
|||||||
Module,
|
Module,
|
||||||
ModuleLink,
|
ModuleLink,
|
||||||
ModuleIssue,
|
ModuleIssue,
|
||||||
|
Label,
|
||||||
)
|
)
|
||||||
from plane.api.serializers import (
|
from plane.api.serializers import (
|
||||||
ImporterSerializer,
|
ImporterSerializer,
|
||||||
@ -235,9 +236,20 @@ class ImportServiceEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
def delete(self, request, slug, service, pk):
|
def delete(self, request, slug, service, pk):
|
||||||
try:
|
try:
|
||||||
importer = Importer.objects.filter(
|
importer = Importer.objects.get(
|
||||||
pk=pk, service=service, workspace__slug=slug
|
pk=pk, service=service, workspace__slug=slug
|
||||||
)
|
)
|
||||||
|
# Delete all imported Issues
|
||||||
|
imported_issues = importer.imported_data.get("issues", [])
|
||||||
|
Issue.objects.filter(id__in=imported_issues).delete()
|
||||||
|
|
||||||
|
# Delete all imported Labels
|
||||||
|
imported_labels = importer.imported_data.get("labels", [])
|
||||||
|
Label.objects.filter(id__in=imported_labels).delete()
|
||||||
|
|
||||||
|
if importer.service == "jira":
|
||||||
|
imported_modules = importer.imported_data.get("modules", [])
|
||||||
|
Module.objects.filter(id__in=imported_modules).delete()
|
||||||
importer.delete()
|
importer.delete()
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -247,6 +259,27 @@ class ImportServiceEndpoint(BaseAPIView):
|
|||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def patch(self, request, slug, service, pk):
|
||||||
|
try:
|
||||||
|
importer = Importer.objects.get(
|
||||||
|
pk=pk, service=service, workspace__slug=slug
|
||||||
|
)
|
||||||
|
serializer = ImporterSerializer(importer, data=request.data, partial=True)
|
||||||
|
if serializer.is_valid():
|
||||||
|
serializer.save()
|
||||||
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
except Importer.DoesNotExist:
|
||||||
|
return Response(
|
||||||
|
{"error": "Importer Does not exists"}, status=status.HTTP_404_NOT_FOUND
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response(
|
||||||
|
{"error": "Something went wrong please try again later"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UpdateServiceImportStatusEndpoint(BaseAPIView):
|
class UpdateServiceImportStatusEndpoint(BaseAPIView):
|
||||||
def post(self, request, slug, project_id, service, importer_id):
|
def post(self, request, slug, project_id, service, importer_id):
|
||||||
|
@ -33,6 +33,7 @@ class Importer(ProjectBaseModel):
|
|||||||
token = models.ForeignKey(
|
token = models.ForeignKey(
|
||||||
"db.APIToken", on_delete=models.CASCADE, related_name="importer"
|
"db.APIToken", on_delete=models.CASCADE, related_name="importer"
|
||||||
)
|
)
|
||||||
|
imported_data = models.JSONField(null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Importer"
|
verbose_name = "Importer"
|
||||||
|
Loading…
Reference in New Issue
Block a user