[MERGE][IMP] portal, various: add access tokens in document access button for customer notification emails
Previously to this merge portal customers receiving a notification email on a shared document could not directly reach the document on the portal as the access token was not given to them. The only way to give access to portal was done using the specific email implemented for sale orders or invoices. This behavior is now extended to notification emails. This merge adds the token support for customers through inheritance in portal mixin. It also fixes inherit order so that the call chain effectively goes through portal before calling the mail.thread base implementation. This merge is related to task 40064. #Closes #21426.
This commit is contained in:
@@ -41,7 +41,7 @@ MAGIC_COLUMNS = ('id', 'create_uid', 'create_date', 'write_uid', 'write_date')
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
_name = "account.invoice"
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin']
|
||||
_inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin']
|
||||
_description = "Invoice"
|
||||
_order = "date_invoice desc, number desc, id desc"
|
||||
|
||||
@@ -875,10 +875,11 @@ class AccountInvoice(models.Model):
|
||||
def _notification_recipients(self, message, groups):
|
||||
groups = super(AccountInvoice, self)._notification_recipients(message, groups)
|
||||
|
||||
for group_name, group_method, group_data in groups:
|
||||
if group_name == 'customer':
|
||||
continue
|
||||
group_data['has_button_access'] = True
|
||||
if self.state not in ('draft', 'cancel'):
|
||||
for group_name, group_method, group_data in groups:
|
||||
if group_name == 'customer':
|
||||
continue
|
||||
group_data['has_button_access'] = True
|
||||
|
||||
return groups
|
||||
|
||||
|
||||
@@ -634,7 +634,7 @@ class MailThread(models.AbstractModel):
|
||||
local_kwargs.pop('res_id', None)
|
||||
|
||||
if link_type in ['view', 'assign', 'follow', 'unfollow']:
|
||||
params = dict(base_params)
|
||||
params = dict(base_params, **local_kwargs)
|
||||
base_link = '/mail/%s' % link_type
|
||||
elif link_type == 'controller':
|
||||
controller = local_kwargs.pop('controller')
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
from werkzeug.urls import url_encode
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class PortalMixin(models.AbstractModel):
|
||||
@@ -18,6 +18,27 @@ class PortalMixin(models.AbstractModel):
|
||||
for record in self:
|
||||
record.portal_url = '#'
|
||||
|
||||
def _get_access_token_field(self):
|
||||
""" Give the field used to fetch the customer portal access token, if
|
||||
any. Override this method if the field holding the token is named
|
||||
differently. """
|
||||
return 'access_token' if 'access_token' in self else False
|
||||
|
||||
def _get_customer_field(self):
|
||||
""" Give the field used to fetch the customer partner_id, if any.
|
||||
Override this method if the field holding the token is named differently. """
|
||||
return 'partner_id' if 'partner_id' in self else False
|
||||
|
||||
def _get_access_token(self):
|
||||
""" Get the current record access token """
|
||||
field = self._get_access_token_field()
|
||||
return self[field] if field else False
|
||||
|
||||
def _get_customer(self):
|
||||
""" Get the current record custome (res.partner record) """
|
||||
field = self._get_customer_field()
|
||||
return self[field] if field else self.env['res.partner']
|
||||
|
||||
def get_share_url(self):
|
||||
self.ensure_one()
|
||||
params = {
|
||||
@@ -30,3 +51,28 @@ class PortalMixin(models.AbstractModel):
|
||||
params.update(self.partner_id.signup_get_auth_param()[self.partner_id.id])
|
||||
|
||||
return '/mail/view?' + url_encode(params)
|
||||
|
||||
@api.multi
|
||||
def _notification_recipients(self, message, groups):
|
||||
access_token = self._get_access_token()
|
||||
customer = self._get_customer()
|
||||
|
||||
if access_token and customer:
|
||||
additional_params = {
|
||||
'access_token': self.access_token,
|
||||
}
|
||||
additional_params.update(customer.signup_get_auth_param()[customer.id])
|
||||
access_link = self._notification_link_helper('view', **additional_params)
|
||||
|
||||
new_group = [
|
||||
('portal_customer', lambda partner: partner.id == customer.id, {
|
||||
'has_button_access': False,
|
||||
'button_access': {
|
||||
'url': access_link,
|
||||
'title': ('View %s') % self.env['ir.model']._get(message.model).display_name,
|
||||
},
|
||||
})
|
||||
]
|
||||
else:
|
||||
new_group = []
|
||||
return super(PortalMixin, self)._notification_recipients(message, new_group + groups)
|
||||
|
||||
@@ -68,7 +68,7 @@ class ProjectTaskType(models.Model):
|
||||
class Project(models.Model):
|
||||
_name = "project.project"
|
||||
_description = "Project"
|
||||
_inherit = ['mail.alias.mixin', 'mail.thread', 'portal.mixin']
|
||||
_inherit = ['portal.mixin', 'mail.alias.mixin', 'mail.thread']
|
||||
_inherits = {'account.analytic.account': "analytic_account_id"}
|
||||
_order = "sequence, name, id"
|
||||
_period_number = 5
|
||||
@@ -444,7 +444,7 @@ class Task(models.Model):
|
||||
_name = "project.task"
|
||||
_description = "Task"
|
||||
_date_name = "date_start"
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin', 'rating.mixin']
|
||||
_inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin', 'rating.mixin']
|
||||
_mail_post_access = 'read'
|
||||
_order = "priority desc, sequence, date_start, name, id"
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ from odoo.addons import decimal_precision as dp
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_name = "sale.order"
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin']
|
||||
_inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin']
|
||||
_description = "Quotation"
|
||||
_order = 'date_order desc, id desc'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user