Skip to content

Commit

Permalink
Add translations to single-admin account deletion attempt error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed Apr 3, 2024
1 parent 27034e5 commit 8051e52
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
4 changes: 3 additions & 1 deletion frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
4 changes: 3 additions & 1 deletion frontend/src/lib/utils/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion frontend/src/routes/(app)/[model=urlmodel]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8051e52

Please sign in to comment.