diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po new file mode 100644 index 0000000..0d330f1 --- /dev/null +++ b/locale/en/LC_MESSAGES/django.po @@ -0,0 +1,20 @@ +msgid "resident_national_id_not_valid" +msgstr "Worker national id not valid." + +msgid "organization_national_id_not_valid" +msgstr "Organization national id not valid." + +msgid "vehicle_national_id_not_valid" +msgstr "Vehicle national id not valid." + +msgid "resident_national_id_checksum_not_valid" +msgstr "Worker national id checksum not valid." + +msgid "organization_national_id_checksum_not_valid" +msgstr "Organization national id checksum not valid." + +msgid "vehicle_national_id_checksum_not_valid" +msgstr "Vehicle national id checksum not valid." + +msgid "role_validation.unknown_role" +msgstr "Unknown role coming from mPass." \ No newline at end of file diff --git a/msystems/apps.py b/msystems/apps.py index f7cf183..e4f9eb8 100644 --- a/msystems/apps.py +++ b/msystems/apps.py @@ -98,6 +98,7 @@ class MsystemsConfig(AppConfig): ADMIN = 'Admin' INSPECTOR = 'Inspector' EMPLOYER = 'Employer' + IMIS_ADMIN = 'IMIS Administrator' ##### ------------------ #### saml_config = None diff --git a/msystems/services.py b/msystems/services.py index e931bd6..7487f3d 100644 --- a/msystems/services.py +++ b/msystems/services.py @@ -6,6 +6,8 @@ from django.db import transaction from django.db.models import Q from secrets import token_hex +from django.core.exceptions import ValidationError +from django.utils.translation import gettext as _ from core.models import User, InteractiveUser, Role, UserRole from core.services.userServices import create_or_update_user_districts @@ -84,6 +86,9 @@ def _update_user_legal_entities(self, user: User, user_data: dict) -> None: def _update_user_roles(self, user, user_data): msystem_roles_list = user_data.get('Role', [MsystemsConfig.EMPLOYER]) + for role in msystem_roles_list: + self._validate_incoming_roles(role) + self._delete_old_user_roles(user, msystem_roles_list) self._add_new_user_roles(user, msystem_roles_list) @@ -158,4 +163,11 @@ def _remove_previous_user_roles(self, i_user): role.delete_history() def _parse_msystem_role_to_imis_role(self, msystem_role): - return Role.objects.filter(name=msystem_role).first() + role_string = msystem_role + if msystem_role == MsystemsConfig.ADMIN: + role_string = MsystemsConfig.IMIS_ADMIN + return Role.objects.filter(name=role_string).first() + + def _validate_incoming_roles(self, role): + if role not in [MsystemsConfig.ADMIN, MsystemsConfig.EMPLOYER, MsystemsConfig.INSPECTOR]: + raise ValidationError(_("role_validation.unknown_role"))