diff --git a/project_visibility_followers_portal/__init__.py b/project_visibility_followers_portal/__init__.py index cde864b..a9e3372 100644 --- a/project_visibility_followers_portal/__init__.py +++ b/project_visibility_followers_portal/__init__.py @@ -1,3 +1,2 @@ -# -*- coding: utf-8 -*- from . import models diff --git a/project_visibility_followers_portal/__manifest__.py b/project_visibility_followers_portal/__manifest__.py index 4bea689..d724b2e 100644 --- a/project_visibility_followers_portal/__manifest__.py +++ b/project_visibility_followers_portal/__manifest__.py @@ -3,7 +3,7 @@ { "name": "project_visibility_followers_portal", - "version": "14.0.1.0.0", + "version": "16.0.1.0.0", "author": "Elabore", "website": "https://github.com/elabore-coop/project-tools", "maintainer": "Clément Thomas", @@ -77,7 +77,6 @@ This module is maintained by Elabore. }, # always loaded "data": [ - "views/project_views.xml", "security/project_security.xml" ], # only loaded in demonstration mode diff --git a/project_visibility_followers_portal/models/project_project.py b/project_visibility_followers_portal/models/project_project.py index dd53048..31d7ad2 100644 --- a/project_visibility_followers_portal/models/project_project.py +++ b/project_visibility_followers_portal/models/project_project.py @@ -5,6 +5,7 @@ from odoo import models, fields, api class Project(models.Model): _inherit = "project.project" + # A reprendre pour ajouter l’option de visibilité privacy_visibility = fields.Selection( selection_add=[('followers_portal','Invited portal users and invited internal users')], ondelete={'followers_portal': 'set default'}) @@ -16,7 +17,7 @@ class Project(models.Model): """ project = super(Project, self).create(vals) if project.privacy_visibility == 'followers_portal' and project.partner_id.user_ids: - project.allowed_user_ids |= project.partner_id.user_ids + project.message_partner_ids |= project.partner_id return project def write(self, vals): @@ -26,5 +27,6 @@ class Project(models.Model): res = super(Project, self).write(vals) if vals.get('partner_id') or vals.get('privacy_visibility'): for project in self.filtered(lambda project: project.privacy_visibility == 'followers_portal'): - project.allowed_user_ids |= project.partner_id.user_ids - return res \ No newline at end of file + project.message_partner_ids |= project.partner_id + return res + diff --git a/project_visibility_followers_portal/models/project_task.py b/project_visibility_followers_portal/models/project_task.py index 97bfedb..9c41205 100644 --- a/project_visibility_followers_portal/models/project_task.py +++ b/project_visibility_followers_portal/models/project_task.py @@ -6,49 +6,20 @@ from odoo.exceptions import ValidationError class Task(models.Model): _inherit = "project.task" - @api.constrains('allowed_user_ids') + @api.constrains('message_partner_ids') def _check_no_portal_allowed(self): for task in self.filtered(lambda t: t.project_id.privacy_visibility not in ('portal','followers_portal')): - portal_users = task.allowed_user_ids.filtered('share') + portal_users = task.message_partner_ids.user_ids.filtered('share') if portal_users: user_names = ', '.join(portal_users[:10].mapped('name')) raise ValidationError(_("The project visibility setting doesn't allow portal users to see the project's tasks. (%s)", user_names)) - - @api.depends('project_id.allowed_user_ids', 'project_id.privacy_visibility') - def _compute_allowed_user_ids(self): - for task in self.with_context(prefetch_fields=False): - portal_users = task.allowed_user_ids.filtered('share') - internal_users = task.allowed_user_ids - portal_users - - if task.project_id.privacy_visibility == 'followers': - task.allowed_user_ids |= task.project_id.allowed_internal_user_ids - task.allowed_user_ids -= portal_users - elif task.project_id.privacy_visibility == 'portal': - task.allowed_user_ids |= task.project_id.allowed_portal_user_ids - elif task.project_id.privacy_visibility == 'followers_portal': - task.allowed_user_ids |= task.project_id.allowed_internal_user_ids - task.allowed_user_ids |= task.project_id.allowed_portal_user_ids - - if task.project_id.privacy_visibility not in ('portal','followers_portal'): - task.allowed_user_ids -= portal_users - elif task.project_id.privacy_visibility not in ('followers','followers_portal'): - task.allowed_user_ids -= internal_users def _compute_access_warning(self): for task in self.filtered(lambda x: x.project_id.privacy_visibility not in ('portal','followers_portal')): task.access_warning = _( "The task cannot be shared with the recipient(s) because the privacy of the project is too restricted. Set the privacy of the project to 'Visible by following customers' in order to make it accessible by the recipient(s).") - def message_subscribe(self, partner_ids=None, channel_ids=None, subtype_ids=None): - """ - Add the users subscribed to allowed portal users - """ - res = super(Task, self).message_subscribe(partner_ids=partner_ids, channel_ids=channel_ids, subtype_ids=subtype_ids) - if partner_ids: - new_allowed_users = self.env['res.partner'].browse(partner_ids).user_ids.filtered('share') - tasks = self.filtered(lambda task: task.project_id.privacy_visibility == 'followers_portal') - tasks.sudo().allowed_user_ids |= new_allowed_users - return res + @api.model_create_multi def create(self, vals_list): @@ -71,18 +42,18 @@ class Task(models.Model): group_func = lambda pdata: pdata['type'] == 'user' and project_user_group_id in pdata['groups'] if self.project_id.privacy_visibility == 'followers_portal': - allowed_user_ids = self.project_id.allowed_internal_user_ids.partner_id.ids + message_partner_ids = self.project_id.message_partner_ids.partner_id.ids group_func = lambda pdata:\ pdata['type'] == 'user'\ and ( project_manager_group_id in pdata['groups']\ - or (project_user_group_id in pdata['groups'] and pdata['id'] in allowed_user_ids) + or (project_user_group_id in pdata['groups'] and pdata['id'] in message_partner_ids) ) groups = [('group_project_user', group_func, {})]+groups - allowed_user_ids = self.project_id.allowed_portal_user_ids.partner_id.ids + message_partner_ids = self.project_id.message_partner_ids groups.insert(0, ( - 'allowed_portal_users', - lambda pdata: pdata['type'] == 'portal' and pdata['id'] in allowed_user_ids, + 'message_partner_ids', + lambda pdata: pdata['type'] == 'portal' and pdata['id'] in message_partner_ids, {} )) diff --git a/project_visibility_followers_portal/security/project_security.xml b/project_visibility_followers_portal/security/project_security.xml index 0cae1df..2021e7e 100644 --- a/project_visibility_followers_portal/security/project_security.xml +++ b/project_visibility_followers_portal/security/project_security.xml @@ -8,8 +8,7 @@ [ ('privacy_visibility', '=', 'followers_portal'), - '|', ('allowed_portal_user_ids', 'in', user.ids), - ('allowed_internal_user_ids', 'in', user.ids), + ('message_partner_ids', 'in', [user.partner_id.id]) ] @@ -19,36 +18,46 @@ [ ('project_id.privacy_visibility', '=', 'followers_portal'), - ('allowed_user_ids', 'in', user.ids), + '|', + ('project_id.message_partner_ids', 'child_of', [user.partner_id.commercial_partner_id.id]), + ('message_partner_ids', 'child_of', [user.partner_id.commercial_partner_id.id]), ] + - + [ '|', ('privacy_visibility', '!=', 'followers_portal'), - ('allowed_internal_user_ids', 'in', user.ids), + ('message_partner_ids', 'in', [user.partner_id.id]), '|', ('privacy_visibility', '!=', 'followers'), - ('allowed_internal_user_ids', 'in', user.ids), + ('message_partner_ids', 'in', [user.partner_id.id]) ] [ '|', - ('project_id.privacy_visibility', '!=', 'followers_portal'), - ('allowed_user_ids', 'in', user.ids), - '|', - ('project_id.privacy_visibility', '!=', 'followers'), - ('allowed_user_ids', 'in', user.ids), + '&', + ('project_id', '!=', False), + ( + '|', + ('project_id.privacy_visibility', '!=', 'followers_portal'), + ('project_id.message_partner_ids', 'in', [user.partner_id.id]), + '|', + ('project_id.privacy_visibility', '!=', 'followers'), + ('project_id.message_partner_ids', 'in', [user.partner_id.id]), + ), + '|', + ('message_partner_ids', 'in', [user.partner_id.id]), + # to subscribe check access to the record, follower is not enough at creation + ('user_ids', 'in', user.id) ] - - diff --git a/project_visibility_followers_portal/views/project_views.xml b/project_visibility_followers_portal/views/project_views.xml deleted file mode 100644 index bcc815b..0000000 --- a/project_visibility_followers_portal/views/project_views.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - project.form.visibility.followers.portal - project.project - - - - {'invisible': [('privacy_visibility', '!=', 'followers'),('privacy_visibility', '!=', 'followers_portal')]} - - - {'invisible': [('privacy_visibility', '!=', 'portal'),('privacy_visibility', '!=', 'followers_portal')]} - - - - - -