From 86350c56ff70863caeb8ce44ce34d45c3fb5791d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 15 Feb 2018 16:09:36 +0100 Subject: [PATCH] [REF] various: clean override of _notify_get_groups Overrides of _notify_get_groups are used to add some buttons in notification emails and control the display of "Access document" button. This commit cleans some overrides : * accounting: portal users that are not the customer have no access to the invoice and should not have the access button; * project: remove unnecessary override on project model and consider portal users have access to the document through customer portal; * sale: portal users that are not the customer have no access to the sale order and should not have the access button; * website_blog: display access button to everyone only if the post is published; otherwise keep standard behavior; * website_forum: display access button to everyone only if the post has not been closed or deactivated; otherwise keep standard behavior; * website_slides: display access button to everyone only if the slides has been published; otherwise keep standard behavior; --- addons/account/models/account_invoice.py | 5 +++- addons/project/models/project.py | 34 +++++++--------------- addons/sale/models/sale.py | 5 +++- addons/website_blog/models/website_blog.py | 6 ++-- addons/website_forum/models/forum.py | 6 ++-- addons/website_slides/models/slides.py | 2 +- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 05a04619d47..fe6b7659b4d 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -873,11 +873,14 @@ class AccountInvoice(models.Model): @api.multi def _notify_get_groups(self, message, groups): + """ Give access button to users and portal customer as portal is integrated + in account. Customer and portal group have probably no right to see + the document so they don't have the access button. """ groups = super(AccountInvoice, self)._notify_get_groups(message, groups) if self.state not in ('draft', 'cancel'): for group_name, group_method, group_data in groups: - if group_name == 'customer': + if group_name in ('customer', 'portal'): continue group_data['has_button_access'] = True diff --git a/addons/project/models/project.py b/addons/project/models/project.py index c0323cce0dc..9b0b7e8d717 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -376,17 +376,6 @@ class Project(models.Model): self.mapped('tasks').message_unsubscribe(partner_ids=partner_ids, channel_ids=channel_ids) return super(Project, self).message_unsubscribe(partner_ids=partner_ids, channel_ids=channel_ids) - @api.multi - def _notify_get_groups(self, message, groups): - groups = super(Project, self)._notify_get_groups(message, groups) - - for group_name, group_method, group_data in groups: - if group_name in ['customer', 'portal']: - continue - group_data['has_button_access'] = True - - return groups - # --------------------------------------------------- # Actions # --------------------------------------------------- @@ -874,25 +863,24 @@ class Task(models.Model): @api.multi def _notify_get_groups(self, message, groups): - """ Handle project users and managers recipients that can convert assign - tasks and create new one directly from notification emails. """ + """ Handle project users and managers recipients that can assign + tasks and create new one directly from notification emails. Also give + access button to portal users and portal customers. If they are notified + they should probably have access to the document. """ groups = super(Task, self)._notify_get_groups(message, groups) self.ensure_one() - if not self.user_id: + if not self.user_id and not self.stage_id.fold: take_action = self._notify_get_action_link('assign') project_actions = [{'url': take_action, 'title': _('I take it')}] - else: - project_actions = [] + new_group = ( + 'group_project_user', lambda partner: bool(partner.user_ids) and any(user.has_group('project.group_project_user') for user in partner.user_ids), { + 'actions': project_actions, + }) + groups = [new_group] + groups - new_group = ( - 'group_project_user', lambda partner: bool(partner.user_ids) and any(user.has_group('project.group_project_user') for user in partner.user_ids), { - 'actions': project_actions, - }) - - groups = [new_group] + groups for group_name, group_method, group_data in groups: - if group_name in ['customer', 'portal']: + if group_name in ('customer'): continue group_data['has_button_access'] = True diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index df61e13d3ba..09a387c9b43 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -648,12 +648,15 @@ class SaleOrder(models.Model): @api.multi def _notify_get_groups(self, message, groups): + """ Give access button to users and portal customer as portal is integrated + in sale. Customer and portal group have probably no right to see + the document so they don't have the access button. """ groups = super(SaleOrder, self)._notify_get_groups(message, groups) self.ensure_one() if self.state not in ('draft', 'cancel'): for group_name, group_method, group_data in groups: - if group_name == 'customer': + if group_name in ('customer', 'portal'): continue group_data['has_button_access'] = True diff --git a/addons/website_blog/models/website_blog.py b/addons/website_blog/models/website_blog.py index 8e68beff13c..e6957a34412 100644 --- a/addons/website_blog/models/website_blog.py +++ b/addons/website_blog/models/website_blog.py @@ -234,10 +234,12 @@ class BlogPost(models.Model): @api.multi def _notify_get_groups(self, message, groups): + """ Add access button to everyone if the document is published. """ groups = super(BlogPost, self)._notify_get_groups(message, groups) - for group_name, group_method, group_data in groups: - group_data['has_button_access'] = True + if self.website_published: + for group_name, group_method, group_data in groups: + group_data['has_button_access'] = True return groups diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 52ef1ad8305..073eb69e219 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -794,10 +794,12 @@ class Post(models.Model): @api.multi def _notify_get_groups(self, message, groups): + """ Add access button to everyone if the document is active. """ groups = super(Post, self)._notify_get_groups(message, groups) - for group_name, group_method, group_data in groups: - group_data['has_button_access'] = True + if self.state == 'active': + for group_name, group_method, group_data in groups: + group_data['has_button_access'] = True return groups diff --git a/addons/website_slides/models/slides.py b/addons/website_slides/models/slides.py index 0f958b7d8c7..d2e24ba52a8 100644 --- a/addons/website_slides/models/slides.py +++ b/addons/website_slides/models/slides.py @@ -454,9 +454,9 @@ class Slide(models.Model): @api.multi def _notify_get_groups(self, message, groups): + """ Add access button to everyone if the document is active. """ groups = super(Slide, self)._notify_get_groups(message, groups) - self.ensure_one() if self.website_published: for group_name, group_method, group_data in groups: group_data['has_button_access'] = True