diff --git a/bemade_sports_clinic/__manifest__.py b/bemade_sports_clinic/__manifest__.py index b4fcf89..0f7aed8 100644 --- a/bemade_sports_clinic/__manifest__.py +++ b/bemade_sports_clinic/__manifest__.py @@ -18,7 +18,7 @@ # { 'name': 'Sports Clinic Management', - 'version': '16.0.1.5.7', + 'version': '16.0.1.5.8', 'summary': 'Manage the patients of a sports medicine clinic.', 'description': """ Adds the notion of sports teams, players (patients), coaches and treatment @@ -49,6 +49,7 @@ 'views/sports_patient_views.xml', 'views/sports_clinic_portal_views.xml', 'views/res_partner_views.xml', + 'views/res_users_views.xml', ], 'demo': ['data/demo/sports_clinic_demo_data.xml'], 'installable': True, diff --git a/bemade_sports_clinic/migrations/16.0.1.5.8/post-migrate.py b/bemade_sports_clinic/migrations/16.0.1.5.8/post-migrate.py new file mode 100644 index 0000000..818ad3b --- /dev/null +++ b/bemade_sports_clinic/migrations/16.0.1.5.8/post-migrate.py @@ -0,0 +1,7 @@ +from odoo import api, SUPERUSER_ID + + +def migrate(cr, version): + env = api.Environment(cr, SUPERUSER_ID, {}) + env['sports.team'].search([])._allow_access_for_staff_internal_users() + cr.execute('CREATE EXTENSION IF NOT EXISTS "unaccent"') diff --git a/bemade_sports_clinic/models/patient_contact.py b/bemade_sports_clinic/models/patient_contact.py index 36e70cc..90420b4 100644 --- a/bemade_sports_clinic/models/patient_contact.py +++ b/bemade_sports_clinic/models/patient_contact.py @@ -7,13 +7,13 @@ class PatientContact(models.Model): _description = "Emergency or other contacts for a patient." sequence = fields.Integer(required=True, default=0) - name = fields.Char(unaccent=False) + name = fields.Char(unaccent=True) contact_type = fields.Selection(selection=[ ('mother', 'Mother'), ('father', 'Father'), ('other', 'Other'), ], required=True) - mobile = fields.Char(unaccent=False, required=True) + mobile = fields.Char(unaccent=False) # TODO: add email here and on views patient_id = fields.Many2one(comodel_name='sports.patient', string='Patient') diff --git a/bemade_sports_clinic/models/res_users.py b/bemade_sports_clinic/models/res_users.py index 1dcd258..e522245 100644 --- a/bemade_sports_clinic/models/res_users.py +++ b/bemade_sports_clinic/models/res_users.py @@ -7,6 +7,14 @@ class User(models.Model): is_treatment_professional = fields.Boolean( compute="_compute_is_treatment_professional", store=True) + accessible_team_ids = fields.Many2many( + comodel_name="sports.team", + relation="sports_team_res_users_rel", + column1="user_id", + column2="team_id", + string="Accessible Sports Teams", + ) + @api.depends('groups_id') def _compute_is_treatment_professional(self): for rec in self: diff --git a/bemade_sports_clinic/models/sports_team.py b/bemade_sports_clinic/models/sports_team.py index 6f7d589..9856b72 100644 --- a/bemade_sports_clinic/models/sports_team.py +++ b/bemade_sports_clinic/models/sports_team.py @@ -28,6 +28,28 @@ class SportsTeam(models.Model): store=True) head_therapist_name = fields.Char(related='head_therapist_id.name') website = fields.Char() + allowed_user_ids = fields.Many2many( + comodel_name='res.users', + relation='sports_team_res_users_rel', + column1='team_id', + column2='user_id', + string='Allowed Users', + domain=lambda self: [['groups_id', 'in', self.env.ref("base.group_user").ids ]] + ) + + def write(self, vals): + res = super().write(vals) + if 'staff_ids' in vals: + self._allow_access_for_staff_internal_users() + return res + + @api.model_create_multi + def create(self, vals_list): + res = super().create(vals_list) + for index, rec in enumerate(res): + if 'staff_ids' in vals_list[index]: + rec._allow_access_for_staff_internal_users() + return res @api.depends('patient_ids.is_injured') def _compute_player_counts(self): @@ -48,6 +70,10 @@ class SportsTeam(models.Model): staff = rec.staff_ids.filtered(lambda r: r.role == 'head_therapist') rec.head_therapist_id = staff.partner_id if staff else False + def _allow_access_for_staff_internal_users(self): + for rec in self: + rec.allowed_user_ids |= rec.staff_ids.user_ids.filtered(lambda user: user.has_group("base.group_user")) + class TeamStaff(models.Model): _name = "sports.team.staff" diff --git a/bemade_sports_clinic/security/sports_clinic_rules.xml b/bemade_sports_clinic/security/sports_clinic_rules.xml index 41bf382..78a97b1 100644 --- a/bemade_sports_clinic/security/sports_clinic_rules.xml +++ b/bemade_sports_clinic/security/sports_clinic_rules.xml @@ -2,13 +2,140 @@ - + Restrict Team Staff Access to Their Players Only + + + + - [('id', 'in', - user.partner_id.team_staff_rel_ids.team_id.patient_ids.ids)] + [('team_ids.staff_ids.user_ids', 'in', user.id)] + + + + Restrict Team Staff Access to Their Teams Only + + + + + + + + [('staff_ids.user_ids', 'in', user.id)] + + + + Restrict Team Staff Access to Their Teams Only + + + + + + + + [('patient_id.team_ids.staff_ids.user_ids', 'in', user.id)] + + + + Restrict Team Access to Allowed Internal Users + + + + + + + + [('allowed_user_ids', 'in', user.id)] + + + + Restrict Patient Access to Allowed Internal Users + + + + + + + + [('team_ids.allowed_user_ids', 'in', user.id)] + + + + Restrict Team Access to Allowed Internal Users + + + + + + + + [('patient_id.team_ids.allowed_user_ids', 'in', user.id)] + + + + Restrict Patient Contact Access to Allowed Internal Users + + + + + + + + [('patient_id.team_ids.allowed_user_ids', 'in', user.id)] + + + + Allow Team Access to Administrators + + + + + + + + [(1, '=', 1)] + + + + Allow Patient Access to Administrators + + + + + + + + [(1, '=', 1)] + + + + Allow Injury Access to Administrators + + + + + + + + [(1, '=', 1)] + + + + Allow Sports Patient Contact Access to Administrators + + + + + + + + [(1, '=', 1)] diff --git a/bemade_sports_clinic/views/res_users_views.xml b/bemade_sports_clinic/views/res_users_views.xml new file mode 100644 index 0000000..cbef072 --- /dev/null +++ b/bemade_sports_clinic/views/res_users_views.xml @@ -0,0 +1,16 @@ + + + + view.users.form.inherit + + res.users + + + + + + + + + \ No newline at end of file diff --git a/bemade_sports_clinic/views/sports_team_views.xml b/bemade_sports_clinic/views/sports_team_views.xml index 50ccca2..988fe2c 100644 --- a/bemade_sports_clinic/views/sports_team_views.xml +++ b/bemade_sports_clinic/views/sports_team_views.xml @@ -125,9 +125,17 @@ - - + + + + + + + +