Skip to content

Commit

Permalink
OM-47: add validation and translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Oct 31, 2023
1 parent 66dd83e commit df0e5c1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion msystems/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')

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)

Expand Down Expand Up @@ -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"))

0 comments on commit df0e5c1

Please sign in to comment.