fix tests, security and post-migration
This commit is contained in:
parent
1ab1d00cab
commit
75ed4642c6
4 changed files with 62 additions and 34 deletions
|
|
@ -2,5 +2,22 @@
|
||||||
access. Everything is calculated from there. Inverse functions deal with
|
access. Everything is calculated from there. Inverse functions deal with
|
||||||
sports.team.staff records instead of having a separate table for storing
|
sports.team.staff records instead of having a separate table for storing
|
||||||
access rights."""
|
access rights."""
|
||||||
|
|
||||||
|
from odoo import api, SUPERUSER_ID, Command
|
||||||
|
|
||||||
|
|
||||||
def migrate(cr, version):
|
def migrate(cr, version):
|
||||||
cr.execute("DROP TABLE sports_team_res_users_rel")
|
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
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,20 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<data noupdate="1">
|
<data>
|
||||||
<record id="module_category_sports_clinic_management" model="ir.module.category">
|
<record id="module_category_sports_clinic_management" model="ir.module.category">
|
||||||
<field name="name">Sports Medicine Clinic Management</field>
|
<field name="name">Sports Medicine Clinic Management</field>
|
||||||
</record>
|
</record>
|
||||||
<record id="group_sports_clinic_user" model="res.groups">
|
<record id="group_sports_clinic_user" model="res.groups">
|
||||||
<field name="name">Internal User</field>
|
<field name="name">Internal User</field>
|
||||||
<field name="category_id" ref="module_category_sports_clinic_management"/>
|
<field name="category_id" ref="module_category_sports_clinic_management"/>
|
||||||
|
<field name="implied_ids" eval="[
|
||||||
|
Command.set(
|
||||||
|
[
|
||||||
|
ref('base.group_user'),
|
||||||
|
ref('base.group_partner_manager'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]"/>
|
||||||
</record>
|
</record>
|
||||||
<record id="group_sports_clinic_treatment_professional" model="res.groups">
|
<record id="group_sports_clinic_treatment_professional" model="res.groups">
|
||||||
<field name="name">Treatment Professional</field>
|
<field name="name">Treatment Professional</field>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from odoo import fields, Command
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@tagged("-at_install", "post_install")
|
@tagged("-at_install", "post_install")
|
||||||
class TestPatient(TransactionCase):
|
class TestPatient(TransactionCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
from odoo.tests import TransactionCase, Form
|
from odoo.tests import TransactionCase, Form, tagged
|
||||||
from odoo.fields import Date
|
from odoo.fields import Date
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from odoo.exceptions import AccessError
|
from odoo.exceptions import AccessError
|
||||||
|
from odoo import Command
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@tagged("-at_install", "post_install")
|
||||||
class TestRights(TransactionCase):
|
class TestRights(TransactionCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
|
@ -12,18 +17,14 @@ class TestRights(TransactionCase):
|
||||||
cls.admin_user = cls.env["res.users"].create(
|
cls.admin_user = cls.env["res.users"].create(
|
||||||
{
|
{
|
||||||
"name": "Admin User",
|
"name": "Admin User",
|
||||||
"login": "admin",
|
"login": "sports_admin",
|
||||||
"password": "admin",
|
"password": "sports_admin",
|
||||||
"groups_id": [
|
"groups_id": [
|
||||||
(
|
Command.set(
|
||||||
6,
|
cls.env.ref(
|
||||||
0,
|
"bemade_sports_clinic.group_sports_clinic_admin"
|
||||||
[
|
).id,
|
||||||
cls.env.ref(
|
),
|
||||||
"bemade_sports_clinic.group_sports_clinic_admin"
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -34,18 +35,17 @@ class TestRights(TransactionCase):
|
||||||
"login": "treatment_professional",
|
"login": "treatment_professional",
|
||||||
"password": "treatment_professional",
|
"password": "treatment_professional",
|
||||||
"groups_id": [
|
"groups_id": [
|
||||||
(
|
Command.set(
|
||||||
6,
|
cls.env.ref(
|
||||||
0,
|
"bemade_sports_clinic.group_sports_clinic_treatment_professional"
|
||||||
[
|
).id,
|
||||||
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):
|
def test_treatment_pro_has_access_only_to_staffed_teams(self):
|
||||||
"""A treatment professional should only have access to teams and,
|
"""A treatment professional should only have access to teams and,
|
||||||
|
|
@ -61,16 +61,18 @@ class TestRights(TransactionCase):
|
||||||
Form(
|
Form(
|
||||||
self.env["sports.patient"]
|
self.env["sports.patient"]
|
||||||
.with_user(self.treatment_professional_user)
|
.with_user(self.treatment_professional_user)
|
||||||
.browse(patients.ids)
|
.browse(patients[0].id)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_treatment_pro_can_remove_patient_from_team(self):
|
def test_treatment_pro_can_remove_patient_from_team(self):
|
||||||
team, patients = self._generate_team_with_patient(self.admin_user)
|
team, patients = self._generate_team_with_patient(self.admin_user)
|
||||||
self.env['sports.team.staff'].create({
|
self.env["sports.team.staff"].with_user(self.admin_user).create(
|
||||||
"team_id": team.id,
|
{
|
||||||
"partner_id": self.treatment_professional_user.id,
|
"team_id": team.id,
|
||||||
"role": "head_therapist",
|
"partner_id": self.treatment_professional_user.partner_id.id,
|
||||||
})
|
"role": "head_therapist",
|
||||||
|
}
|
||||||
|
)
|
||||||
# Test removing the patient since we are team staff
|
# Test removing the patient since we are team staff
|
||||||
# Should not throw an error...
|
# Should not throw an error...
|
||||||
with Form(team.with_user(self.treatment_professional_user)) as team:
|
with Form(team.with_user(self.treatment_professional_user)) as team:
|
||||||
|
|
@ -81,7 +83,7 @@ class TestRights(TransactionCase):
|
||||||
user = user or self.env.user
|
user = user or self.env.user
|
||||||
team = (
|
team = (
|
||||||
self.env["sports.team"]
|
self.env["sports.team"]
|
||||||
.with_user(self.user)
|
.with_user(user)
|
||||||
.create(
|
.create(
|
||||||
{
|
{
|
||||||
"name": "Test Team",
|
"name": "Test Team",
|
||||||
|
|
@ -90,22 +92,22 @@ class TestRights(TransactionCase):
|
||||||
)
|
)
|
||||||
patients = (
|
patients = (
|
||||||
self.env["sports.patient"]
|
self.env["sports.patient"]
|
||||||
.with_user(self.user)
|
.with_user(user)
|
||||||
.create(
|
.create(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"first_name": "Test",
|
"first_name": "Test",
|
||||||
"last_name": "Patient One",
|
"last_name": "Patient One",
|
||||||
"date_of_birth": Date.today() - timedelta(days=-365 * 18),
|
"date_of_birth": Date.today() - timedelta(days=-365 * 18),
|
||||||
"team_ids": [6, 0, team.ids],
|
"team_ids": [(6, 0, team.ids)],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"first_name": "Test",
|
"first_name": "Test",
|
||||||
"last_name": "Patient Two",
|
"last_name": "Patient Two",
|
||||||
"date_of_birth": Date.today() - timedelta(days=-365 * 18),
|
"date_of_birth": Date.today() - timedelta(days=-365 * 18),
|
||||||
"team_ids": [6, 0, team.ids],
|
"team_ids": [(6, 0, team.ids)],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return team, patients
|
return team, patients
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue