Skip to content

Commit

Permalink
Return 404 on API requests other than GET (#5365) (#5366)
Browse files Browse the repository at this point in the history
- Other request methods need love too!

(cherry picked from commit 59ffdca)
(cherry picked from commit b89a120)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
  • Loading branch information
github-actions[bot] and SchrodingersGat committed Jul 28, 2023
1 parent 73768bf commit 385e7cb
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions InvenTree/InvenTree/api.py
Expand Up @@ -59,14 +59,39 @@ class NotFoundView(AjaxView):

permission_classes = [permissions.AllowAny]

def not_found(self, request):
"""Return a 404 error"""
return JsonResponse(
{
'detail': _('API endpoint not found'),
'url': request.build_absolute_uri(),
},
status=404
)

def options(self, request, *args, **kwargs):
"""Return 404"""
return self.not_found(request)

def get(self, request, *args, **kwargs):
"""Process an `not found` event on the API."""
data = {
'details': _('API endpoint not found'),
'url': request.build_absolute_uri(),
}
"""Return 404"""
return self.not_found(request)

def post(self, request, *args, **kwargs):
"""Return 404"""
return self.not_found(request)

return JsonResponse(data, status=404)
def patch(self, request, *args, **kwargs):
"""Return 404"""
return self.not_found(request)

def put(self, request, *args, **kwargs):
"""Return 404"""
return self.not_found(request)

def delete(self, request, *args, **kwargs):
"""Return 404"""
return self.not_found(request)


class BulkDeleteMixin:
Expand Down

0 comments on commit 385e7cb

Please sign in to comment.