diff --git a/backend/core/views.py b/backend/core/views.py index 0e781ea0b..2fcffb3fa 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -843,7 +843,7 @@ def update(self, request: Request, *args, **kwargs) -> Response: if number_of_admin_users == 1 : new_user_groups = set(request.data["user_groups"]) if str(admin_group.pk) not in new_user_groups : - return Response({"error":"You can't remove the admin user group from the only admin user of the application."},status=HTTP_403_FORBIDDEN) + return Response({"error":"attemptToRemoveOnlyAdminUserGroup"},status=HTTP_403_FORBIDDEN) return super().update(request, *args, **kwargs) @@ -852,7 +852,7 @@ def destroy(self, request, *args, **kwargs): if user.is_admin() : number_of_admin_users = User.get_admin_users().count() if number_of_admin_users == 1 : - return Response({"error":"You can't delete the only admin account of your application."},status=HTTP_403_FORBIDDEN) + return Response({"error":"attemptToDeleteOnlyAdminAccountError"},status=HTTP_403_FORBIDDEN) return super().destroy(request,*args,**kwargs) diff --git a/frontend/messages/en.json b/frontend/messages/en.json index 9ee365bf1..8e1cb7b6b 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -491,5 +491,7 @@ "libraryAlreadyImportedError": "This library has already been imported.", "invalidLibraryFileError": "Invalid library file. Please make sure the format is correct.", "taintedFormMessage": "Do you want to leave this page? Changes you made may not be saved.", - "riskScenariosStatus": "Risk scenarios status" + "riskScenariosStatus": "Risk scenarios status", + "attemptToDeleteOnlyAdminAccountError": "You can't delete the only admin account of your application.", + "attemptToRemoveOnlyAdminUserGroup": "You can't remove the only admin user of the application from the admin user group." } diff --git a/frontend/messages/fr.json b/frontend/messages/fr.json index 030a726db..775e010a0 100644 --- a/frontend/messages/fr.json +++ b/frontend/messages/fr.json @@ -491,5 +491,7 @@ "libraryAlreadyImportedError": "Cette libairie a été déjà été importée.", "invalidLibraryFileError": "Fichier de bibliothèque invalide. Veuillez vérifier le format du fichier.", "taintedFormMessage": "Voulez-vous vraiment quitter cette page ? Toutes les données non enregistrées seront perdues.", - "riskScenariosStatus": "Statut des scénarios de risque" + "riskScenariosStatus": "Statut des scénarios de risque", + "attemptToDeleteOnlyAdminAccountError": "Vous ne pouvez pas supprimer votre unique compte administrateur de l'application.", + "attemptToRemoveOnlyAdminUserGroup": "Vous ne pouvez pas retirer le seul compte administrateur de l'application du groupe des administrateurs." } diff --git a/frontend/src/lib/utils/locales.ts b/frontend/src/lib/utils/locales.ts index 44e8e03c5..86724080d 100644 --- a/frontend/src/lib/utils/locales.ts +++ b/frontend/src/lib/utils/locales.ts @@ -309,7 +309,9 @@ export function localItems(languageTag: string): LocalItems { highSOK: m.highSOK({ languageTag: languageTag }), libraryImportError: m.libraryImportError({ languageTag: languageTag }), libraryAlreadyExistsError: m.libraryAlreadyImportedError({ languageTag: languageTag }), - invalidLibraryFileError: m.invalidLibraryFileError({ languageTag: languageTag }) + invalidLibraryFileError: m.invalidLibraryFileError({ languageTag: languageTag }), + attemptToDeleteOnlyAdminAccountError: m.attemptToDeleteOnlyAdminAccountError({ languageTag: languageTag }), + attemptToRemoveOnlyAdminUserGroup: m.attemptToRemoveOnlyAdminUserGroup({ languageTag: languageTag }) }; return LOCAL_ITEMS; } diff --git a/frontend/src/routes/(app)/[model=urlmodel]/+page.server.ts b/frontend/src/routes/(app)/[model=urlmodel]/+page.server.ts index 5d5c227ab..e3d947766 100644 --- a/frontend/src/routes/(app)/[model=urlmodel]/+page.server.ts +++ b/frontend/src/routes/(app)/[model=urlmodel]/+page.server.ts @@ -156,7 +156,7 @@ export const actions: Actions = { const response = await res.json(); console.log(response); if (response.error) { - setFlash({ type: 'error', message: response.error }, event); + setFlash({ type: 'error', message: localItems(languageTag())[response.error] }, event); return fail(403, { form: deleteForm }); } if (response.non_field_errors) { diff --git a/frontend/src/routes/(app)/users/[id=uuid]/edit/+page.server.ts b/frontend/src/routes/(app)/users/[id=uuid]/edit/+page.server.ts index efd879bc2..3578753eb 100644 --- a/frontend/src/routes/(app)/users/[id=uuid]/edit/+page.server.ts +++ b/frontend/src/routes/(app)/users/[id=uuid]/edit/+page.server.ts @@ -6,6 +6,8 @@ import { redirect, fail, type Actions } from '@sveltejs/kit'; import { getModelInfo } from '$lib/utils/crud'; import { setFlash } from 'sveltekit-flash-message/server'; import * as m from '$paraglide/messages'; +import { languageTag } from '$paraglide/runtime'; +import { localItems } from '$lib/utils/locales'; export const load: PageServerLoad = async ({ params, fetch }) => { const URLModel = 'users'; @@ -58,7 +60,7 @@ export const actions: Actions = { const response = await res.json(); console.error('server response:', response); if (response.error) { - setFlash({ type: 'error', message: response.error }, event); + setFlash({ type: 'error', message: localItems(languageTag())[response.error] }, event); return fail(403, { form: form }); } if (response.non_field_errors) {