diff --git a/label_studio/core/mixins.py b/label_studio/core/mixins.py index 920d5756d2bd..e90f6c773fbb 100644 --- a/label_studio/core/mixins.py +++ b/label_studio/core/mixins.py @@ -1,56 +1,10 @@ """This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license. """ -import json import logging -from django.shortcuts import redirect -from django.urls import reverse -from django.http import HttpResponseNotAllowed - - logger = logging.getLogger(__name__) -class APIViewVirtualRedirectMixin(object): - def post(self, request, *args, **kwargs): - red = self.request.POST.get('_redirect', '').lower() - method = self.request.POST.get('_method', '').lower() - - res = super(APIViewVirtualRedirectMixin, self).post(request, *args, **kwargs) - - if red == 'true': - if method == "delete" and hasattr(self, 'redirect_delete_route'): - return redirect(reverse(self.redirect_delete_route)) - elif hasattr(self, 'redirect_route_callback'): - return redirect(self.redirect_route_callback(**self.request.POST)) - elif hasattr(self, 'redirect_kwarg'): - return redirect(reverse(self.redirect_route, - kwargs={'pk': self.kwargs[self.redirect_kwarg]})) - else: - return redirect(reverse(self.redirect_route)) - else: - return res - - -class APIViewVirtualMethodMixin(object): - def post(self, request, *args, **kwargs): - method = self.request.POST.get('_method', '').lower() - - if method == 'put': - res = self.put(request, *args, **kwargs) - elif method == 'delete': - res = self.delete(request, *args, **kwargs) - elif method == 'patch': - res = self.patch(request, *args, **kwargs) - else: - if hasattr(super(APIViewVirtualMethodMixin, self), 'post'): - res = super(APIViewVirtualMethodMixin, self).post(request, *args, **kwargs) - else: - return HttpResponseNotAllowed(permitted_methods=[]) - - return res - - class DummyModelMixin(): def has_permission(self, user): return True diff --git a/label_studio/organizations/api.py b/label_studio/organizations/api.py index 6eaf9188821f..1ba6147f7ac2 100644 --- a/label_studio/organizations/api.py +++ b/label_studio/organizations/api.py @@ -12,7 +12,6 @@ from drf_yasg.utils import swagger_auto_schema from django.utils.decorators import method_decorator -from label_studio.core.mixins import APIViewVirtualRedirectMixin, APIViewVirtualMethodMixin from label_studio.core.permissions import all_permissions, ViewClassPermission from label_studio.core.utils.common import get_object_with_check_and_log @@ -94,9 +93,7 @@ def get(self, request, *args, **kwargs): operation_summary='Update organization settings', operation_description='Update the settings for a specific organization by ID.' )) -class OrganizationAPI(APIViewVirtualRedirectMixin, - APIViewVirtualMethodMixin, - generics.RetrieveUpdateAPIView): +class OrganizationAPI(generics.RetrieveUpdateAPIView): parser_classes = (JSONParser, FormParser, MultiPartParser) queryset = Organization.objects.all() diff --git a/label_studio/projects/api.py b/label_studio/projects/api.py index 081883dae214..4fe97f077c5c 100644 --- a/label_studio/projects/api.py +++ b/label_studio/projects/api.py @@ -34,7 +34,6 @@ from webhooks.utils import api_webhook, api_webhook_for_delete, emit_webhooks_for_instance from webhooks.models import WebhookAction -from core.mixins import APIViewVirtualRedirectMixin, APIViewVirtualMethodMixin from core.permissions import all_permissions, ViewClassPermission from core.utils.common import ( get_object_with_check_and_log, bool_from_request, paginator, paginator_help) @@ -165,9 +164,7 @@ def post(self, request, *args, **kwargs): operation_description='Update the project settings for a specific project.', request_body=ProjectSerializer )) -class ProjectAPI(APIViewVirtualRedirectMixin, - APIViewVirtualMethodMixin, - generics.RetrieveUpdateDestroyAPIView): +class ProjectAPI(generics.RetrieveUpdateDestroyAPIView): parser_classes = (JSONParser, FormParser, MultiPartParser) queryset = Project.objects.with_counts() @@ -215,11 +212,6 @@ def perform_destroy(self, instance): with DisableSignals(): instance.delete() - @swagger_auto_schema(auto_schema=None) - @api_webhook(WebhookAction.PROJECT_UPDATED) - def post(self, request, *args, **kwargs): - return super(ProjectAPI, self).post(request, *args, **kwargs) - @swagger_auto_schema(auto_schema=None) @api_webhook(WebhookAction.PROJECT_UPDATED) def put(self, request, *args, **kwargs): @@ -575,9 +567,7 @@ def get(self, *args, **kwargs): """.format(settings.HOSTNAME or 'https://localhost:8080') )) class TasksListAPI(generics.ListCreateAPIView, - generics.DestroyAPIView, - APIViewVirtualMethodMixin, - APIViewVirtualRedirectMixin): + generics.DestroyAPIView): parser_classes = (JSONParser, FormParser) queryset = Task.objects.all()