diff --git a/backend/library/views.py b/backend/library/views.py index dbde1a552..24e9073b4 100644 --- a/backend/library/views.py +++ b/backend/library/views.py @@ -31,9 +31,9 @@ from .serializers import LibrarySerializer, LibraryUploadSerializer from .utils import get_available_libraries, get_library, import_library_view - class LibraryViewSet(BaseModelViewSet): serializer_class = LibrarySerializer + parser_classes = [FileUploadParser] # solve issue with URN containing dot, see https://stackoverflow.com/questions/27963899/django-rest-framework-using-dot-in-url lookup_value_regex = r"[\w.:-]+" @@ -127,15 +127,11 @@ def import_library(self, request, pk=None): status=HTTP_422_UNPROCESSABLE_ENTITY, ) - -class UploadLibraryView(APIView): - parser_classes = (FileUploadParser,) - serializer_class = LibraryUploadSerializer - - def post(self, request): + @action(detail=False, methods=["post"], url_path="upload") + def upload_library(self, request): if not request.data: return HttpResponse( - json.dumps({"error": "No file detected !"}), status=HTTP_400_BAD_REQUEST + json.dumps({"error": "noFileDetected"}), status=HTTP_400_BAD_REQUEST ) try: diff --git a/frontend/messages/en.json b/frontend/messages/en.json index e264e6d85..b96e78e0b 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -441,5 +441,6 @@ "notApplicable": "Not applicable", "administrator": "Administrator", "domainManager": "Domain manager", - "analyst": "Analyst" + "analyst": "Analyst", + "noFileDetected": "Error: no file detected" } diff --git a/frontend/messages/fr.json b/frontend/messages/fr.json index 1e72c8f56..28c78dd2f 100644 --- a/frontend/messages/fr.json +++ b/frontend/messages/fr.json @@ -441,5 +441,6 @@ "notApplicable": "Non applicable", "administrator": "Administrateur", "domainManager": "Gestionnaire de domaine", - "analyst": "Analyste" + "analyst": "Analyste", + "noFileDetected": "Erreur: aucun fichier détecté" } diff --git a/frontend/src/lib/utils/locales.ts b/frontend/src/lib/utils/locales.ts index f41f94bfa..d0d26d357 100644 --- a/frontend/src/lib/utils/locales.ts +++ b/frontend/src/lib/utils/locales.ts @@ -290,6 +290,7 @@ export function localItems(languageTag: string): LocalItems { analyst: m.analyst({ languageTag: languageTag }), auditor: m.auditor({ languageTag: languageTag }), domainManager: m.domainManager({ languageTag: languageTag }), + noFileDetected: m.noFileDetected({ languageTag: languageTag }), }; return LOCAL_ITEMS; diff --git a/frontend/src/lib/utils/schemas.ts b/frontend/src/lib/utils/schemas.ts index b6ef79183..d7285e6f6 100644 --- a/frontend/src/lib/utils/schemas.ts +++ b/frontend/src/lib/utils/schemas.ts @@ -54,7 +54,7 @@ export const RiskMatrixSchema = baseNamedObject({ }); export const LibraryUploadSchema = z.object({ - file: z.string() + file: z.string().optional() }); export const RiskAssessmentSchema = baseNamedObject({ diff --git a/frontend/src/routes/(app)/libraries/+page.server.ts b/frontend/src/routes/(app)/libraries/+page.server.ts index 00c50f462..2a4318955 100644 --- a/frontend/src/routes/(app)/libraries/+page.server.ts +++ b/frontend/src/routes/(app)/libraries/+page.server.ts @@ -10,6 +10,8 @@ import { z } from 'zod'; import { tableSourceMapper } from '@skeletonlabs/skeleton'; import { listViewFields } from '$lib/utils/table'; import type { Library, urlModel } from '$lib/utils/types'; +import { localItems } from '$lib/utils/locales'; +import { languageTag } from '$paraglide/runtime'; export const load = (async ({ fetch }) => { const endpoint = `${BASE_API_URL}/libraries/`; @@ -94,7 +96,7 @@ export const actions: Actions = { if (!req.ok) { const response = await req.json(); console.error(response); - setFlash({ type: 'error', message: `Error: ${response.error}` }, event); + setFlash({ type: 'error', message: localItems(languageTag())[response.error] }, event); return fail(400, { form }); } setFlash({ type: 'success', message: 'Library successfully imported !' }, event); diff --git a/frontend/src/routes/(app)/libraries/+page.svelte b/frontend/src/routes/(app)/libraries/+page.svelte index 136199ae2..aea6c9e39 100644 --- a/frontend/src/routes/(app)/libraries/+page.svelte +++ b/frontend/src/routes/(app)/libraries/+page.svelte @@ -72,7 +72,7 @@ {m.upload()} {:catch err}