From afa061515801558a0860b5204203a119ba2df9b8 Mon Sep 17 00:00:00 2001 From: Valtteri Lattu Date: Tue, 27 Jul 2021 15:18:31 +0300 Subject: [PATCH] [MIG] privacy_consent: Migration to 14.0 --- privacy_consent/__manifest__.py | 4 +- privacy_consent/models/mail_mail.py | 10 ++++- privacy_consent/models/mail_template.py | 5 ++- privacy_consent/models/privacy_activity.py | 15 ++++++-- privacy_consent/models/privacy_consent.py | 22 ++++++++--- privacy_consent/models/res_partner.py | 8 +++- privacy_consent/tests/test_consent.py | 38 +++++++++++++------ .../odoo/addons/privacy_consent | 1 + setup/privacy_consent/setup.py | 6 +++ 9 files changed, 83 insertions(+), 26 deletions(-) create mode 120000 setup/privacy_consent/odoo/addons/privacy_consent create mode 100644 setup/privacy_consent/setup.py diff --git a/privacy_consent/__manifest__.py b/privacy_consent/__manifest__.py index 40b1cf4..f49ac16 100644 --- a/privacy_consent/__manifest__.py +++ b/privacy_consent/__manifest__.py @@ -4,10 +4,10 @@ "name": "Privacy - Consent", "summary": "Allow people to explicitly accept or reject inclusion " "in some activity, GDPR compliant", - "version": "13.0.1.0.3", + "version": "14.0.1.0.0", "development_status": "Production/Stable", "category": "Privacy", - "website": "https://github.com/OCA/management-activity", + "website": "https://github.com/OCA/data-protection", "author": "Tecnativa, initOS GmbH, Odoo Community Association (OCA)", "license": "AGPL-3", "application": False, diff --git a/privacy_consent/models/mail_mail.py b/privacy_consent/models/mail_mail.py index 583fa38..6b49211 100644 --- a/privacy_consent/models/mail_mail.py +++ b/privacy_consent/models/mail_mail.py @@ -51,6 +51,12 @@ class MailMail(models.Model): return result # Tokenize consent links consent = self.env["privacy.consent"].browse(self.mail_message_id.res_id) - result = result.replace("/privacy/consent/accept/", consent._url(True),) - result = result.replace("/privacy/consent/reject/", consent._url(False),) + result = result.replace( + "/privacy/consent/accept/", + consent._url(True), + ) + result = result.replace( + "/privacy/consent/reject/", + consent._url(False), + ) return result diff --git a/privacy_consent/models/mail_template.py b/privacy_consent/models/mail_template.py index 207d216..fa1d704 100644 --- a/privacy_consent/models/mail_template.py +++ b/privacy_consent/models/mail_template.py @@ -30,5 +30,8 @@ class MailTemplate(models.Model): 'Accept\n' 'Reject' ) - % ("/privacy/consent/accept/", "/privacy/consent/reject/",) + % ( + "/privacy/consent/accept/", + "/privacy/consent/reject/", + ) ) diff --git a/privacy_consent/models/privacy_activity.py b/privacy_consent/models/privacy_activity.py index ebecf2c..ea79f7b 100644 --- a/privacy_consent/models/privacy_activity.py +++ b/privacy_consent/models/privacy_activity.py @@ -16,8 +16,15 @@ class PrivacyActivity(models.Model): help="Run this action when a new consent request is created or its " "acceptance status is updated.", ) - consent_ids = fields.One2many("privacy.consent", "activity_id", "Consents",) - consent_count = fields.Integer("Consents count", compute="_compute_consent_count",) + consent_ids = fields.One2many( + "privacy.consent", + "activity_id", + "Consents", + ) + consent_count = fields.Integer( + "Consents count", + compute="_compute_consent_count", + ) consent_required = fields.Selection( [("auto", "Automatically"), ("manual", "Manually")], "Ask subjects for consent", @@ -55,7 +62,9 @@ class PrivacyActivity(models.Model): def _compute_consent_count(self): self.consent_count = 0 groups = self.env["privacy.consent"].read_group( - [("activity_id", "in", self.ids)], ["activity_id"], ["activity_id"], + [("activity_id", "in", self.ids)], + ["activity_id"], + ["activity_id"], ) for group in groups: self.browse(group["activity_id"][0]).consent_count = group[ diff --git a/privacy_consent/models/privacy_consent.py b/privacy_consent/models/privacy_consent.py index e697628..0311554 100644 --- a/privacy_consent/models/privacy_consent.py +++ b/privacy_consent/models/privacy_consent.py @@ -20,7 +20,10 @@ class PrivacyConsent(models.Model): ), ] - active = fields.Boolean(default=True, index=True,) + active = fields.Boolean( + default=True, + index=True, + ) accepted = fields.Boolean( track_visibility="onchange", help="Indicates current acceptance status, which can come from " @@ -74,10 +77,15 @@ class PrivacyConsent(models.Model): """Secret token to publicly authenticate this record.""" secret = self.env["ir.config_parameter"].sudo().get_param("database.secret") params = "{}-{}-{}-{}".format( - self.env.cr.dbname, self.id, self.partner_id.id, self.activity_id.id, + self.env.cr.dbname, + self.id, + self.partner_id.id, + self.activity_id.id, ) return hmac.new( - secret.encode("utf-8"), params.encode("utf-8"), hashlib.sha512, + secret.encode("utf-8"), + params.encode("utf-8"), + hashlib.sha512, ).hexdigest() def _url(self, accept): @@ -109,7 +117,9 @@ class PrivacyConsent(models.Model): if one.state == "draft": continue action = one.activity_id.server_action_id.with_context( - active_id=one.id, active_ids=one.ids, active_model=one._name, + active_id=one.id, + active_ids=one.ids, + active_model=one._name, ) action.run() @@ -132,7 +142,9 @@ class PrivacyConsent(models.Model): reason = self._fields["partner_id"].string for one in self: one._message_add_suggested_recipient( - result, partner=one.partner_id, reason=reason, + result, + partner=one.partner_id, + reason=reason, ) return result diff --git a/privacy_consent/models/res_partner.py b/privacy_consent/models/res_partner.py index d421928..162b8a3 100644 --- a/privacy_consent/models/res_partner.py +++ b/privacy_consent/models/res_partner.py @@ -8,7 +8,9 @@ class ResPartner(models.Model): _inherit = "res.partner" privacy_consent_ids = fields.One2many( - "privacy.consent", "partner_id", "Privacy consents", + "privacy.consent", + "partner_id", + "Privacy consents", ) privacy_consent_count = fields.Integer( "Consents", @@ -21,7 +23,9 @@ class ResPartner(models.Model): """Count consent requests.""" self.privacy_consent_count = 0 groups = self.env["privacy.consent"].read_group( - [("partner_id", "in", self.ids)], ["partner_id"], ["partner_id"], + [("partner_id", "in", self.ids)], + ["partner_id"], + ["partner_id"], ) for group in groups: self.browse(group["partner_id"][0]).privacy_consent_count = group[ diff --git a/privacy_consent/tests/test_consent.py b/privacy_consent/tests/test_consent.py index 87a620a..1db8ecf 100644 --- a/privacy_consent/tests/test_consent.py +++ b/privacy_consent/tests/test_consent.py @@ -79,7 +79,13 @@ class ActivityCase(HttpCase): def _build_email(_self, email_from, email_to, subject, body, *args, **kwargs): self._built_messages.append(body) return _build_email.origin( - _self, email_from, email_to, subject, body, *args, **kwargs, + _self, + email_from, + email_to, + subject, + body, + *args, + **kwargs, ) try: @@ -105,13 +111,15 @@ class ActivityCase(HttpCase): good_email = "@" in (consent.partner_id.email or "") expected_messages = 3 if good_email else 2 self.assertEqual( - consent.state, "sent" if good_email else "draft", + consent.state, + "sent" if good_email else "draft", ) messages = consent.message_ids self.assertEqual(len(messages), expected_messages) # 2nd message notifies creation self.assertEqual( - messages[expected_messages - 1].subtype_id, self.mt_consent_consent_new, + messages[expected_messages - 1].subtype_id, + self.mt_consent_consent_new, ) # 3rd message notifies subject # Placeholder links should be logged @@ -127,7 +135,8 @@ class ActivityCase(HttpCase): # 4th message contains the state change if good_email: self.assertEqual( - messages[0].subtype_id, self.mt_consent_state_changed, + messages[0].subtype_id, + self.mt_consent_state_changed, ) # Partner's is_blacklisted should be synced with default consent self.assertFalse(consent.partner_id.is_blacklisted) @@ -144,13 +153,16 @@ class ActivityCase(HttpCase): """We have a good mail template by default.""" good = self.env.ref("privacy_consent.template_consent") self.assertEqual( - self.activity_noconsent.consent_template_id, good, + self.activity_noconsent.consent_template_id, + good, ) self.assertEqual( - self.activity_noconsent.consent_template_default_body_html, good.body_html, + self.activity_noconsent.consent_template_default_body_html, + good.body_html, ) self.assertEqual( - self.activity_noconsent.consent_template_default_subject, good.subject, + self.activity_noconsent.consent_template_default_subject, + good.subject, ) def test_find_subject_if_consent_required(self): @@ -185,7 +197,8 @@ class ActivityCase(HttpCase): consents = self.env[result["res_model"]].search(result["domain"]) self.assertEqual(consents.mapped("state"), ["draft"] * 3) self.assertEqual( - consents.mapped("partner_id.is_blacklisted"), [False] * 3, + consents.mapped("partner_id.is_blacklisted"), + [False] * 3, ) self.assertEqual(consents.mapped("accepted"), [False] * 3) self.assertEqual(consents.mapped("last_metadata"), [False] * 3) @@ -218,7 +231,8 @@ class ActivityCase(HttpCase): self.assertEqual(messages[0].subtype_id, self.mt_consent_state_changed) self.assertEqual(consents.mapped("state"), ["sent", "draft", "draft"]) self.assertEqual( - consents.mapped("partner_id.is_blacklisted"), [True, False, False], + consents.mapped("partner_id.is_blacklisted"), + [True, False, False], ) # Placeholder links should be logged self.assertTrue("/privacy/consent/accept/" in messages[1].body) @@ -240,7 +254,8 @@ class ActivityCase(HttpCase): self.assertFalse(consents[0].partner_id.is_blacklisted) self.assertEqual(consents.mapped("state"), ["answered", "draft", "draft"]) self.assertEqual( - consents[0].message_ids[0].subtype_id, self.mt_consent_acceptance_changed, + consents[0].message_ids[0].subtype_id, + self.mt_consent_acceptance_changed, ) # Visit tokenized reject URL result = self.url_open(reject_url).text @@ -254,7 +269,8 @@ class ActivityCase(HttpCase): self.assertTrue(consents[0].partner_id.is_blacklisted) self.assertEqual(consents.mapped("state"), ["answered", "draft", "draft"]) self.assertEqual( - consents[0].message_ids[0].subtype_id, self.mt_consent_acceptance_changed, + consents[0].message_ids[0].subtype_id, + self.mt_consent_acceptance_changed, ) self.assertFalse(consents[1].last_metadata) diff --git a/setup/privacy_consent/odoo/addons/privacy_consent b/setup/privacy_consent/odoo/addons/privacy_consent new file mode 120000 index 0000000..f558b8c --- /dev/null +++ b/setup/privacy_consent/odoo/addons/privacy_consent @@ -0,0 +1 @@ +../../../../privacy_consent \ No newline at end of file diff --git a/setup/privacy_consent/setup.py b/setup/privacy_consent/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/privacy_consent/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)