Skip to content

Commit 0429996

Browse files
committed
[FIX] rma: portal views access errors
- Portal mail thread needs token config. - Unpublished products will raise AccessError on RMAs portal views for portal users due to record rules. - Ensure active_id when getting actions in rma, since we could come from a context that pollutes the expected active rma id.
1 parent aff0d83 commit 0429996

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

rma/models/rma.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,10 @@ def action_replace(self):
599599
"""Invoked when 'Replace' button in rma form view is clicked."""
600600
self.ensure_one()
601601
self._ensure_can_be_replaced()
602-
action = self.env.ref("rma.rma_delivery_wizard_action").read()[0]
602+
# Force active_id to avoid issues when coming from smart buttons
603+
# in other models
604+
action = self.env.ref("rma.rma_delivery_wizard_action").with_context(
605+
active_id=self.id).read()[0]
603606
action['name'] = 'Replace product(s)'
604607
action['context'] = dict(self.env.context)
605608
action['context'].update(
@@ -615,7 +618,10 @@ def action_return(self):
615618
"""
616619
self.ensure_one()
617620
self._ensure_can_be_returned()
618-
action = self.env.ref("rma.rma_delivery_wizard_action").read()[0]
621+
# Force active_id to avoid issues when coming from smart buttons
622+
# in other models
623+
action = self.env.ref("rma.rma_delivery_wizard_action").with_context(
624+
active_id=self.id).read()[0]
619625
action['context'] = dict(self.env.context)
620626
action['context'].update(
621627
active_id=self.id,
@@ -628,9 +634,12 @@ def action_split(self):
628634
"""Invoked when 'Split' button in rma form view is clicked."""
629635
self.ensure_one()
630636
self._ensure_can_be_split()
631-
action = self.env.ref("rma.rma_split_wizard_action").read()[0]
637+
# Force active_id to avoid issues when coming from smart buttons
638+
# in other models
639+
action = self.env.ref("rma.rma_split_wizard_action").with_context(
640+
active_id=self.id).read()[0]
632641
action['context'] = dict(self.env.context)
633-
action['context'].update(active_ids=self.ids)
642+
action['context'].update(active_id=self.id, active_ids=self.ids)
634643
return action
635644

636645
def action_cancel(self):
@@ -663,7 +672,10 @@ def action_preview(self):
663672
def action_view_receipt(self):
664673
"""Invoked when 'Receipt' smart button in rma form view is clicked."""
665674
self.ensure_one()
666-
action = self.env.ref('stock.action_picking_tree_all').read()[0]
675+
# Force active_id to avoid issues when coming from smart buttons
676+
# in other models
677+
action = self.env.ref('stock.action_picking_tree_all').with_context(
678+
active_id=self.id).read()[0]
667679
action.update(
668680
res_id=self.reception_move_id.picking_id.id,
669681
view_mode="form",
@@ -687,7 +699,8 @@ def action_view_refund(self):
687699

688700
def action_view_delivery(self):
689701
"""Invoked when 'Delivery' smart button in rma form view is clicked."""
690-
action = self.env.ref('stock.action_picking_tree_all').read()[0]
702+
action = self.env.ref('stock.action_picking_tree_all').with_context(
703+
active_id=self.id).read()[0]
691704
picking = self.delivery_move_ids.mapped('picking_id')
692705
if len(picking) > 1:
693706
action['domain'] = [('id', 'in', picking.ids)]

rma/views/rma_portal_templates.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
</a>
5151
</td>
5252
<td class="d-none d-md-table-cell"><span t-field="rma.date"/></td>
53-
<td><span t-field="rma.product_id.name"/></td>
53+
<!-- Portal users don't have access to unpublished products -->
54+
<td><span t-esc="rma.sudo().product_id.display_name"/></td>
5455
<td class='text-right'><span t-field="rma.product_uom_qty"/></td>
5556
<td class="d-none d-md-table-cell tx_status">
5657
<span class="badge badge-pill badge-secondary"><span t-field="rma.state"/></span>
@@ -132,12 +133,14 @@
132133
<span t-field="rma.picking_id"/>
133134
</div>
134135
</div>
135-
<div t-if="rma.product_id" class="row mb-2 mb-sm-1">
136+
<!-- We need to prevent access errors if the product is
137+
unpublished-->
138+
<div t-if="rma.sudo().product_id" class="row mb-2 mb-sm-1">
136139
<div class="col-12 col-sm-4">
137140
<strong>Product</strong>
138141
</div>
139142
<div class="col-12 col-sm-8">
140-
<span t-field="rma.product_id"/>
143+
<span t-esc="rma.sudo().product_id.display_name"/>
141144
</div>
142145
</div>
143146
<div t-if="rma.product_uom_qty" class="row mb-2 mb-sm-1">
@@ -262,6 +265,9 @@
262265
<h2>Communication</h2>
263266
<t t-call="portal.message_thread">
264267
<t t-set="object" t-value="rma"/>
268+
<t t-set="token" t-value="rma.access_token"/>
269+
<t t-set="pid" t-value="pid"/>
270+
<t t-set="hash" t-value="hash"/>
265271
</t>
266272
</div>
267273
</t>

0 commit comments

Comments
 (0)