[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;
This commit is contained in:
Thibault Delavallée
2018-02-26 14:15:12 +01:00
parent 6eda1dcb7a
commit 86350c56ff
6 changed files with 28 additions and 30 deletions
+4 -1
View File
@@ -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
+11 -23
View File
@@ -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
+4 -1
View File
@@ -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
+4 -2
View File
@@ -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
+4 -2
View File
@@ -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
+1 -1
View File
@@ -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