Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded AjaxView usage #8461

Merged
merged 7 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/extract_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def top_level_path(path: str) -> str:

path = path.strip()

key = path.split('/')[1]
parts = path.split('/')
key = parts[1] if len(parts) > 1 else parts[0]

if key in SPECIAL_PATHS:
return key
Expand Down
46 changes: 42 additions & 4 deletions src/backend/InvenTree/InvenTree/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from .mixins import ListAPI, RetrieveUpdateAPI
from .status import check_system_health, is_worker_running
from .version import inventreeApiText
from .views import AjaxView

logger = logging.getLogger('inventree')

Expand Down Expand Up @@ -196,8 +195,35 @@ def list(self, request, *args, **kwargs):
return JsonResponse(inventreeApiText())


class InfoView(AjaxView):
"""Simple JSON endpoint for InvenTree information.
class InfoApiSerializer(serializers.Serializer):
"""InvenTree server information - some information might be blanked if called without elevated credentials."""

server = serializers.CharField(read_only=True)
version = serializers.CharField(read_only=True)
instance = serializers.CharField(read_only=True)
apiVersion = serializers.IntegerField(read_only=True) # noqa: N815
worker_running = serializers.BooleanField(read_only=True)
worker_count = serializers.IntegerField(read_only=True)
worker_pending_tasks = serializers.IntegerField(read_only=True)
plugins_enabled = serializers.BooleanField(read_only=True)
plugins_install_disabled = serializers.BooleanField(read_only=True)
active_plugins = serializers.JSONField(read_only=True)
email_configured = serializers.BooleanField(read_only=True)
debug_mode = serializers.BooleanField(read_only=True)
docker_mode = serializers.BooleanField(read_only=True)
default_locale = serializers.ChoiceField(
choices=settings.LOCALE_CODES, read_only=True
)
system_health = serializers.BooleanField(read_only=True)
database = serializers.CharField(read_only=True)
platform = serializers.CharField(read_only=True)
installer = serializers.CharField(read_only=True)
target = serializers.CharField(read_only=True)
django_admin = serializers.CharField(read_only=True)


class InfoView(APIView):
"""JSON endpoint for InvenTree server information.

Use to confirm that the server is running, etc.
"""
Expand All @@ -208,6 +234,13 @@ def worker_pending_tasks(self):
"""Return the current number of outstanding background tasks."""
return OrmQ.objects.count()

@extend_schema(
responses={
200: OpenApiResponse(
response=InfoApiSerializer, description='InvenTree server information'
)
}
)
def get(self, request, *args, **kwargs):
"""Serve current server information."""
is_staff = request.user.is_staff
Expand Down Expand Up @@ -261,7 +294,7 @@ def check_auth_header(self, request):
return False


class NotFoundView(AjaxView):
class NotFoundView(APIView):
"""Simple JSON view when accessing an invalid API view."""

permission_classes = [permissions.AllowAny]
Expand All @@ -280,22 +313,27 @@ def options(self, request, *args, **kwargs):
"""Return 404."""
return self.not_found(request)

@extend_schema(exclude=True)
def get(self, request, *args, **kwargs):
"""Return 404."""
return self.not_found(request)

@extend_schema(exclude=True)
def post(self, request, *args, **kwargs):
"""Return 404."""
return self.not_found(request)

@extend_schema(exclude=True)
def patch(self, request, *args, **kwargs):
"""Return 404."""
return self.not_found(request)

@extend_schema(exclude=True)
def put(self, request, *args, **kwargs):
"""Return 404."""
return self.not_found(request)

@extend_schema(exclude=True)
def delete(self, request, *args, **kwargs):
"""Return 404."""
return self.not_found(request)
Expand Down
6 changes: 5 additions & 1 deletion src/backend/InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""InvenTree API version information."""

# InvenTree API version
INVENTREE_API_VERSION = 279
INVENTREE_API_VERSION = 280

"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""


INVENTREE_API_TEXT = """

v280 - 2024-11-10 : https://github.com/inventree/InvenTree/pull/8461
- Makes schema for API information endpoint more informing
- Removes general not found endpoint

v279 - 2024-11-09 : https://github.com/inventree/InvenTree/pull/8458
- Adds "order_outstanding" and "part" filters to the BuildLine API endpoint
- Adds "order_outstanding" filter to the SalesOrderLineItem API endpoint
Expand Down
Loading