diff options
| author | Mitali Patel <mpa@odoo.com> | 2017-12-15 14:38:02 +0530 |
|---|---|---|
| committer | David Beguin <dbe@odoo.com> | 2018-08-03 15:20:42 +0200 |
| commit | 84f528bcff12e39b5ed172a4789aab27c9f89a19 (patch) | |
| tree | 747f84c680e2a1a122ac190792d4a2d7b07612ef /addons/account/controllers | |
| parent | 766a1025b1ba25ef40897418fac662eaa42d3a0f (diff) | |
[IMP] Portal - Share link : Easily share the url of a document
Purpose
=======
- Quickly share the url to someone else (a client, a colleague,...)
- Ensure that the recipient can access at least
the portal view of the shared record.
- Typically used when a client cannot retrieve the mail to access his order.
The share link can be used in this case.
Specifications
==============
For any object inheriting form portal.mixin:
- Add a button SHARE (not visible in edit mode)
- When clicking on this button, a popup opens with :
- A warning message for tasks and projects only (see below)
- the link (like in gmail) that can be copied
- Recipients
- mail composer (with preselected template) ==> see below
- button [Send Link] [Copy Link] Discard
- After sharing document, put internal note like
"Document shared to xyz,...." with template message
- Anyone with the link, even anonymous user (not logged in) can have access
to the document with the access token provided in the url.
Impacted models:
- account.invoice (Community)
- project.project (Community)
- project.task (Community)
- purchase.order (Community)
- sale.order (Community)
- helpdesk.ticket (Enterprise)
Warning messages and access rules:
Allowed :
- SO canceled or draft will be accessible with the link
with access_token
- If the customer account is B2B (signup not enabled), the recipient
will anyway see the document as the user specifically wants the
recipient to see the document.
Restrictions :
- For Project and Task, if the privacy is not public, then, there is a
contradiction between the access_token mechanism
and the privacy of the document.
- A warning message will be displayed in the share wizard to inform the
user if the document cannot be visible by the recipients and to
ask him to set the privacy to 'Visible by following customer'.
The send button will, in that case, be hidden.
- To avoid to block the share for a new project, default privacy value
is now set to 'Visible by followong customer'
Technical implementation
========================
- Move the access_token mechanism (field + methods + mail controller)
to the portal.mixin to be able to use it in a generic way for each object
inheriting the portal.mixin
- Generalise a part of the _*model*_get_page_view_values method
into a single one in portal
- Generalize the _*model*_check_access into the portal controller of the
portal module
- Remove the init_column + default value for the access_token
> old records have an access_token,
> new one won't but it will be generated on demand via the get_access_token
Done for performance reasons
- Add share button into action menu separately. + kanban view context menu
(except for task and project where button not in action menu but 'simple'
button for task and project because other modules already provide action
to send documents by email, which is not the case for project and task.)
- Add a sign_token used to authentify the recipient in the portal view chatter,
if any. The message will be posted as if the user was logged in.
- Set the _get_share_url as private for security reason
- Add a redirect parameter to _get_share_url to get
If false : The direct portal view url
If True : The redirect url (mail/view/?)
- Cleaning up unnecessary code
- Bug fix :
- Before, if user was not logged and record had partner_id,
if partner id was null, post message was done as admin.
Now, the post message is done as public user.
- If the user had an uid but had no access_token, he could be able
to gain the access token of the record.
check_access_rights was missing in the get_access_action.
Task ID : 30985
Closes #25629
Diffstat (limited to 'addons/account/controllers')
| -rw-r--r-- | addons/account/controllers/__init__.py | 1 | ||||
| -rw-r--r-- | addons/account/controllers/mail.py | 30 | ||||
| -rw-r--r-- | addons/account/controllers/portal.py | 32 |
3 files changed, 3 insertions, 60 deletions
diff --git a/addons/account/controllers/__init__.py b/addons/account/controllers/__init__.py index 6d24304de46..1a195b71756 100644 --- a/addons/account/controllers/__init__.py +++ b/addons/account/controllers/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import mail from . import onboarding from . import portal diff --git a/addons/account/controllers/mail.py b/addons/account/controllers/mail.py deleted file mode 100644 index 564856b909c..00000000000 --- a/addons/account/controllers/mail.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -import werkzeug - -from odoo.addons.mail.controllers.main import MailController -from odoo.exceptions import AccessError -from odoo.http import request -from odoo.tools.misc import consteq - - -class MailController(MailController): - - @classmethod - def _redirect_to_record(cls, model, res_id, access_token=None): - # If the current user doesn't have access to the invoice, but provided - # a valid access token, redirect him to the front-end view. - if model == 'account.invoice' and res_id and access_token: - uid = request.session.uid or request.env.ref('base.public_user').id - record_sudo = request.env[model].sudo().browse(res_id).exists() - try: - record_sudo.sudo(uid).check_access_rights('read') - record_sudo.sudo(uid).check_access_rule('read') - except AccessError: - if record_sudo.access_token and consteq(record_sudo.access_token, access_token): - record_action = record_sudo.with_context( - force_website=True).get_access_action(uid) - if record_action['type'] == 'ir.actions.act_url': - return werkzeug.utils.redirect(record_action['url']) - return super(MailController, cls)._redirect_to_record(model, res_id, access_token=access_token) diff --git a/addons/account/controllers/portal.py b/addons/account/controllers/portal.py index c59be47e588..0da9ea570dc 100644 --- a/addons/account/controllers/portal.py +++ b/addons/account/controllers/portal.py @@ -8,7 +8,6 @@ from odoo import http, _ from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager, get_records_pager from odoo.exceptions import AccessError from odoo.http import request -from odoo.tools import consteq class PortalAccount(CustomerPortal): @@ -32,38 +31,13 @@ class PortalAccount(CustomerPortal): # My Invoices # ------------------------------------------------------------ - def _invoice_check_access(self, invoice_id, access_token=None): - invoice = request.env['account.invoice'].browse([invoice_id]) - invoice_sudo = invoice.sudo() - try: - invoice.check_access_rights('read') - invoice.check_access_rule('read') - except AccessError: - if not access_token or not consteq(invoice_sudo.access_token, access_token): - raise - return invoice_sudo - def _invoice_get_page_view_values(self, invoice, access_token, **kwargs): values = { 'page_name': 'invoice', 'invoice': invoice, } - if access_token: - # force breadcrumbs even if access_token to `invite` users to register if they click on it - values['no_breadcrumbs'] = False - values['access_token'] = access_token + return self._get_page_view_values(invoice, access_token, values, 'my_invoices_history', False, **kwargs) - if kwargs.get('error'): - values['error'] = kwargs['error'] - if kwargs.get('warning'): - values['warning'] = kwargs['warning'] - if kwargs.get('success'): - values['success'] = kwargs['success'] - - history = request.session.get('my_invoices_history', []) - values.update(get_records_pager(history, invoice)) - - return values @http.route(['/my/invoices', '/my/invoices/page/<int:page>'], type='http', auth="user", website=True) def portal_my_invoices(self, page=1, date_begin=None, date_end=None, sortby=None, **kw): @@ -117,7 +91,7 @@ class PortalAccount(CustomerPortal): @http.route(['/my/invoices/<int:invoice_id>'], type='http', auth="public", website=True) def portal_my_invoice_detail(self, invoice_id, access_token=None, **kw): try: - invoice_sudo = self._invoice_check_access(invoice_id, access_token) + invoice_sudo = self._document_check_access('account.invoice', invoice_id, access_token) except AccessError: return request.redirect('/my') @@ -130,7 +104,7 @@ class PortalAccount(CustomerPortal): ], type='http', auth="public", website=True) def portal_my_invoice_report(self, invoice_id, access_token=None, **kw): try: - invoice_sudo = self._invoice_check_access(invoice_id, access_token) + invoice_sudo = self._document_check_access('account.invoice', invoice_id, access_token) except AccessError: return request.redirect('/my') |
