Skip to content

Commit

Permalink
OM-244 Added missing insuree rights migration
Browse files Browse the repository at this point in the history
  • Loading branch information
malinowskikam committed Aug 27, 2024
1 parent ef6848f commit 994c906
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
34 changes: 34 additions & 0 deletions msystems/migrations/0008_add_insuree_rights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.db import migrations

rolerights = {
'Employer': ['101101', '101102', '101104'],
'Inspector': ['101101']
}


def add_rights(role_name, role_model, role_right_model):
role = role_model.objects.get(name=role_name)
for right_id in rolerights[role_name]:
if not role_right_model.objects.filter(validity_to__isnull=True, role=role, right_id=right_id).exists():
_add_right_for_role(role, right_id, role_right_model)


def _add_right_for_role(role, right_id, role_right_model):
role_right_model.objects.create(role=role, right_id=right_id, audit_user_id=1)


def on_migration(apps, schema_editor):
role_model = apps.get_model("core", "role")
role_right_model = apps.get_model("core", "roleright")
for role in rolerights:
add_rights(role, role_model, role_right_model)


class Migration(migrations.Migration):
dependencies = [
('msystems', '0007_add_languages'),
]

operations = [
migrations.RunPython(on_migration, migrations.RunPython.noop),
]
2 changes: 1 addition & 1 deletion msystems/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from msystems.tests.saml_user_service_tests import SamlUserServiceTestCase
from msystems.tests.mpass_user_service_tests import MpassUserServiceTestCase
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from location.models import Location
from msystems.apps import MsystemsConfig

from msystems.services.saml_user_service import SamlUserService
from msystems.services.mpass_user_service import MpassUserService
from msystems.tests.data import example_username, example_user_data, example_user_data_multiple_ph
from core.models import User, InteractiveUser, UserRole, Role
from policyholder.models import PolicyHolder


class SamlUserServiceTestCase(TestCase):
class MpassUserServiceTestCase(TestCase):
service = None

@classmethod
def setUpClass(cls):
super(SamlUserServiceTestCase, cls).setUpClass()
cls.service = SamlUserService()
super(MpassUserServiceTestCase, cls).setUpClass()
cls.service = MpassUserService()

def test_login(self):
self.assertFalse(User.objects.filter(
Expand Down

0 comments on commit 994c906

Please sign in to comment.