From 7593c073d228cad275bf33147064b56e5a799976 Mon Sep 17 00:00:00 2001 From: Laurent Desausoi Date: Thu, 22 Sep 2022 14:57:40 +0000 Subject: [PATCH] [IMP] core: use inert SQL based neutralization Before this commit the neutralize system introduced in v16 was using ORM methods in order to change appropriate records. Although flexible, this approach could lead to call some methods with side effects while neutralizing (eg: overloads of write). This patch converts the neutralize system to a safer "inert" SQL based approach by migrating the generic method _neutralize to SQL files exposed in the data folder. Task id: 2961687 closes odoo/odoo#102792 X-original-commit: e5dbded9bb363351feff7ca8a56c7f8a6860f492 Related: odoo/enterprise#32580 Signed-off-by: Fabien Meghazi --- .../data/neutralize.sql | 5 +++ .../models/account_edi_proxy_user.py | 10 ----- addons/auth_oauth/data/neutralize.sql | 3 ++ addons/auth_oauth/models/auth_oauth.py | 6 --- addons/delivery/data/neutralize.sql | 4 ++ addons/delivery/models/delivery_carrier.py | 13 ------ .../delivery/tests/test_packing_delivery.py | 6 --- addons/iap/data/neutralize.sql | 4 ++ addons/iap/models/iap_account.py | 23 ----------- addons/l10n_eg_edi_eta/data/neutralize.sql | 4 ++ addons/l10n_eg_edi_eta/models/res_company.py | 14 ------- addons/l10n_es_edi_sii/data/neutralize.sql | 3 ++ addons/l10n_es_edi_sii/models/res_company.py | 6 --- addons/l10n_es_edi_sii/tests/__init__.py | 1 - .../l10n_es_edi_sii/tests/test_neutralize.py | 15 ------- addons/l10n_in_edi/data/neutralize.sql | 7 ++++ addons/l10n_in_edi/models/res_company.py | 12 ------ addons/mail/data/neutralize.sql | 3 ++ addons/mail/models/mail_template.py | 10 ----- addons/mail/tests/test_mail_render.py | 16 -------- .../partner_autocomplete/data/neutralize.sql | 4 ++ .../partner_autocomplete/models/__init__.py | 1 - .../models/iap_account.py | 10 ----- addons/partner_autocomplete/tests/__init__.py | 1 - .../tests/test_neutralize.py | 17 -------- addons/payment/data/neutralize.sql | 4 ++ addons/payment/models/payment_provider.py | 28 ------------- addons/payment_adyen/data/neutralize.sql | 5 +++ .../payment_adyen/models/payment_provider.py | 8 ---- addons/payment_adyen/tests/test_adyen.py | 7 ---- addons/payment_alipay/data/neutralize.sql | 5 +++ .../payment_alipay/models/payment_provider.py | 8 ---- addons/payment_alipay/tests/test_alipay.py | 7 ---- addons/payment_aps/data/neutralize.sql | 6 +++ addons/payment_aps/models/payment_provider.py | 9 ---- addons/payment_aps/tests/__init__.py | 1 - .../tests/test_payment_provider.py | 16 -------- addons/payment_asiapay/data/neutralize.sql | 6 +++ .../models/payment_provider.py | 9 ---- .../tests/test_payment_provider.py | 8 ---- addons/payment_authorize/data/neutralize.sql | 6 +++ .../models/payment_provider.py | 9 ---- .../payment_authorize/tests/test_authorize.py | 8 ---- addons/payment_buckaroo/data/neutralize.sql | 4 ++ .../models/payment_provider.py | 4 -- .../payment_buckaroo/tests/test_buckaroo.py | 6 --- .../payment_flutterwave/data/neutralize.sql | 5 +++ .../models/payment_provider.py | 8 ---- .../tests/test_payment_provider.py | 6 --- .../payment_mercado_pago/data/neutralize.sql | 3 ++ .../models/payment_provider.py | 7 ---- .../tests/test_payment_provider.py | 5 --- addons/payment_ogone/data/neutralize.sql | 7 ++++ .../payment_ogone/models/payment_provider.py | 10 ----- addons/payment_ogone/tests/test_ogone.py | 9 ---- addons/payment_paypal/data/neutralize.sql | 5 +++ .../payment_paypal/models/payment_provider.py | 8 ---- addons/payment_paypal/tests/test_paypal.py | 7 ---- addons/payment_payulatam/data/neutralize.sql | 5 +++ .../models/payment_provider.py | 8 ---- .../payment_payulatam/tests/test_payulatam.py | 7 ---- addons/payment_payumoney/data/neutralize.sql | 4 ++ .../models/payment_provider.py | 4 -- .../payment_payumoney/tests/test_payumoney.py | 6 --- addons/payment_razorpay/data/neutralize.sql | 5 +++ .../models/payment_provider.py | 8 ---- .../tests/test_payment_provider.py | 7 ---- addons/payment_sips/data/neutralize.sql | 4 ++ .../payment_sips/models/payment_provider.py | 4 -- addons/payment_sips/tests/test_sips.py | 6 --- addons/payment_stripe/data/neutralize.sql | 5 +++ .../payment_stripe/models/payment_provider.py | 8 ---- addons/payment_stripe/tests/test_stripe.py | 7 ---- addons/pos_adyen/data/neutralize.sql | 3 ++ addons/sms/data/neutralize.sql | 4 ++ addons/sms/models/__init__.py | 1 - addons/sms/models/iap_account.py | 10 ----- addons/sms/tests/__init__.py | 1 - addons/sms/tests/test_neutralize.py | 17 -------- addons/snailmail/data/neutralize.sql | 4 ++ addons/snailmail/models/__init__.py | 1 - addons/snailmail/models/iap_account.py | 10 ----- addons/snailmail/tests/__init__.py | 4 -- addons/snailmail/tests/test_neutralize.py | 17 -------- addons/web/__manifest__.py | 1 + addons/web/data/neutralize.sql | 4 ++ addons/web/views/neutralize_views.xml | 19 +++++++++ addons/website/__manifest__.py | 1 + addons/website/data/neutralize.sql | 8 ++++ addons/website/models/website.py | 9 ---- addons/website/views/neutralize_views.xml | 29 +++++++++++++ .../data/neutralize.sql | 4 ++ .../website_crm_iap_reveal/models/__init__.py | 1 - .../models/iap_account.py | 10 ----- .../website_crm_iap_reveal/tests/__init__.py | 1 - .../tests/test_neutralize.py | 15 ------- odoo/addons/base/data/neutralize.sql | 19 +++++++++ odoo/addons/base/models/ir_cron.py | 13 ------ odoo/addons/base/models/ir_mail_server.py | 6 --- odoo/addons/base/tests/__init__.py | 1 + odoo/addons/base/tests/test_neutralize.py | 17 ++++++++ odoo/cli/neutralize.py | 41 +++++++++++-------- odoo/cli/neutralize_watermarks.xml | 39 ------------------ odoo/models.py | 6 --- odoo/modules/__init__.py | 2 +- odoo/modules/neutralize.py | 21 ++++++++++ 106 files changed, 275 insertions(+), 594 deletions(-) create mode 100644 addons/account_edi_proxy_client/data/neutralize.sql create mode 100644 addons/auth_oauth/data/neutralize.sql create mode 100644 addons/delivery/data/neutralize.sql create mode 100644 addons/iap/data/neutralize.sql create mode 100644 addons/l10n_eg_edi_eta/data/neutralize.sql create mode 100644 addons/l10n_es_edi_sii/data/neutralize.sql delete mode 100644 addons/l10n_es_edi_sii/tests/test_neutralize.py create mode 100644 addons/l10n_in_edi/data/neutralize.sql create mode 100644 addons/mail/data/neutralize.sql create mode 100644 addons/partner_autocomplete/data/neutralize.sql delete mode 100644 addons/partner_autocomplete/models/iap_account.py delete mode 100644 addons/partner_autocomplete/tests/test_neutralize.py create mode 100644 addons/payment/data/neutralize.sql create mode 100644 addons/payment_adyen/data/neutralize.sql create mode 100644 addons/payment_alipay/data/neutralize.sql create mode 100644 addons/payment_aps/data/neutralize.sql delete mode 100644 addons/payment_aps/tests/test_payment_provider.py create mode 100644 addons/payment_asiapay/data/neutralize.sql create mode 100644 addons/payment_authorize/data/neutralize.sql create mode 100644 addons/payment_buckaroo/data/neutralize.sql create mode 100644 addons/payment_flutterwave/data/neutralize.sql create mode 100644 addons/payment_mercado_pago/data/neutralize.sql create mode 100644 addons/payment_ogone/data/neutralize.sql create mode 100644 addons/payment_paypal/data/neutralize.sql create mode 100644 addons/payment_payulatam/data/neutralize.sql create mode 100644 addons/payment_payumoney/data/neutralize.sql create mode 100644 addons/payment_razorpay/data/neutralize.sql create mode 100644 addons/payment_sips/data/neutralize.sql create mode 100644 addons/payment_stripe/data/neutralize.sql create mode 100644 addons/pos_adyen/data/neutralize.sql create mode 100644 addons/sms/data/neutralize.sql delete mode 100644 addons/sms/models/iap_account.py delete mode 100644 addons/sms/tests/test_neutralize.py create mode 100644 addons/snailmail/data/neutralize.sql delete mode 100644 addons/snailmail/models/iap_account.py delete mode 100644 addons/snailmail/tests/__init__.py delete mode 100644 addons/snailmail/tests/test_neutralize.py create mode 100644 addons/web/data/neutralize.sql create mode 100644 addons/web/views/neutralize_views.xml create mode 100644 addons/website/data/neutralize.sql create mode 100644 addons/website/views/neutralize_views.xml create mode 100644 addons/website_crm_iap_reveal/data/neutralize.sql delete mode 100644 addons/website_crm_iap_reveal/models/iap_account.py delete mode 100644 addons/website_crm_iap_reveal/tests/test_neutralize.py create mode 100644 odoo/addons/base/data/neutralize.sql create mode 100644 odoo/addons/base/tests/test_neutralize.py delete mode 100644 odoo/cli/neutralize_watermarks.xml create mode 100644 odoo/modules/neutralize.py diff --git a/addons/account_edi_proxy_client/data/neutralize.sql b/addons/account_edi_proxy_client/data/neutralize.sql new file mode 100644 index 00000000000..e465020d6c2 --- /dev/null +++ b/addons/account_edi_proxy_client/data/neutralize.sql @@ -0,0 +1,5 @@ +-- disable edi connections in general, and the Italian one (l10n_it_edi_sdicoop) in particular +INSERT INTO ir_config_parameter (key, value) +VALUES ('account_edi_proxy_client.demo', true) + ON CONFLICT (key) DO + UPDATE SET value = true; diff --git a/addons/account_edi_proxy_client/models/account_edi_proxy_user.py b/addons/account_edi_proxy_client/models/account_edi_proxy_user.py index f35ec557b3b..a78b2b20286 100644 --- a/addons/account_edi_proxy_client/models/account_edi_proxy_user.py +++ b/addons/account_edi_proxy_client/models/account_edi_proxy_user.py @@ -206,13 +206,3 @@ class AccountEdiProxyClientUser(models.Model): ) f = Fernet(key) return f.decrypt(base64.b64decode(data)) - - def _neutralize(self): - super()._neutralize() - self.env.flush_all() - self.env.invalidate_all() - self.env.cr.execute(""" - INSERT INTO ir_config_parameter(key, value) - VALUES ('account_edi_proxy_client.demo', true) - ON CONFLICT (key) DO UPDATE SET value = true - """) diff --git a/addons/auth_oauth/data/neutralize.sql b/addons/auth_oauth/data/neutralize.sql new file mode 100644 index 00000000000..2f859ace1dc --- /dev/null +++ b/addons/auth_oauth/data/neutralize.sql @@ -0,0 +1,3 @@ +-- disable oauth providers +UPDATE auth_oauth_provider + SET enabled = false; diff --git a/addons/auth_oauth/models/auth_oauth.py b/addons/auth_oauth/models/auth_oauth.py index 40cc66ab89e..268d50b388c 100644 --- a/addons/auth_oauth/models/auth_oauth.py +++ b/addons/auth_oauth/models/auth_oauth.py @@ -20,9 +20,3 @@ class AuthOAuthProvider(models.Model): css_class = fields.Char(string='CSS class', default='fa fa-fw fa-sign-in text-primary') body = fields.Char(required=True, string="Login button label", help='Link text in Login Dialog', translate=True) sequence = fields.Integer(default=10) - - def _neutralize(self): - super()._neutralize() - self.flush_model(['enabled']) - self.env.cr.execute("UPDATE auth_oauth_provider SET enabled = false") - self.invalidate_model(['enabled']) diff --git a/addons/delivery/data/neutralize.sql b/addons/delivery/data/neutralize.sql new file mode 100644 index 00000000000..0aa2776e7eb --- /dev/null +++ b/addons/delivery/data/neutralize.sql @@ -0,0 +1,4 @@ +-- disable delivery carriers +UPDATE delivery_carrier + SET prod_environment = false, + active = false; diff --git a/addons/delivery/models/delivery_carrier.py b/addons/delivery/models/delivery_carrier.py index ddac1a0e983..c1c755f36cf 100644 --- a/addons/delivery/models/delivery_carrier.py +++ b/addons/delivery/models/delivery_carrier.py @@ -390,16 +390,3 @@ class DeliveryCarrier(models.Model): def _product_price_to_company_currency(self, quantity, product, company): return company.currency_id._convert(quantity * product.standard_price, product.currency_id, company, fields.Date.today()) - - # -------------------------- # - # neutralize # - # -------------------------- # - - def _neutralize(self): - super()._neutralize() - self.flush_model() - self.invalidate_model() - self.env.cr.execute(""" - UPDATE delivery_carrier - SET prod_environment = false, active = false - """) diff --git a/addons/delivery/tests/test_packing_delivery.py b/addons/delivery/tests/test_packing_delivery.py index 82e51f442d9..e4710c705e8 100644 --- a/addons/delivery/tests/test_packing_delivery.py +++ b/addons/delivery/tests/test_packing_delivery.py @@ -76,9 +76,3 @@ class TestPacking(TestPackingCommon): # default weight was set. pack_wiz = self.env['choose.delivery.package'].with_context(pack_action_ctx).create({}) self.assertEqual(pack_wiz.shipping_weight, 13.5) - - def test_delivery_carrier_neutralize(self): - """ ensure that devlivery carriers can be nautralized """ - self.assertTrue(self.test_carrier.active) - self.env['delivery.carrier']._neutralize() - self.assertFalse(self.test_carrier.active, "Delivery Carrier was not neutralized") diff --git a/addons/iap/data/neutralize.sql b/addons/iap/data/neutralize.sql new file mode 100644 index 00000000000..8e14848e858 --- /dev/null +++ b/addons/iap/data/neutralize.sql @@ -0,0 +1,4 @@ +INSERT INTO ir_config_parameter (key, value) +VALUES ('iap.endpoint', 'https://iap-sandbox.odoo.com') + ON CONFLICT (key) DO + UPDATE SET value = 'https://iap-sandbox.odoo.com'; diff --git a/addons/iap/models/iap_account.py b/addons/iap/models/iap_account.py index e52dd7bbd9a..55eec6527f7 100644 --- a/addons/iap/models/iap_account.py +++ b/addons/iap/models/iap_account.py @@ -130,26 +130,3 @@ class IapAccount(models.Model): credit = -1 return credit - - def _neutralize(self): - super()._neutralize() - self.env.flush_all() - self.env.invalidate_all() - - self.env.cr.execute(""" - INSERT INTO ir_config_parameter(key, value) - VALUES ('iap.endpoint', 'https://iap-sandbox.odoo.com') - ON CONFLICT (key) DO UPDATE SET value = 'https://iap-sandbox.odoo.com' - """) - - iap_service_endpoints = self._get_iap_config_parameters() - if iap_service_endpoints: - self.env.cr.execute(""" - UPDATE ir_config_parameter - SET value = 'https://iap-services-test.odoo.com' - WHERE key IN %s - """, [tuple(iap_service_endpoints)]) - - def _get_iap_config_parameters(self): - """override this method to extend the list with each parameter""" - return [] diff --git a/addons/l10n_eg_edi_eta/data/neutralize.sql b/addons/l10n_eg_edi_eta/data/neutralize.sql new file mode 100644 index 00000000000..5d7ed847c9e --- /dev/null +++ b/addons/l10n_eg_edi_eta/data/neutralize.sql @@ -0,0 +1,4 @@ +-- disable l10n_eg_edi_eta integration +UPDATE res_company + SET l10n_eg_production_env = false, + l10n_eg_client_secret = 'dummy'; diff --git a/addons/l10n_eg_edi_eta/models/res_company.py b/addons/l10n_eg_edi_eta/models/res_company.py index f4e77c6fdb0..74b75361a7e 100644 --- a/addons/l10n_eg_edi_eta/models/res_company.py +++ b/addons/l10n_eg_edi_eta/models/res_company.py @@ -14,17 +14,3 @@ class ResCompany(models.Model): l10n_eg_invoicing_threshold = fields.Float('Invoicing Threshold', default=0.0, help="Threshold at which you are required to give the VAT number " "of the customer. ") - - # ------------------------------------------------------------ - # neutralize - # ------------------------------------------------------------ - - def _neutralize(self): - super()._neutralize() - self.flush_model() - self.invalidate_model() - self.env.cr.execute(""" - UPDATE res_company - SET l10n_eg_production_env = False, - l10n_eg_client_secret = 'dummy' - """) diff --git a/addons/l10n_es_edi_sii/data/neutralize.sql b/addons/l10n_es_edi_sii/data/neutralize.sql new file mode 100644 index 00000000000..26cb30177b7 --- /dev/null +++ b/addons/l10n_es_edi_sii/data/neutralize.sql @@ -0,0 +1,3 @@ +-- disable_l10n_es_edi_integration +UPDATE res_company + SET l10n_es_edi_test_env = true; diff --git a/addons/l10n_es_edi_sii/models/res_company.py b/addons/l10n_es_edi_sii/models/res_company.py index 193580c4bc7..a8bc527e357 100644 --- a/addons/l10n_es_edi_sii/models/res_company.py +++ b/addons/l10n_es_edi_sii/models/res_company.py @@ -43,9 +43,3 @@ class ResCompany(models.Model): ) else: company.l10n_es_edi_certificate_id = False - - def _neutralize(self): - super()._neutralize() - self.flush_model() - self.invalidate_model() - self.env.cr.execute("UPDATE res_company SET l10n_es_edi_test_env = true") diff --git a/addons/l10n_es_edi_sii/tests/__init__.py b/addons/l10n_es_edi_sii/tests/__init__.py index cbd129afd8a..78cb5d78f6d 100644 --- a/addons/l10n_es_edi_sii/tests/__init__.py +++ b/addons/l10n_es_edi_sii/tests/__init__.py @@ -2,4 +2,3 @@ from . import test_edi_xml from . import test_edi_web_services -from . import test_neutralize diff --git a/addons/l10n_es_edi_sii/tests/test_neutralize.py b/addons/l10n_es_edi_sii/tests/test_neutralize.py deleted file mode 100644 index c3af2ab20b6..00000000000 --- a/addons/l10n_es_edi_sii/tests/test_neutralize.py +++ /dev/null @@ -1,15 +0,0 @@ -# Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.tests.common import tagged, TransactionCase - - -@tagged('post_install_l10n', 'post_install', '-at_install') -class TestL10nEsEdiNeutralize(TransactionCase): - - def test_l10n_es_edi_neutralize(self): - ar_company = self.env['res.company'].create({ - 'name': 'Test ES Company', - 'l10n_es_edi_test_env': False, - }) - - self.env['res.company']._neutralize() - self.assertEqual(ar_company.l10n_es_edi_test_env, True) diff --git a/addons/l10n_in_edi/data/neutralize.sql b/addons/l10n_in_edi/data/neutralize.sql new file mode 100644 index 00000000000..2520fc40a1d --- /dev/null +++ b/addons/l10n_in_edi/data/neutralize.sql @@ -0,0 +1,7 @@ +-- disable l10n_in_edi integration +UPDATE res_company + SET l10n_in_edi_production_env = false, + l10n_in_edi_username = NULL, + l10n_in_edi_password = NULL, + l10n_in_edi_token = NULL, + l10n_in_edi_token_validity = NULL; diff --git a/addons/l10n_in_edi/models/res_company.py b/addons/l10n_in_edi/models/res_company.py index 4aad50bd07b..9582f53c049 100644 --- a/addons/l10n_in_edi/models/res_company.py +++ b/addons/l10n_in_edi/models/res_company.py @@ -22,15 +22,3 @@ class ResCompany(models.Model): if self.l10n_in_edi_token and self.l10n_in_edi_token_validity > fields.Datetime.now(): return True return False - - def _neutralize(self): - super()._neutralize() - self.flush_model() - self.invalidate_model() - self.env.cr.execute("""UPDATE res_company SET - l10n_in_edi_production_env = false, - l10n_in_edi_username = Null, - l10n_in_edi_password = Null, - l10n_in_edi_token = Null, - l10n_in_edi_token_validity = Null - """) diff --git a/addons/mail/data/neutralize.sql b/addons/mail/data/neutralize.sql new file mode 100644 index 00000000000..ac5fd96a584 --- /dev/null +++ b/addons/mail/data/neutralize.sql @@ -0,0 +1,3 @@ +-- deactivate mail template +UPDATE mail_template + SET mail_server_id = NULL; diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 16b191b859d..3939d56ae4c 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -401,13 +401,3 @@ class MailTemplate(models.Model): if force_send: mail.send(raise_exception=raise_exception) return mail.id # TDE CLEANME: return mail + api.returns ? - - # ------------------------------------------------------------ - # neutralize - # ------------------------------------------------------------ - - def _neutralize(self): - super()._neutralize() - self.flush_model() - self.invalidate_model() - self.env.cr.execute("UPDATE mail_template SET mail_server_id=NULL") diff --git a/addons/mail/tests/test_mail_render.py b/addons/mail/tests/test_mail_render.py index 7a601f87a35..acb7b45a02c 100644 --- a/addons/mail/tests/test_mail_render.py +++ b/addons/mail/tests/test_mail_render.py @@ -450,19 +450,3 @@ class TestMailRender(common.MailCommon): self.assertEqual(result, '''
foobar
body''') - - def test_mail_template_neutralize(self): - """ ensure mail templates can be neutralized """ - fake_mail_server = self.env['ir.mail_server'].create({ - 'name': "fake test email server", - 'smtp_host': "mail.example.com", - 'smtp_port': 15626, - }) - self.test_template.mail_server_id = fake_mail_server - self.env['mail.template']._neutralize() - self.assertFalse(self.test_template.mail_server_id) - - # bonus test mail server neutralize too - self.assertTrue(fake_mail_server.active) - self.env['ir.mail_server']._neutralize() - self.assertFalse(fake_mail_server.active) diff --git a/addons/partner_autocomplete/data/neutralize.sql b/addons/partner_autocomplete/data/neutralize.sql new file mode 100644 index 00000000000..0812a25a6e6 --- /dev/null +++ b/addons/partner_autocomplete/data/neutralize.sql @@ -0,0 +1,4 @@ +INSERT INTO ir_config_parameter (key, value) +VALUES ('iap.partner_autocomplete.endpoint', 'https://iap-services-test.odoo.com') + ON CONFLICT (key) DO + UPDATE SET value = 'https://iap-services-test.odoo.com'; diff --git a/addons/partner_autocomplete/models/__init__.py b/addons/partner_autocomplete/models/__init__.py index dadf1cd7c8b..2932a119805 100644 --- a/addons/partner_autocomplete/models/__init__.py +++ b/addons/partner_autocomplete/models/__init__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import iap_account from . import iap_autocomplete_api from . import ir_http from . import res_partner diff --git a/addons/partner_autocomplete/models/iap_account.py b/addons/partner_autocomplete/models/iap_account.py deleted file mode 100644 index d5958c5a4c5..00000000000 --- a/addons/partner_autocomplete/models/iap_account.py +++ /dev/null @@ -1,10 +0,0 @@ -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import models - - -class IapAccount(models.Model): - _inherit = 'iap.account' - - def _get_iap_config_parameters(self): - return super()._get_iap_config_parameters() + ['iap.partner_autocomplete.endpoint'] diff --git a/addons/partner_autocomplete/tests/__init__.py b/addons/partner_autocomplete/tests/__init__.py index 5a13878239c..15d64f46f30 100644 --- a/addons/partner_autocomplete/tests/__init__.py +++ b/addons/partner_autocomplete/tests/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import test_neutralize from . import test_res_company diff --git a/addons/partner_autocomplete/tests/test_neutralize.py b/addons/partner_autocomplete/tests/test_neutralize.py deleted file mode 100644 index 675cbc392a4..00000000000 --- a/addons/partner_autocomplete/tests/test_neutralize.py +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.tests.common import TransactionCase - - -class TestPartnerAutocompleteNeutralize(TransactionCase): - - def test_partner_autocomplete_neutralize(self): - iap_key = 'iap.partner_autocomplete.endpoint' - self.env['ir.config_parameter'].create({ - 'key': iap_key, - 'value': 'fake test iap partner autocomplete endpoint' - }) - - self.env['iap.account']._neutralize() - self.assertEqual(self.env['ir.config_parameter'].get_param(iap_key), 'https://iap-services-test.odoo.com') diff --git a/addons/payment/data/neutralize.sql b/addons/payment/data/neutralize.sql new file mode 100644 index 00000000000..98d2c432aa5 --- /dev/null +++ b/addons/payment/data/neutralize.sql @@ -0,0 +1,4 @@ +-- disable generic payment provider +UPDATE payment_provider + SET state = 'disabled' + WHERE state NOT IN ('test', 'disabled'); diff --git a/addons/payment/models/payment_provider.py b/addons/payment/models/payment_provider.py index e67efd2195f..50e20dc1981 100644 --- a/addons/payment/models/payment_provider.py +++ b/addons/payment/models/payment_provider.py @@ -593,31 +593,3 @@ class PaymentProvider(models.Model): 'code': 'none', 'state': 'disabled', }) - - def _neutralize(self): - super()._neutralize() - self.flush_model() - self.invalidate_model() - self.env.cr.execute(""" - UPDATE payment_provider SET state = 'disabled' - WHERE state NOT IN ('test', 'disabled') - """) - - def _neutralize_fields(self, provider_code, field_names): - """ Helper to neutralize API keys for the given provider. - - :param str provider_code: The code of the provider whose fields to neutralize. - :param list field_names: The names of the fields to neutralize. - :return: None - """ - self.flush_model() - self.invalidate_model() - query = sql.SQL(""" - UPDATE payment_provider - SET ({fields}) = ROW({vals}) - WHERE code = %s - """).format( - fields=sql.SQL(','.join(field_names)), - vals=sql.SQL(', '.join(['NULL'] * len(field_names))), - ) - self.env.cr.execute(query, (provider_code,)) diff --git a/addons/payment_adyen/data/neutralize.sql b/addons/payment_adyen/data/neutralize.sql new file mode 100644 index 00000000000..898755807a3 --- /dev/null +++ b/addons/payment_adyen/data/neutralize.sql @@ -0,0 +1,5 @@ +-- disable adyen payment provider +UPDATE payment_provider + SET adyen_merchant_account = NULL, + adyen_api_key = NULL, + adyen_hmac_key = NULL; diff --git a/addons/payment_adyen/models/payment_provider.py b/addons/payment_adyen/models/payment_provider.py index 36086e4b026..58bcf0504cd 100644 --- a/addons/payment_adyen/models/payment_provider.py +++ b/addons/payment_adyen/models/payment_provider.py @@ -139,11 +139,3 @@ class PaymentProvider(models.Model): :rtype: str """ return f'ODOO_PARTNER_{partner_id}' - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('adyen', [ - 'adyen_merchant_account', - 'adyen_api_key', - 'adyen_hmac_key', - ]) diff --git a/addons/payment_adyen/tests/test_adyen.py b/addons/payment_adyen/tests/test_adyen.py index 4b3dc53bf9c..71e1087386a 100644 --- a/addons/payment_adyen/tests/test_adyen.py +++ b/addons/payment_adyen/tests/test_adyen.py @@ -334,10 +334,3 @@ class AdyenTest(AdyenCommon, PaymentHttpCommon): payload = dict(self.webhook_notification_payload, additionalData={'hmacSignature': 'dummy'}) tx = self._create_transaction('direct') self.assertRaises(Forbidden, AdyenController._verify_notification_signature, payload, tx) - - def test_adyen_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.adyen_merchant_account, False) - self.assertEqual(self.provider.adyen_api_key, False) - self.assertEqual(self.provider.adyen_hmac_key, False) diff --git a/addons/payment_alipay/data/neutralize.sql b/addons/payment_alipay/data/neutralize.sql new file mode 100644 index 00000000000..f815d7805de --- /dev/null +++ b/addons/payment_alipay/data/neutralize.sql @@ -0,0 +1,5 @@ +-- disable adyen payment provider +UPDATE payment_provider + SET alipay_merchant_partner_id = NULL, + alipay_md5_signature_key = NULL, + alipay_seller_email = NULL; diff --git a/addons/payment_alipay/models/payment_provider.py b/addons/payment_alipay/models/payment_provider.py index b124e4667f4..6af246c92b2 100644 --- a/addons/payment_alipay/models/payment_provider.py +++ b/addons/payment_alipay/models/payment_provider.py @@ -68,11 +68,3 @@ class PaymentProvider(models.Model): return 'https://mapi.alipay.com/gateway.do' else: # test environment return 'https://openapi.alipaydev.com/gateway.do' - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('alipay', [ - 'alipay_merchant_partner_id', - 'alipay_md5_signature_key', - 'alipay_seller_email', - ]) diff --git a/addons/payment_alipay/tests/test_alipay.py b/addons/payment_alipay/tests/test_alipay.py index d081efeac3d..ad697f12627 100644 --- a/addons/payment_alipay/tests/test_alipay.py +++ b/addons/payment_alipay/tests/test_alipay.py @@ -208,10 +208,3 @@ class AlipayTest(AlipayCommon, PaymentHttpCommon): tx = self._create_transaction('redirect') payload = dict(self.notification_data, sign='dummy') self.assertRaises(Forbidden, AlipayController._verify_notification_signature, payload, tx) - - def test_alipay_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.alipay_merchant_partner_id, False) - self.assertEqual(self.provider.alipay_md5_signature_key, False) - self.assertEqual(self.provider.alipay_seller_email, False) diff --git a/addons/payment_aps/data/neutralize.sql b/addons/payment_aps/data/neutralize.sql new file mode 100644 index 00000000000..a7afd7bf906 --- /dev/null +++ b/addons/payment_aps/data/neutralize.sql @@ -0,0 +1,6 @@ +-- disable aps payment provider +UPDATE payment_provider + SET aps_merchant_identifier = NULL, + aps_access_code = NULL, + aps_sha_request = NULL, + aps_sha_response = NULL; diff --git a/addons/payment_aps/models/payment_provider.py b/addons/payment_aps/models/payment_provider.py index ebc37da0242..3b4726c3d0d 100644 --- a/addons/payment_aps/models/payment_provider.py +++ b/addons/payment_aps/models/payment_provider.py @@ -58,12 +58,3 @@ class PaymentProvider(models.Model): key = self.aps_sha_response if incoming else self.aps_sha_request signing_string = ''.join([key, sign_data, key]) return hashlib.sha256(signing_string.encode()).hexdigest() - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('aps', [ - 'aps_merchant_identifier', - 'aps_access_code', - 'aps_sha_request', - 'aps_sha_response', - ]) diff --git a/addons/payment_aps/tests/__init__.py b/addons/payment_aps/tests/__init__.py index 4a36db00650..9783393de31 100644 --- a/addons/payment_aps/tests/__init__.py +++ b/addons/payment_aps/tests/__init__.py @@ -1,6 +1,5 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import common -from . import test_payment_provider from . import test_payment_transaction from . import test_processing_flows diff --git a/addons/payment_aps/tests/test_payment_provider.py b/addons/payment_aps/tests/test_payment_provider.py deleted file mode 100644 index decd008d689..00000000000 --- a/addons/payment_aps/tests/test_payment_provider.py +++ /dev/null @@ -1,16 +0,0 @@ -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.tests import tagged - -from odoo.addons.payment_aps.tests.common import APSCommon - - -@tagged('post_install', '-at_install') -class TestPaymentProvider(APSCommon): - - def test_neutralize(self): - self.env['payment.provider']._neutralize() - self.assertEqual(self.provider.aps_merchant_identifier, False) - self.assertEqual(self.provider.aps_access_code, False) - self.assertEqual(self.provider.aps_sha_request, False) - self.assertEqual(self.provider.aps_sha_response, False) diff --git a/addons/payment_asiapay/data/neutralize.sql b/addons/payment_asiapay/data/neutralize.sql new file mode 100644 index 00000000000..e9674ac07ec --- /dev/null +++ b/addons/payment_asiapay/data/neutralize.sql @@ -0,0 +1,6 @@ +-- disable asiapay payment provider +UPDATE payment_provider + SET asiapay_merchant_id = NULL, + asiapay_currency_id = NULL, + asiapay_secure_hash_secret = NULL, + asiapay_secure_hash_function = NULL; diff --git a/addons/payment_asiapay/models/payment_provider.py b/addons/payment_asiapay/models/payment_provider.py index ddf0568d3e3..8537df4cb1e 100644 --- a/addons/payment_asiapay/models/payment_provider.py +++ b/addons/payment_asiapay/models/payment_provider.py @@ -85,12 +85,3 @@ class PaymentProvider(models.Model): shasign = hashnew(self.asiapay_secure_hash_function) shasign.update(signing_string.encode()) return shasign.hexdigest() - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('asiapay', [ - 'asiapay_merchant_id', - 'asiapay_currency_id', - 'asiapay_secure_hash_secret', - 'asiapay_secure_hash_function', - ]) diff --git a/addons/payment_asiapay/tests/test_payment_provider.py b/addons/payment_asiapay/tests/test_payment_provider.py index 507de7903a8..590c0d673a6 100644 --- a/addons/payment_asiapay/tests/test_payment_provider.py +++ b/addons/payment_asiapay/tests/test_payment_provider.py @@ -37,11 +37,3 @@ class TestPaymentProvider(AsiaPayCommon): self.webhook_notification_data, incoming=True ) self.assertEqual(calculated_signature, '3e5bf55d9a23969130a6686db7aa4f0230956d0a') - - def test_neutralize(self): - """ Test that the sensitive fields of the provider are correctly neutralized. """ - self.env['payment.provider']._neutralize() - self.assertFalse(self.provider.asiapay_merchant_id) - self.assertFalse(self.provider.asiapay_currency_id) - self.assertFalse(self.provider.asiapay_secure_hash_secret) - self.assertFalse(self.provider.asiapay_secure_hash_function) diff --git a/addons/payment_authorize/data/neutralize.sql b/addons/payment_authorize/data/neutralize.sql new file mode 100644 index 00000000000..272c853ae59 --- /dev/null +++ b/addons/payment_authorize/data/neutralize.sql @@ -0,0 +1,6 @@ +-- disable authorize payment provider +UPDATE payment_provider + SET authorize_login = NULL, + authorize_transaction_key = NULL, + authorize_signature_key = NULL, + authorize_client_key = NULL; diff --git a/addons/payment_authorize/models/payment_provider.py b/addons/payment_authorize/models/payment_provider.py index 2f1f2464c88..2b4e3363abc 100644 --- a/addons/payment_authorize/models/payment_provider.py +++ b/addons/payment_authorize/models/payment_provider.py @@ -145,12 +145,3 @@ class PaymentProvider(models.Model): return res return self.authorize_currency_id - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('authorize', [ - 'authorize_login', - 'authorize_transaction_key', - 'authorize_signature_key', - 'authorize_client_key', - ]) diff --git a/addons/payment_authorize/tests/test_authorize.py b/addons/payment_authorize/tests/test_authorize.py index 4fac1bb7fff..54dc046daf0 100644 --- a/addons/payment_authorize/tests/test_authorize.py +++ b/addons/payment_authorize/tests/test_authorize.py @@ -46,11 +46,3 @@ class AuthorizeTest(AuthorizeCommon): self.assertEqual(self.authorize.authorize_currency_id, self.currency_usd) self.assertEqual(self.authorize._get_validation_amount(), 0.01) self.assertEqual(self.authorize._get_validation_currency(), self.currency_usd) - - def test_authorize_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.authorize_login, False) - self.assertEqual(self.provider.authorize_transaction_key, False) - self.assertEqual(self.provider.authorize_signature_key, False) - self.assertEqual(self.provider.authorize_client_key, False) diff --git a/addons/payment_buckaroo/data/neutralize.sql b/addons/payment_buckaroo/data/neutralize.sql new file mode 100644 index 00000000000..cbcac1ea08c --- /dev/null +++ b/addons/payment_buckaroo/data/neutralize.sql @@ -0,0 +1,4 @@ +-- disable buckaroo payment provider +UPDATE payment_provider + SET buckaroo_website_key = NULL, + buckaroo_secret_key = NULL; diff --git a/addons/payment_buckaroo/models/payment_provider.py b/addons/payment_buckaroo/models/payment_provider.py index 8531195127b..e26fdafc199 100644 --- a/addons/payment_buckaroo/models/payment_provider.py +++ b/addons/payment_buckaroo/models/payment_provider.py @@ -63,7 +63,3 @@ class PaymentProvider(models.Model): sign_string += self.buckaroo_secret_key # Calculate the SHA-1 hash over the signing string return sha1(sign_string.encode('utf-8')).hexdigest() - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('buckaroo', ['buckaroo_website_key', 'buckaroo_secret_key']) diff --git a/addons/payment_buckaroo/tests/test_buckaroo.py b/addons/payment_buckaroo/tests/test_buckaroo.py index 2a1f3520b95..2c45a3bde98 100644 --- a/addons/payment_buckaroo/tests/test_buckaroo.py +++ b/addons/payment_buckaroo/tests/test_buckaroo.py @@ -140,9 +140,3 @@ class BuckarooTest(BuckarooCommon, PaymentHttpCommon): '937cca8f486b75e93df1e9811a5ebf43357fc3f2', msg="The signing string items should be ordered based on a lower-case copy of the keys", ) - - def test_buckaroo_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.buckaroo_website_key, False) - self.assertEqual(self.provider.buckaroo_secret_key, False) diff --git a/addons/payment_flutterwave/data/neutralize.sql b/addons/payment_flutterwave/data/neutralize.sql new file mode 100644 index 00000000000..5f774164000 --- /dev/null +++ b/addons/payment_flutterwave/data/neutralize.sql @@ -0,0 +1,5 @@ +-- disable flutterwave payment provider +UPDATE payment_provider + SET flutterwave_public_key = NULL, + flutterwave_secret_key = NULL, + flutterwave_webhook_secret = NULL; diff --git a/addons/payment_flutterwave/models/payment_provider.py b/addons/payment_flutterwave/models/payment_provider.py index fe9926a1586..0d05e92c1eb 100644 --- a/addons/payment_flutterwave/models/payment_provider.py +++ b/addons/payment_flutterwave/models/payment_provider.py @@ -99,11 +99,3 @@ class PaymentProvider(models.Model): "Flutterwave: " + _("Could not establish the connection to the API.") ) return response.json() - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('flutterwave', [ - 'flutterwave_public_key', - 'flutterwave_secret_key', - 'flutterwave_webhook_secret', - ]) diff --git a/addons/payment_flutterwave/tests/test_payment_provider.py b/addons/payment_flutterwave/tests/test_payment_provider.py index eab8e012093..a7a8dec0d1a 100644 --- a/addons/payment_flutterwave/tests/test_payment_provider.py +++ b/addons/payment_flutterwave/tests/test_payment_provider.py @@ -19,9 +19,3 @@ class TestPaymentProvider(FlutterwaveCommon): self.company_id, self.partner.id, 0., is_validation=True ) self.assertNotIn(self.flutterwave, compatible_providers) - - def test_neutralize(self): - self.env['payment.provider']._neutralize() - self.assertEqual(self.provider.flutterwave_public_key, False) - self.assertEqual(self.provider.flutterwave_secret_key, False) - self.assertEqual(self.provider.flutterwave_webhook_secret, False) diff --git a/addons/payment_mercado_pago/data/neutralize.sql b/addons/payment_mercado_pago/data/neutralize.sql new file mode 100644 index 00000000000..aa6b90f1cf3 --- /dev/null +++ b/addons/payment_mercado_pago/data/neutralize.sql @@ -0,0 +1,3 @@ +-- disable mercado_pago payment provider +UPDATE payment_provider + SET mercado_pago_access_token = NULL; diff --git a/addons/payment_mercado_pago/models/payment_provider.py b/addons/payment_mercado_pago/models/payment_provider.py index 7897862d9e5..1e963422560 100644 --- a/addons/payment_mercado_pago/models/payment_provider.py +++ b/addons/payment_mercado_pago/models/payment_provider.py @@ -80,10 +80,3 @@ class Paymentprovider(models.Model): "Mercado Pago: " + _("Could not establish the connection to the API.") ) return response.json() - - def _neutralize(self): - super()._neutralize() - - self._neutralize_fields('mercado_pago', [ - 'mercado_pago_access_token', - ]) diff --git a/addons/payment_mercado_pago/tests/test_payment_provider.py b/addons/payment_mercado_pago/tests/test_payment_provider.py index 110aa299fc6..97618c968cd 100644 --- a/addons/payment_mercado_pago/tests/test_payment_provider.py +++ b/addons/payment_mercado_pago/tests/test_payment_provider.py @@ -15,8 +15,3 @@ class TestPaymentProvider(MercadoPagoCommon): self.company_id, self.partner.id, self.amount, currency_id=self.env.ref('base.AFN').id ) self.assertNotIn(self.provider, compatible_providers) - - def test_neutralize(self): - """ Test that the sensitive fields of the provider are correctly neutralized. """ - self.env['payment.provider']._neutralize() - self.assertFalse(self.provider.mercado_pago_access_token) diff --git a/addons/payment_ogone/data/neutralize.sql b/addons/payment_ogone/data/neutralize.sql new file mode 100644 index 00000000000..f06010282e1 --- /dev/null +++ b/addons/payment_ogone/data/neutralize.sql @@ -0,0 +1,7 @@ +-- disable ogone payment provider +UPDATE payment_provider + SET ogone_pspid = NULL, + ogone_userid = NULL, + ogone_password = NULL, + ogone_shakey_in = NULL, + ogone_shakey_out = NULL; diff --git a/addons/payment_ogone/models/payment_provider.py b/addons/payment_ogone/models/payment_provider.py index 3cc661d579a..d5a971bfe5d 100644 --- a/addons/payment_ogone/models/payment_provider.py +++ b/addons/payment_ogone/models/payment_provider.py @@ -131,13 +131,3 @@ class PaymentProvider(models.Model): _logger.exception("invalid API request at %s with data %s", url, payload) raise ValidationError("Ogone: " + _("The communication with the API failed.")) return response.content - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('ogone', [ - 'ogone_pspid', - 'ogone_userid', - 'ogone_password', - 'ogone_shakey_in', - 'ogone_shakey_out', - ]) diff --git a/addons/payment_ogone/tests/test_ogone.py b/addons/payment_ogone/tests/test_ogone.py index 9c5fd4535ee..85091fb092c 100644 --- a/addons/payment_ogone/tests/test_ogone.py +++ b/addons/payment_ogone/tests/test_ogone.py @@ -164,12 +164,3 @@ class OgoneTest(OgoneCommon, PaymentHttpCommon): 'dummy', tx, ) - - def test_ogone_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.ogone_pspid, False) - self.assertEqual(self.provider.ogone_userid, False) - self.assertEqual(self.provider.ogone_password, False) - self.assertEqual(self.provider.ogone_shakey_in, False) - self.assertEqual(self.provider.ogone_shakey_out, False) diff --git a/addons/payment_paypal/data/neutralize.sql b/addons/payment_paypal/data/neutralize.sql new file mode 100644 index 00000000000..5e56d33b333 --- /dev/null +++ b/addons/payment_paypal/data/neutralize.sql @@ -0,0 +1,5 @@ +-- disable paypal payment provider +UPDATE payment_provider + SET paypal_email_account = NULL, + paypal_seller_account = NULL, + paypal_pdt_token = NULL; diff --git a/addons/payment_paypal/models/payment_provider.py b/addons/payment_paypal/models/payment_provider.py index 63dd8fcab05..3f48840256d 100644 --- a/addons/payment_paypal/models/payment_provider.py +++ b/addons/payment_paypal/models/payment_provider.py @@ -77,11 +77,3 @@ class PaymentProvider(models.Model): 'author_id': self.create_uid.partner_id.id, } self.env['mail.mail'].sudo().create(mail_values).send() - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('paypal', [ - 'paypal_email_account', - 'paypal_seller_account', - 'paypal_pdt_token', - ]) diff --git a/addons/payment_paypal/tests/test_paypal.py b/addons/payment_paypal/tests/test_paypal.py index 4cced442f16..e28bc862daf 100644 --- a/addons/payment_paypal/tests/test_paypal.py +++ b/addons/payment_paypal/tests/test_paypal.py @@ -154,10 +154,3 @@ class PaypalTest(PaypalCommon, PaymentHttpCommon): ): self._make_http_post_request(url, data=self.notification_data) self.assertEqual(origin_check_mock.call_count, 1) - - def test_paypal_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.paypal_email_account, False) - self.assertEqual(self.provider.paypal_seller_account, False) - self.assertEqual(self.provider.paypal_pdt_token, False) diff --git a/addons/payment_payulatam/data/neutralize.sql b/addons/payment_payulatam/data/neutralize.sql new file mode 100644 index 00000000000..c1380b47303 --- /dev/null +++ b/addons/payment_payulatam/data/neutralize.sql @@ -0,0 +1,5 @@ +-- disable payulatam payment provider +UPDATE payment_provider + SET payulatam_merchant_id = NULL, + payulatam_account_id = NULL, + payulatam_api_key = NULL; diff --git a/addons/payment_payulatam/models/payment_provider.py b/addons/payment_payulatam/models/payment_provider.py index fb9b6b42096..27e58e6d342 100644 --- a/addons/payment_payulatam/models/payment_provider.py +++ b/addons/payment_payulatam/models/payment_provider.py @@ -68,11 +68,3 @@ class PaymentProvider(models.Model): values['currency'], ]) return md5(data_string.encode('utf-8')).hexdigest() - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('payulatam', [ - 'payulatam_merchant_id', - 'payulatam_account_id', - 'payulatam_api_key', - ]) diff --git a/addons/payment_payulatam/tests/test_payulatam.py b/addons/payment_payulatam/tests/test_payulatam.py index 0c1f2a15bb0..1acd7057a67 100644 --- a/addons/payment_payulatam/tests/test_payulatam.py +++ b/addons/payment_payulatam/tests/test_payulatam.py @@ -211,10 +211,3 @@ class PayULatamTest(PayULatamCommon, PaymentHttpCommon): self.assertRaises( Forbidden, PayuLatamController._verify_notification_signature, payload, tx ) - - def test_payulatam_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.payulatam_merchant_id, False) - self.assertEqual(self.provider.payulatam_account_id, False) - self.assertEqual(self.provider.payulatam_api_key, False) diff --git a/addons/payment_payumoney/data/neutralize.sql b/addons/payment_payumoney/data/neutralize.sql new file mode 100644 index 00000000000..556026c9016 --- /dev/null +++ b/addons/payment_payumoney/data/neutralize.sql @@ -0,0 +1,4 @@ +-- disable payumoney payment provider +UPDATE payment_provider + SET payumoney_merchant_key = NULL, + payumoney_merchant_salt = NULL; diff --git a/addons/payment_payumoney/models/payment_provider.py b/addons/payment_payumoney/models/payment_provider.py index e1794f91057..1d92186d832 100644 --- a/addons/payment_payumoney/models/payment_provider.py +++ b/addons/payment_payumoney/models/payment_provider.py @@ -49,7 +49,3 @@ class PaymentProvider(models.Model): keys = 'key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||salt' sign = '|'.join(f'{sign_values.get(k) or ""}' for k in keys.split('|')) return hashlib.sha512(sign.encode('utf-8')).hexdigest() - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('payumoney', ['payumoney_merchant_key', 'payumoney_merchant_salt']) diff --git a/addons/payment_payumoney/tests/test_payumoney.py b/addons/payment_payumoney/tests/test_payumoney.py index 0f54c599474..3a40174d476 100644 --- a/addons/payment_payumoney/tests/test_payumoney.py +++ b/addons/payment_payumoney/tests/test_payumoney.py @@ -81,9 +81,3 @@ class PayUMoneyTest(PayumoneyCommon, PaymentHttpCommon): self.assertRaises( Forbidden, PayUMoneyController._verify_notification_signature, payload, tx ) - - def test_payumoney_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.payumoney_merchant_key, False) - self.assertEqual(self.provider.payumoney_merchant_salt, False) diff --git a/addons/payment_razorpay/data/neutralize.sql b/addons/payment_razorpay/data/neutralize.sql new file mode 100644 index 00000000000..de7332932a5 --- /dev/null +++ b/addons/payment_razorpay/data/neutralize.sql @@ -0,0 +1,5 @@ +-- disable razorpay payment provider +UPDATE payment_provider + SET razorpay_key_id = NULL, + razorpay_key_secret = NULL, + razorpay_webhook_secret = NULL; diff --git a/addons/payment_razorpay/models/payment_provider.py b/addons/payment_razorpay/models/payment_provider.py index e2249296069..c28275515ea 100644 --- a/addons/payment_razorpay/models/payment_provider.py +++ b/addons/payment_razorpay/models/payment_provider.py @@ -121,11 +121,3 @@ class PaymentProvider(models.Model): else: # Notification data. secret = self.razorpay_webhook_secret return hmac.new(secret.encode(), msg=data, digestmod=hashlib.sha256).hexdigest() - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('razorpay', [ - 'razorpay_key_id', - 'razorpay_key_secret', - 'razorpay_webhook_secret', - ]) diff --git a/addons/payment_razorpay/tests/test_payment_provider.py b/addons/payment_razorpay/tests/test_payment_provider.py index d0ebfb9df28..92d30dacb40 100644 --- a/addons/payment_razorpay/tests/test_payment_provider.py +++ b/addons/payment_razorpay/tests/test_payment_provider.py @@ -24,10 +24,3 @@ class TestPaymentProvider(RazorpayCommon): self.assertEqual( calculated_signature, '437b72e4e87362a39951b44487cf698410b074afdbed19ec44fffd32d2f863f3' ) - - def test_neutralize(self): - """ Test that the sensitive fields of the provider are correctly neutralized. """ - self.env['payment.provider']._neutralize() - self.assertFalse(self.provider.razorpay_key_id) - self.assertFalse(self.provider.razorpay_key_secret) - self.assertFalse(self.provider.razorpay_webhook_secret) diff --git a/addons/payment_sips/data/neutralize.sql b/addons/payment_sips/data/neutralize.sql new file mode 100644 index 00000000000..6c10073727d --- /dev/null +++ b/addons/payment_sips/data/neutralize.sql @@ -0,0 +1,4 @@ +-- disable sips payment provider +UPDATE payment_provider + SET sips_merchant_id = NULL, + sips_secret = NULL; diff --git a/addons/payment_sips/models/payment_provider.py b/addons/payment_sips/models/payment_provider.py index dda96b1039f..6be08652f7c 100644 --- a/addons/payment_sips/models/payment_provider.py +++ b/addons/payment_sips/models/payment_provider.py @@ -54,7 +54,3 @@ class PaymentProvider(models.Model): key = self.sips_secret shasign = sha256((data + key).encode('utf-8')) return shasign.hexdigest() - - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('sips', ['sips_merchant_id', 'sips_secret']) diff --git a/addons/payment_sips/tests/test_sips.py b/addons/payment_sips/tests/test_sips.py index ee533f967ef..a482cc99519 100644 --- a/addons/payment_sips/tests/test_sips.py +++ b/addons/payment_sips/tests/test_sips.py @@ -138,9 +138,3 @@ class SipsTest(SipsCommon, PaymentHttpCommon): tx = self._create_transaction('redirect') payload = dict(self.notification_data, Seal='dummy') self.assertRaises(Forbidden, SipsController._verify_notification_signature, payload, tx) - - def test_sips_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.sips_merchant_id, False) - self.assertEqual(self.provider.sips_secret, False) diff --git a/addons/payment_stripe/data/neutralize.sql b/addons/payment_stripe/data/neutralize.sql new file mode 100644 index 00000000000..7a61528d8d1 --- /dev/null +++ b/addons/payment_stripe/data/neutralize.sql @@ -0,0 +1,5 @@ +-- disable stripe payment provider +UPDATE payment_provider + SET stripe_secret_key = NULL, + stripe_publishable_key = NULL, + stripe_webhook_secret = NULL; diff --git a/addons/payment_stripe/models/payment_provider.py b/addons/payment_stripe/models/payment_provider.py index 3bdaa1f95fa..54b6b4c4de4 100644 --- a/addons/payment_stripe/models/payment_provider.py +++ b/addons/payment_stripe/models/payment_provider.py @@ -264,14 +264,6 @@ class PaymentProvider(models.Model): """ return {} - def _neutralize(self): - super()._neutralize() - self._neutralize_fields('stripe', [ - 'stripe_secret_key', - 'stripe_publishable_key', - 'stripe_webhook_secret', - ]) - # === BUSINESS METHODS - STRIPE CONNECT ONBOARDING === # def _stripe_fetch_or_create_connected_account(self): diff --git a/addons/payment_stripe/tests/test_stripe.py b/addons/payment_stripe/tests/test_stripe.py index 56734f84bb1..ef2156d6004 100644 --- a/addons/payment_stripe/tests/test_stripe.py +++ b/addons/payment_stripe/tests/test_stripe.py @@ -114,13 +114,6 @@ class StripeTest(StripeCommon, PaymentHttpCommon): self._make_json_request(url, data=self.notification_data) self.assertEqual(signature_check_mock.call_count, 1) - def test_stripe_neutralize(self): - self.env['payment.provider']._neutralize() - - self.assertEqual(self.provider.stripe_secret_key, False) - self.assertEqual(self.provider.stripe_publishable_key, False) - self.assertEqual(self.provider.stripe_webhook_secret, False) - def test_onboarding_action_redirect_to_url(self): """ Test that the action generate and return an URL when the provider is disabled. """ with patch.object( diff --git a/addons/pos_adyen/data/neutralize.sql b/addons/pos_adyen/data/neutralize.sql new file mode 100644 index 00000000000..73e15f5368b --- /dev/null +++ b/addons/pos_adyen/data/neutralize.sql @@ -0,0 +1,3 @@ +-- disable Adyen Payement POS integration +UPDATE pos_payment_method + SET adyen_test_mode = true; diff --git a/addons/sms/data/neutralize.sql b/addons/sms/data/neutralize.sql new file mode 100644 index 00000000000..dc2dc5b0838 --- /dev/null +++ b/addons/sms/data/neutralize.sql @@ -0,0 +1,4 @@ +INSERT INTO ir_config_parameter (key, value) +VALUES ('sms.endpoint', 'https://iap-services-test.odoo.com') + ON CONFLICT (key) DO + UPDATE SET value = 'https://iap-services-test.odoo.com'; diff --git a/addons/sms/models/__init__.py b/addons/sms/models/__init__.py index 180afdbed90..c767c8d7427 100644 --- a/addons/sms/models/__init__.py +++ b/addons/sms/models/__init__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import iap_account from . import ir_actions_server from . import ir_model from . import mail_followers diff --git a/addons/sms/models/iap_account.py b/addons/sms/models/iap_account.py deleted file mode 100644 index 52abfc0b890..00000000000 --- a/addons/sms/models/iap_account.py +++ /dev/null @@ -1,10 +0,0 @@ -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import models - - -class IapAccount(models.Model): - _inherit = 'iap.account' - - def _get_iap_config_parameters(self): - return super()._get_iap_config_parameters() + ['sms.endpoint'] diff --git a/addons/sms/tests/__init__.py b/addons/sms/tests/__init__.py index d846aeb46c2..609586bec6b 100644 --- a/addons/sms/tests/__init__.py +++ b/addons/sms/tests/__init__.py @@ -2,5 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import common -from . import test_neutralize from . import test_sms_template diff --git a/addons/sms/tests/test_neutralize.py b/addons/sms/tests/test_neutralize.py deleted file mode 100644 index cb4df39b1d5..00000000000 --- a/addons/sms/tests/test_neutralize.py +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.tests.common import TransactionCase - - -class TestSmsNeutralize(TransactionCase): - - def test_sms_neutralize(self): - sms_key = 'sms.endpoint' - self.env['ir.config_parameter'].create({ - 'key': sms_key, - 'value': 'fake test sms endpoint' - }) - - self.env['iap.account']._neutralize() - self.assertEqual(self.env['ir.config_parameter'].get_param(sms_key), 'https://iap-services-test.odoo.com') diff --git a/addons/snailmail/data/neutralize.sql b/addons/snailmail/data/neutralize.sql new file mode 100644 index 00000000000..fcdc8939c01 --- /dev/null +++ b/addons/snailmail/data/neutralize.sql @@ -0,0 +1,4 @@ +INSERT INTO ir_config_parameter (key, value) +VALUES ('snailmail.endpoint', 'https://iap-services-test.odoo.com') + ON CONFLICT (key) DO + UPDATE SET value = 'https://iap-services-test.odoo.com'; diff --git a/addons/snailmail/models/__init__.py b/addons/snailmail/models/__init__.py index da01330dbf0..88cdc50e848 100644 --- a/addons/snailmail/models/__init__.py +++ b/addons/snailmail/models/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from . import iap_account from . import ir_actions_report from . import mail_message from . import mail_notification diff --git a/addons/snailmail/models/iap_account.py b/addons/snailmail/models/iap_account.py deleted file mode 100644 index 65e2609e371..00000000000 --- a/addons/snailmail/models/iap_account.py +++ /dev/null @@ -1,10 +0,0 @@ -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import models - - -class IapAccount(models.Model): - _inherit = 'iap.account' - - def _get_iap_config_parameters(self): - return super()._get_iap_config_parameters() + ['snailmail.endpoint'] diff --git a/addons/snailmail/tests/__init__.py b/addons/snailmail/tests/__init__.py deleted file mode 100644 index df749d5a467..00000000000 --- a/addons/snailmail/tests/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import test_neutralize diff --git a/addons/snailmail/tests/test_neutralize.py b/addons/snailmail/tests/test_neutralize.py deleted file mode 100644 index 6e34b1168b2..00000000000 --- a/addons/snailmail/tests/test_neutralize.py +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.tests.common import TransactionCase - - -class TestSnailMailNeutralize(TransactionCase): - - def test_snailmail_neutralize(self): - key = 'snailmail.endpoint' - self.env['ir.config_parameter'].create({ - 'key': key, - 'value': 'fake test snailmail endpoint' - }) - - self.env['iap.account']._neutralize() - self.assertEqual(self.env['ir.config_parameter'].get_param(key), 'https://iap-services-test.odoo.com') diff --git a/addons/web/__manifest__.py b/addons/web/__manifest__.py index a8fc85619a8..d7a1518906f 100644 --- a/addons/web/__manifest__.py +++ b/addons/web/__manifest__.py @@ -20,6 +20,7 @@ This module provides the core of the Odoo Web Client. 'views/base_document_layout_views.xml', 'views/speedscope_template.xml', 'views/lazy_assets.xml', + 'views/neutralize_views.xml', 'data/ir_attachment.xml', 'data/report_layout.xml', ], diff --git a/addons/web/data/neutralize.sql b/addons/web/data/neutralize.sql new file mode 100644 index 00000000000..07930bc42c5 --- /dev/null +++ b/addons/web/data/neutralize.sql @@ -0,0 +1,4 @@ +-- activate neutralization watermarks +UPDATE ir_ui_view + SET active = true + WHERE key = 'web.neutralize_banner'; diff --git a/addons/web/views/neutralize_views.xml b/addons/web/views/neutralize_views.xml new file mode 100644 index 00000000000..aa7f6b20365 --- /dev/null +++ b/addons/web/views/neutralize_views.xml @@ -0,0 +1,19 @@ + + + + diff --git a/addons/website/__manifest__.py b/addons/website/__manifest__.py index 94ef19f740e..7e38622b29d 100644 --- a/addons/website/__manifest__.py +++ b/addons/website/__manifest__.py @@ -103,6 +103,7 @@ 'views/ir_attachment_views.xml', 'views/ir_model_views.xml', 'views/res_partner_views.xml', + 'views/neutralize_views.xml', 'wizard/base_language_install_views.xml', 'wizard/website_robots.xml', ], diff --git a/addons/website/data/neutralize.sql b/addons/website/data/neutralize.sql new file mode 100644 index 00000000000..2a5cd90c53b --- /dev/null +++ b/addons/website/data/neutralize.sql @@ -0,0 +1,8 @@ +-- delete domains on websites +UPDATE website + SET domain = NULL; + +-- activate neutralization watermarks +UPDATE ir_ui_view + SET active = true + WHERE key = 'website.neutralize_ribbon'; diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 61f04b39398..c5109f976c7 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -1761,12 +1761,3 @@ class Website(models.Model): for word in re.findall(match_pattern, value): if word[0] == search[0]: yield word.lower() - - # ---------------------------------------------------------- - # ORM overrides - # ---------------------------------------------------------- - def _neutralize(self): - super()._neutralize() - self.flush_model() - self.invalidate_model() - self.env.cr.execute("UPDATE website SET domain=NULL") diff --git a/addons/website/views/neutralize_views.xml b/addons/website/views/neutralize_views.xml new file mode 100644 index 00000000000..67f431bd30b --- /dev/null +++ b/addons/website/views/neutralize_views.xml @@ -0,0 +1,29 @@ + + + + diff --git a/addons/website_crm_iap_reveal/data/neutralize.sql b/addons/website_crm_iap_reveal/data/neutralize.sql new file mode 100644 index 00000000000..b5eb7f43afc --- /dev/null +++ b/addons/website_crm_iap_reveal/data/neutralize.sql @@ -0,0 +1,4 @@ +INSERT INTO ir_config_parameter (key, value) +VALUES ('reveal.endpoint', 'https://iap-services-test.odoo.com') + ON CONFLICT (key) DO + UPDATE SET value = 'https://iap-services-test.odoo.com'; diff --git a/addons/website_crm_iap_reveal/models/__init__.py b/addons/website_crm_iap_reveal/models/__init__.py index 43835711f67..adb2668c05c 100644 --- a/addons/website_crm_iap_reveal/models/__init__.py +++ b/addons/website_crm_iap_reveal/models/__init__.py @@ -4,5 +4,4 @@ from . import crm_lead from . import crm_reveal_rule from . import crm_reveal_view -from . import iap_account from . import ir_http diff --git a/addons/website_crm_iap_reveal/models/iap_account.py b/addons/website_crm_iap_reveal/models/iap_account.py deleted file mode 100644 index 7faa332600b..00000000000 --- a/addons/website_crm_iap_reveal/models/iap_account.py +++ /dev/null @@ -1,10 +0,0 @@ -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import models - - -class IapAccount(models.Model): - _inherit = 'iap.account' - - def _get_iap_config_parameters(self): - return super()._get_iap_config_parameters() + ['reveal.endpoint'] diff --git a/addons/website_crm_iap_reveal/tests/__init__.py b/addons/website_crm_iap_reveal/tests/__init__.py index e8dcca99d39..af852259937 100644 --- a/addons/website_crm_iap_reveal/tests/__init__.py +++ b/addons/website_crm_iap_reveal/tests/__init__.py @@ -2,4 +2,3 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import test_lead_reveal -from . import test_neutralize diff --git a/addons/website_crm_iap_reveal/tests/test_neutralize.py b/addons/website_crm_iap_reveal/tests/test_neutralize.py deleted file mode 100644 index de1868897f9..00000000000 --- a/addons/website_crm_iap_reveal/tests/test_neutralize.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.tests.common import TransactionCase - - -class TestIapLeadWebsiteNeutralize(TransactionCase): - - def test_iap_lead_website_neutralize(self): - ICP = self.env['ir.config_parameter'] - key = 'reveal.endpoint' - ICP.set_param(key, 'Fake test reveal endpoint') - - self.env['iap.account']._neutralize() - self.assertEqual(ICP.get_param(key), 'https://iap-services-test.odoo.com') diff --git a/odoo/addons/base/data/neutralize.sql b/odoo/addons/base/data/neutralize.sql new file mode 100644 index 00000000000..809e1958597 --- /dev/null +++ b/odoo/addons/base/data/neutralize.sql @@ -0,0 +1,19 @@ +-- deactivate mail servers +UPDATE ir_mail_server + SET active = false; + +-- deactivate crons +UPDATE ir_cron + SET active = false + WHERE id NOT IN ( + SELECT res_id + FROM ir_model_data + WHERE model = 'ir.cron' + AND name = 'autovacuum_job' +); + +-- neutralization flag for the database +INSERT INTO ir_config_parameter (key, value) +VALUES ('database.is_neutralized', true) + ON CONFLICT (key) DO + UPDATE SET value = true; diff --git a/odoo/addons/base/models/ir_cron.py b/odoo/addons/base/models/ir_cron.py index 5d514a3f76d..a6f86423677 100644 --- a/odoo/addons/base/models/ir_cron.py +++ b/odoo/addons/base/models/ir_cron.py @@ -502,19 +502,6 @@ class ir_cron(models.Model): cr.execute('NOTIFY cron_trigger, %s', [self.env.cr.dbname]) _logger.debug("cron workers notified") - def _neutralize(self): - super()._neutralize() - self.env.flush_all() - self.env.invalidate_all() - self.env.cr.execute(""" - UPDATE ir_cron - SET active = false - WHERE id NOT IN ( - SELECT res_id FROM ir_model_data - WHERE model='ir.cron' AND name = 'autovacuum_job' - ) - """) - class ir_cron_trigger(models.Model): _name = 'ir.cron.trigger' diff --git a/odoo/addons/base/models/ir_mail_server.py b/odoo/addons/base/models/ir_mail_server.py index d254feece3b..cfe3358c658 100644 --- a/odoo/addons/base/models/ir_mail_server.py +++ b/odoo/addons/base/models/ir_mail_server.py @@ -784,9 +784,3 @@ class IrMailServer(models.Model): outgoing mail server. """ return getattr(threading.current_thread(), 'testing', False) or self.env.registry.in_test_mode() - - def _neutralize(self): - super()._neutralize() - self.env.flush_all() - self.env.invalidate_all() - self.env.cr.execute("UPDATE ir_mail_server SET active = false") diff --git a/odoo/addons/base/tests/__init__.py b/odoo/addons/base/tests/__init__.py index cbb693194df..b79ba51813f 100644 --- a/odoo/addons/base/tests/__init__.py +++ b/odoo/addons/base/tests/__init__.py @@ -53,3 +53,4 @@ from . import test_form_create from . import test_cloc from . import test_profiler from . import test_pdf +from . import test_neutralize diff --git a/odoo/addons/base/tests/test_neutralize.py b/odoo/addons/base/tests/test_neutralize.py new file mode 100644 index 00000000000..b3ea59d2326 --- /dev/null +++ b/odoo/addons/base/tests/test_neutralize.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.modules import neutralize + +from odoo.tests import tagged +from odoo.tests.common import TransactionCase + + +@tagged('post_install', '-at_install', 'neutralize') +class TestNeutralize(TransactionCase): + def test_10_neutralize(self): + """ Simply testing that none of the SQL neutralize crashes """ + installed_modules = neutralize.get_installed_modules(self.cr) + queries = neutralize.get_neutralization_queries(installed_modules) + for query in queries: + self.cr.execute(query) diff --git a/odoo/cli/neutralize.py b/odoo/cli/neutralize.py index a466af8e6cf..283dd5a20b6 100644 --- a/odoo/cli/neutralize.py +++ b/odoo/cli/neutralize.py @@ -7,8 +7,6 @@ import sys import odoo -from pathlib import Path - from . import Command _logger = logging.getLogger(__name__) @@ -20,28 +18,35 @@ class Neutralize(Command): def run(self, args): parser = odoo.tools.config.parser group = optparse.OptionGroup(parser, "Neutralize", "Neutralize the database specified by the `-d` argument.") + group.add_option("--stdout", action="store_true", dest="to_stdout", + help="Output the neutralization SQL instead of applying it") parser.add_option_group(group) - odoo.tools.config.parse_config(args) + opt = odoo.tools.config.parse_config(args) dbname = odoo.tools.config['db_name'] if not dbname: _logger.error('Neutralize command needs a database name. Use "-d" argument') sys.exit(1) - registry = odoo.registry(dbname) - _logger.info('Starting database neutralization') + if not opt.to_stdout: + _logger.info("Starting %s database neutralization", dbname) + try: - with registry.cursor() as cr: - env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) - for model in env.values(): - model._neutralize() - env['ir.config_parameter'].set_param('database.is_neutralized', True) - # Signal changes so the config parameter we just set gets updated in a - # running database without requiring a restart. - env.registry.signal_changes() - with open(Path(__file__).parent / 'neutralize_watermarks.xml', 'rb') as f: - odoo.tools.convert_xml_import(cr, "__neutralize__", f) + with odoo.sql_db.db_connect(dbname).cursor() as cursor: + installed_modules = odoo.modules.neutralize.get_installed_modules(cursor) + queries = odoo.modules.neutralize.get_neutralization_queries(installed_modules) + if opt.to_stdout: + # pylint: disable=bad-builtin + print('BEGIN;') + for query in queries: + # pylint: disable=bad-builtin + print(query.rstrip(";") + ";") + # pylint: disable=bad-builtin + print("COMMIT;") + else: + for query in queries: + cursor.execute(query) + _logger.info("Neutralization finished") except Exception: - _logger.error('An exception occured during neutralization.') - raise - _logger.info('Neutralization finished') + _logger.critical("An error occurred during the neutralization. THE DATABASE IS NOT NEUTRALIZED!") + sys.exit(1) diff --git a/odoo/cli/neutralize_watermarks.xml b/odoo/cli/neutralize_watermarks.xml deleted file mode 100644 index d3c87228c13..00000000000 --- a/odoo/cli/neutralize_watermarks.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - diff --git a/odoo/models.py b/odoo/models.py index e684da6f886..64fc2f207c0 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -6625,12 +6625,6 @@ class BaseModel(metaclass=MetaModel): records_batches.append(self.create(create_values)) return self.concat(*records_batches) - def _neutralize(self): - """ Neutralize this model's records. - This should prevent the database from connecting to external services. - """ - return - collections.abc.Set.register(BaseModel) # not exactly true as BaseModel doesn't have index or count diff --git a/odoo/modules/__init__.py b/odoo/modules/__init__.py index 4203a92a102..8b939af8f93 100644 --- a/odoo/modules/__init__.py +++ b/odoo/modules/__init__.py @@ -5,7 +5,7 @@ """ -from . import db, graph, loading, migration, module, registry +from . import db, graph, loading, migration, module, registry, neutralize from odoo.modules.loading import load_modules, reset_modules_state diff --git a/odoo/modules/neutralize.py b/odoo/modules/neutralize.py new file mode 100644 index 00000000000..856dd6db531 --- /dev/null +++ b/odoo/modules/neutralize.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import odoo + + +def get_installed_modules(cursor): + cursor.execute(''' + SELECT name + FROM ir_module_module + WHERE state IN ('installed', 'to upgrade', 'to remove'); + ''') + return [result[0] for result in cursor.fetchall()] + +def get_neutralization_queries(modules): + # neutralization for each module + for module in modules: + filename = odoo.modules.get_module_resource(module, 'data/neutralize.sql') + if filename: + with odoo.tools.misc.file_open(filename) as file: + yield file.read().strip()