diff --git a/bemade_sports_clinic/migrations/16.0.1.7.0/post-migrate.py b/bemade_sports_clinic/migrations/16.0.1.7.0/post-migrate.py index f96358f..140cc3d 100644 --- a/bemade_sports_clinic/migrations/16.0.1.7.0/post-migrate.py +++ b/bemade_sports_clinic/migrations/16.0.1.7.0/post-migrate.py @@ -2,5 +2,22 @@ access. Everything is calculated from there. Inverse functions deal with sports.team.staff records instead of having a separate table for storing access rights.""" + +from odoo import api, SUPERUSER_ID, Command + + def migrate(cr, version): - cr.execute("DROP TABLE sports_team_res_users_rel") \ No newline at end of file + env = api.Environment(cr, SUPERUSER_ID, {}) + rules = ( + env.ref("bemade_sports_clinic.restrict_staff_access_to_teams") + + env.ref("bemade_sports_clinic.restrict_staff_access_to_team_injuries") + + env.ref("bemade_sports_clinic.restrict_staff_access_to_team_players") + ) + rules.write({ + "groups": [Command.link(env.ref("base.group_user").id)] + }) + env.ref("bemade_sports_clinic.group_sports_clinic_user").write({ + "implied_ids": [Command.link(env.ref("base.group_partner_manager").id)] + }) + cr.execute("DROP TABLE sports_team_res_users_rel") + # Check the groups are OK diff --git a/bemade_sports_clinic/security/sports_clinic_groups.xml b/bemade_sports_clinic/security/sports_clinic_groups.xml index 13a58f2..455b2fe 100644 --- a/bemade_sports_clinic/security/sports_clinic_groups.xml +++ b/bemade_sports_clinic/security/sports_clinic_groups.xml @@ -1,12 +1,20 @@ - + Sports Medicine Clinic Management Internal User + Treatment Professional diff --git a/bemade_sports_clinic/tests/test_patient.py b/bemade_sports_clinic/tests/test_patient.py index 8d012cb..ece8524 100644 --- a/bemade_sports_clinic/tests/test_patient.py +++ b/bemade_sports_clinic/tests/test_patient.py @@ -3,6 +3,7 @@ from odoo import fields, Command from datetime import timedelta + @tagged("-at_install", "post_install") class TestPatient(TransactionCase): @classmethod diff --git a/bemade_sports_clinic/tests/test_rights.py b/bemade_sports_clinic/tests/test_rights.py index b3e306a..13207c8 100644 --- a/bemade_sports_clinic/tests/test_rights.py +++ b/bemade_sports_clinic/tests/test_rights.py @@ -1,9 +1,14 @@ -from odoo.tests import TransactionCase, Form +from odoo.tests import TransactionCase, Form, tagged from odoo.fields import Date from datetime import timedelta from odoo.exceptions import AccessError +from odoo import Command +import logging + +_logger = logging.getLogger(__name__) +@tagged("-at_install", "post_install") class TestRights(TransactionCase): @classmethod def setUpClass(cls): @@ -12,18 +17,14 @@ class TestRights(TransactionCase): cls.admin_user = cls.env["res.users"].create( { "name": "Admin User", - "login": "admin", - "password": "admin", + "login": "sports_admin", + "password": "sports_admin", "groups_id": [ - ( - 6, - 0, - [ - cls.env.ref( - "bemade_sports_clinic.group_sports_clinic_admin" - ), - ], - ) + Command.set( + cls.env.ref( + "bemade_sports_clinic.group_sports_clinic_admin" + ).id, + ), ], } ) @@ -34,18 +35,17 @@ class TestRights(TransactionCase): "login": "treatment_professional", "password": "treatment_professional", "groups_id": [ - ( - 6, - 0, - [ - cls.env.ref( - "bemade_sports_clinic.group_sports_clinic_treatment_professional" - ).id - ], - ) + Command.set( + cls.env.ref( + "bemade_sports_clinic.group_sports_clinic_treatment_professional" + ).id, + ), ], } ) + _logger.info( + f"Treatment Pro Groups: {cls.treatment_professional_user.groups_id.name}" + ) def test_treatment_pro_has_access_only_to_staffed_teams(self): """A treatment professional should only have access to teams and, @@ -61,16 +61,18 @@ class TestRights(TransactionCase): Form( self.env["sports.patient"] .with_user(self.treatment_professional_user) - .browse(patients.ids) + .browse(patients[0].id) ) def test_treatment_pro_can_remove_patient_from_team(self): team, patients = self._generate_team_with_patient(self.admin_user) - self.env['sports.team.staff'].create({ - "team_id": team.id, - "partner_id": self.treatment_professional_user.id, - "role": "head_therapist", - }) + self.env["sports.team.staff"].with_user(self.admin_user).create( + { + "team_id": team.id, + "partner_id": self.treatment_professional_user.partner_id.id, + "role": "head_therapist", + } + ) # Test removing the patient since we are team staff # Should not throw an error... with Form(team.with_user(self.treatment_professional_user)) as team: @@ -81,7 +83,7 @@ class TestRights(TransactionCase): user = user or self.env.user team = ( self.env["sports.team"] - .with_user(self.user) + .with_user(user) .create( { "name": "Test Team", @@ -90,22 +92,22 @@ class TestRights(TransactionCase): ) patients = ( self.env["sports.patient"] - .with_user(self.user) + .with_user(user) .create( [ { "first_name": "Test", "last_name": "Patient One", "date_of_birth": Date.today() - timedelta(days=-365 * 18), - "team_ids": [6, 0, team.ids], + "team_ids": [(6, 0, team.ids)], }, { "first_name": "Test", "last_name": "Patient Two", "date_of_birth": Date.today() - timedelta(days=-365 * 18), - "team_ids": [6, 0, team.ids], + "team_ids": [(6, 0, team.ids)], }, ] ) ) - return team, patients \ No newline at end of file + return team, patients