Browse Source

[MIG] privacy_consent: Migration to 14.0

pull/56/head
Valtteri Lattu 3 years ago
parent
commit
afa0615158
  1. 4
      privacy_consent/__manifest__.py
  2. 10
      privacy_consent/models/mail_mail.py
  3. 5
      privacy_consent/models/mail_template.py
  4. 15
      privacy_consent/models/privacy_activity.py
  5. 22
      privacy_consent/models/privacy_consent.py
  6. 8
      privacy_consent/models/res_partner.py
  7. 38
      privacy_consent/tests/test_consent.py
  8. 1
      setup/privacy_consent/odoo/addons/privacy_consent
  9. 6
      setup/privacy_consent/setup.py

4
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,

10
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

5
privacy_consent/models/mail_template.py

@ -30,5 +30,8 @@ class MailTemplate(models.Model):
'<a href="%s">Accept</a>\n'
'<a href="%s">Reject</a>'
)
% ("/privacy/consent/accept/", "/privacy/consent/reject/",)
% (
"/privacy/consent/accept/",
"/privacy/consent/reject/",
)
)

15
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[

22
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

8
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[

38
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)

1
setup/privacy_consent/odoo/addons/privacy_consent

@ -0,0 +1 @@
../../../../privacy_consent

6
setup/privacy_consent/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading…
Cancel
Save