[MIG] project_visibility_followers_portal: Migration to 16.0
This commit is contained in:
@@ -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
|
||||
project.message_partner_ids |= project.partner_id
|
||||
return res
|
||||
|
||||
|
@@ -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,
|
||||
{}
|
||||
))
|
||||
|
||||
|
Reference in New Issue
Block a user