2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

factor out read_license_file

This commit is contained in:
Matthias Mair
2025-02-05 01:16:41 +01:00
parent 4768009f0c
commit 4d75f51df3

View File

@ -35,21 +35,7 @@ from .version import inventreeApiText
logger = structlog.get_logger('inventree') logger = structlog.get_logger('inventree')
class LicenseViewSerializer(serializers.Serializer): def read_license_file(path: Path) -> list:
"""Serializer for license information."""
backend = serializers.CharField(help_text='Backend licenses texts', read_only=True)
frontend = serializers.CharField(
help_text='Frontend licenses texts', read_only=True
)
class LicenseView(APIView):
"""Simple JSON endpoint for InvenTree license information."""
permission_classes = [permissions.IsAuthenticated]
def read_license_file(self, path: Path) -> list:
"""Extract license information from the provided file. """Extract license information from the provided file.
Arguments: Arguments:
@ -90,6 +76,21 @@ class LicenseView(APIView):
return output return output
class LicenseViewSerializer(serializers.Serializer):
"""Serializer for license information."""
backend = serializers.CharField(help_text='Backend licenses texts', read_only=True)
frontend = serializers.CharField(
help_text='Frontend licenses texts', read_only=True
)
class LicenseView(APIView):
"""Simple JSON endpoint for InvenTree license information."""
permission_classes = [permissions.IsAuthenticated]
@extend_schema(responses={200: OpenApiResponse(response=LicenseViewSerializer)}) @extend_schema(responses={200: OpenApiResponse(response=LicenseViewSerializer)})
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
"""Return information about the InvenTree server.""" """Return information about the InvenTree server."""
@ -98,8 +99,8 @@ class LicenseView(APIView):
'web/static/web/.vite/dependencies.json' 'web/static/web/.vite/dependencies.json'
) )
return JsonResponse({ return JsonResponse({
'backend': self.read_license_file(backend), 'backend': read_license_file(backend),
'frontend': self.read_license_file(frontend), 'frontend': read_license_file(frontend),
}) })