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/purchase | |
| 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/purchase')
| -rw-r--r-- | addons/purchase/controllers/portal.py | 23 | ||||
| -rw-r--r-- | addons/purchase/data/purchase_data.xml | 8 | ||||
| -rw-r--r-- | addons/purchase/models/purchase.py | 11 | ||||
| -rw-r--r-- | addons/purchase/views/purchase_views.xml | 1 |
4 files changed, 24 insertions, 19 deletions
diff --git a/addons/purchase/controllers/portal.py b/addons/purchase/controllers/portal.py index 53a517845e6..d121494bf68 100644 --- a/addons/purchase/controllers/portal.py +++ b/addons/purchase/controllers/portal.py @@ -23,6 +23,12 @@ class CustomerPortal(CustomerPortal): ]) return values + def _purchase_order_get_page_view_values(self, order, access_token, **kwargs): + values = { + 'order': order, + } + return self._get_page_view_values(order, access_token, values, 'my_purchases_history', True, **kwargs) + @http.route(['/my/purchase', '/my/purchase/page/<int:page>'], type='http', auth="user", website=True) def portal_my_purchase_orders(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw): values = self._prepare_portal_layout_values() @@ -93,17 +99,12 @@ class CustomerPortal(CustomerPortal): }) return request.render("purchase.portal_my_purchase_orders", values) - @http.route(['/my/purchase/<int:order_id>'], type='http', auth="user", website=True) - def portal_my_purchase_order(self, order_id=None, **kw): - order = request.env['purchase.order'].browse(order_id) + @http.route(['/my/purchase/<int:order_id>'], type='http', auth="public", website=True) + def portal_my_purchase_order(self, order_id=None, access_token=None, **kw): try: - order.check_access_rights('read') - order.check_access_rule('read') + order_sudo = self._document_check_access('purchase.order', order_id, access_token=access_token) except AccessError: return request.redirect('/my') - history = request.session.get('my_purchases_history', []) - values = { - 'order': order.sudo(), - } - values.update(get_records_pager(history, order)) - return request.render("purchase.portal_my_purchase_order", values) + + values = self._purchase_order_get_page_view_values(order_sudo, access_token, **kw) + return request.render("purchase.portal_my_purchase_order", values)
\ No newline at end of file diff --git a/addons/purchase/data/purchase_data.xml b/addons/purchase/data/purchase_data.xml index a7cae1b0012..85953c0f1e0 100644 --- a/addons/purchase/data/purchase_data.xml +++ b/addons/purchase/data/purchase_data.xml @@ -27,5 +27,13 @@ <field name="company_id" eval="False"/> </record> + <!-- Share Button in action menu --> + <record id="model_purchase_order_action_share" model="ir.actions.server"> + <field name="name">Share</field> + <field name="model_id" ref="purchase.model_purchase_order"/> + <field name="binding_model_id" ref="purchase.model_purchase_order"/> + <field name="state">code</field> + <field name="code">action = records.action_share()</field> + </record> </data> </odoo> diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index cfa1fec6362..36b8aa3aa8e 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -14,7 +14,7 @@ from odoo.addons import decimal_precision as dp class PurchaseOrder(models.Model): _name = "purchase.order" - _inherit = ['mail.thread', 'mail.activity.mixin'] + _inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin'] _description = "Purchase Order" _order = 'date_order desc, id desc' @@ -125,13 +125,10 @@ class PurchaseOrder(models.Model): user_id = fields.Many2one('res.users', string='Purchase Representative', index=True, track_visibility='onchange', default=lambda self: self.env.user) company_id = fields.Many2one('res.company', 'Company', required=True, index=True, states=READONLY_STATES, default=lambda self: self.env.user.company_id.id) - website_url = fields.Char( - 'Website URL', compute='_website_url', - help='The full URL to access the document through the website.') - - def _website_url(self): + def _compute_access_url(self): + super(PurchaseOrder, self)._compute_access_url() for order in self: - order.website_url = '/my/purchase/%s' % (order.id) + order.access_url = '/my/purchase/%s' % (order.id) @api.model def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): diff --git a/addons/purchase/views/purchase_views.xml b/addons/purchase/views/purchase_views.xml index b815f3438f6..e9a3115b773 100644 --- a/addons/purchase/views/purchase_views.xml +++ b/addons/purchase/views/purchase_views.xml @@ -489,5 +489,4 @@ </search> </field> </record> - </odoo> |
