From 2b1e2abda3df01fd69027671f10d81d66b838126 Mon Sep 17 00:00:00 2001 From: Horacio Tellez Date: Thu, 23 Feb 2023 13:22:54 +0000 Subject: [PATCH] [IMP] payment,*: restrict access to `payment.transaction` records Since 15.0, it is no longer possible to have partnerless transactions. Nonetheless, migrated databases could contain transactions without a `partner_id` set. This commit cleans existing rules to make those transactions are not accessible to unwanted users. We take the opportunity to clean the security of payment.transaction records globally. Now only admin and accounting users have access to payment.transaction records. The code of different applications has been adapted accordingly. Task - 3102824 closes odoo/odoo#113515 Related: odoo/upgrade#4564 Related: odoo/enterprise#40939 Signed-off-by: Masereel Pierre --- addons/account_payment/models/account_move.py | 5 +- .../security/ir.model.access.csv | 1 + addons/account_payment/security/ir_rules.xml | 10 ---- .../views/account_portal_templates.xml | 20 ++++---- addons/payment/security/ir.model.access.csv | 2 - addons/payment/security/payment_security.xml | 7 --- addons/sale/data/mail_template_data.xml | 14 +++--- addons/sale/models/sale_order.py | 5 +- addons/sale/views/sale_portal_templates.xml | 2 +- addons/website_sale/controllers/delivery.py | 2 +- addons/website_sale/controllers/main.py | 10 ++-- addons/website_sale/models/sale_order.py | 2 +- addons/website_sale/views/templates.xml | 50 +++++++++---------- .../website_sale_picking/views/templates.xml | 2 +- 14 files changed, 58 insertions(+), 74 deletions(-) diff --git a/addons/account_payment/models/account_move.py b/addons/account_payment/models/account_move.py index 1a5b3da8ab1..3ad2a0cdba3 100644 --- a/addons/account_payment/models/account_move.py +++ b/addons/account_payment/models/account_move.py @@ -15,7 +15,8 @@ class AccountMove(models.Model): readonly=True, copy=False) authorized_transaction_ids = fields.Many2many( string="Authorized Transactions", comodel_name='payment.transaction', - compute='_compute_authorized_transaction_ids', readonly=True, copy=False) + compute='_compute_authorized_transaction_ids', readonly=True, copy=False, + compute_sudo=True) amount_paid = fields.Monetary( string="Amount paid", compute='_compute_amount_paid' @@ -64,7 +65,7 @@ class AccountMove(models.Model): def get_portal_last_transaction(self): self.ensure_one() - return self.with_context(active_test=False).transaction_ids._get_last() + return self.with_context(active_test=False).transaction_ids.sudo()._get_last() def payment_action_capture(self): """ Capture all transactions linked to this invoice. """ diff --git a/addons/account_payment/security/ir.model.access.csv b/addons/account_payment/security/ir.model.access.csv index 64198ce3726..2d760562796 100644 --- a/addons/account_payment/security/ir.model.access.csv +++ b/addons/account_payment/security/ir.model.access.csv @@ -1,3 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink payment_link_wizard,payment.link.wizard,payment.model_payment_link_wizard,account.group_account_invoice,1,1,1,0 payment_refund_wizard,payment.refund.wizard,model_payment_refund_wizard,account.group_account_invoice,1,1,1,0 +payment_transaction_user,payment.transaction.user,model_payment_transaction,account.group_account_invoice,1,1,1,0 diff --git a/addons/account_payment/security/ir_rules.xml b/addons/account_payment/security/ir_rules.xml index c3f4dd9c812..58fe64373d7 100644 --- a/addons/account_payment/security/ir_rules.xml +++ b/addons/account_payment/security/ir_rules.xml @@ -1,16 +1,6 @@ - - - - Access every transaction - - - [(1, '=', 1)] - - - diff --git a/addons/account_payment/views/account_portal_templates.xml b/addons/account_payment/views/account_portal_templates.xml index 7405ca73af0..17bfbabe292 100644 --- a/addons/account_payment/views/account_portal_templates.xml +++ b/addons/account_payment/views/account_portal_templates.xml @@ -12,19 +12,19 @@ - + - Authorized - Pending - + Paid @@ -100,9 +100,9 @@ There was an error processing your payment: transaction failed.
- - - + + + @@ -115,9 +115,9 @@ inherit_id="account.portal_invoice_success"> - - -
+ + +
Communication:
diff --git a/addons/payment/security/ir.model.access.csv b/addons/payment/security/ir.model.access.csv index 1dfd9af50a5..2706330d09d 100644 --- a/addons/payment/security/ir.model.access.csv +++ b/addons/payment/security/ir.model.access.csv @@ -7,6 +7,4 @@ payment_method_all,payment.method.all,model_payment_method,,1,0,0,0 payment_method_system,payment.method.system,model_payment_method,base.group_system,1,1,1,1 payment_token_all,payment.token.all,model_payment_token,,1,0,0,0 payment_token_system,payment.token.system,model_payment_token,base.group_system,1,1,1,1 -payment_transaction_all,payment.transaction.all,model_payment_transaction,,1,0,0,0 payment_transaction_system,payment.transaction.system,model_payment_transaction,base.group_system,1,1,1,1 -payment_transaction_user,payment.transaction.user,model_payment_transaction,base.group_user,1,1,1,0 diff --git a/addons/payment/security/payment_security.xml b/addons/payment/security/payment_security.xml index 4de5e36f8e9..58b5f69772c 100644 --- a/addons/payment/security/payment_security.xml +++ b/addons/payment/security/payment_security.xml @@ -11,13 +11,6 @@ - - Access own transactions only - - ['|', ('partner_id', '=', False), ('partner_id', '=', user.partner_id.id)] - - - Access transactions in own companies only diff --git a/addons/sale/data/mail_template_data.xml b/addons/sale/data/mail_template_data.xml index 9adcef8dd5b..a05caacee87 100644 --- a/addons/sale/data/mail_template_data.xml +++ b/addons/sale/data/mail_template_data.xml @@ -56,13 +56,13 @@

Hello,

- + Your order S00049 amounting in $ 10.00 - + has been confirmed.
Thank you for your trust!
- + is pending. It will be confirmed when the payment is received. Your payment reference is . @@ -187,13 +187,13 @@ Payment Method: - - + + - + - ($ 10.00) + ($ 10.00) diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index e9eb31b8623..b93b7e82533 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -244,7 +244,8 @@ class SaleOrder(models.Model): comodel_name='payment.transaction', string="Authorized Transactions", compute='_compute_authorized_transaction_ids', - copy=False) + copy=False, + compute_sudo=True) # UTMs - enforcing the fact that we want to 'set null' when relation is unlinked campaign_id = fields.Many2one(ondelete='set null') @@ -1405,7 +1406,7 @@ class SaleOrder(models.Model): def get_portal_last_transaction(self): self.ensure_one() - return self.transaction_ids._get_last() + return self.transaction_ids.sudo()._get_last() def _get_order_lines_to_report(self): down_payment_lines = self.order_line.filtered(lambda line: diff --git a/addons/sale/views/sale_portal_templates.xml b/addons/sale/views/sale_portal_templates.xml index 6fbc16a5f98..51cbc3174f2 100644 --- a/addons/sale/views/sale_portal_templates.xml +++ b/addons/sale/views/sale_portal_templates.xml @@ -437,7 +437,7 @@