|
|
@ -9,72 +9,71 @@ class ActivityCase(HttpCase): |
|
|
|
def setUp(self): |
|
|
|
super(ActivityCase, self).setUp() |
|
|
|
self.cron = self.env.ref("privacy_consent.cron_auto_consent") |
|
|
|
self.cron_mail_queue = self.env.ref( |
|
|
|
"mail.ir_cron_mail_scheduler_action") |
|
|
|
self.cron_mail_queue = self.env.ref("mail.ir_cron_mail_scheduler_action") |
|
|
|
self.sync_blacklist = self.env.ref("privacy_consent.sync_blacklist") |
|
|
|
self.mt_consent_consent_new = self.env.ref( |
|
|
|
"privacy_consent.mt_consent_consent_new") |
|
|
|
"privacy_consent.mt_consent_consent_new" |
|
|
|
) |
|
|
|
self.mt_consent_acceptance_changed = self.env.ref( |
|
|
|
"privacy_consent.mt_consent_acceptance_changed") |
|
|
|
"privacy_consent.mt_consent_acceptance_changed" |
|
|
|
) |
|
|
|
self.mt_consent_state_changed = self.env.ref( |
|
|
|
"privacy_consent.mt_consent_state_changed") |
|
|
|
"privacy_consent.mt_consent_state_changed" |
|
|
|
) |
|
|
|
# Some partners to ask for consent |
|
|
|
self.partners = self.env["res.partner"] |
|
|
|
self.partners += self.partners.create({ |
|
|
|
"name": "consent-partner-0", |
|
|
|
"email": "partner0@example.com", |
|
|
|
}) |
|
|
|
self.partners += self.partners.create({ |
|
|
|
"name": "consent-partner-1", |
|
|
|
"email": "partner1@example.com", |
|
|
|
}) |
|
|
|
self.partners += self.partners.create({ |
|
|
|
"name": "consent-partner-2", |
|
|
|
"email": "partner2@example.com", |
|
|
|
}) |
|
|
|
self.partners += self.partners.create( |
|
|
|
{"name": "consent-partner-0", "email": "partner0@example.com"} |
|
|
|
) |
|
|
|
self.partners += self.partners.create( |
|
|
|
{"name": "consent-partner-1", "email": "partner1@example.com"} |
|
|
|
) |
|
|
|
self.partners += self.partners.create( |
|
|
|
{"name": "consent-partner-2", "email": "partner2@example.com"} |
|
|
|
) |
|
|
|
# Partner without email, on purpose |
|
|
|
self.partners += self.partners.create({ |
|
|
|
"name": "consent-partner-3", |
|
|
|
}) |
|
|
|
self.partners += self.partners.create({"name": "consent-partner-3"}) |
|
|
|
# Partner with wrong email, on purpose |
|
|
|
self.partners += self.partners.create({ |
|
|
|
"name": "consent-partner-4", |
|
|
|
"email": "wrong-mail", |
|
|
|
}) |
|
|
|
self.partners += self.partners.create( |
|
|
|
{"name": "consent-partner-4", "email": "wrong-mail"} |
|
|
|
) |
|
|
|
# Blacklist some partners |
|
|
|
self.blacklists = self.env["mail.blacklist"] |
|
|
|
self.blacklists += self.blacklists._add("partner1@example.com") |
|
|
|
# Activity without consent |
|
|
|
self.activity_noconsent = self.env["privacy.activity"].create({ |
|
|
|
"name": "activity_noconsent", |
|
|
|
"description": "I'm activity 1", |
|
|
|
}) |
|
|
|
self.activity_noconsent = self.env["privacy.activity"].create( |
|
|
|
{"name": "activity_noconsent", "description": "I'm activity 1"} |
|
|
|
) |
|
|
|
# Activity with auto consent, for all partners |
|
|
|
self.activity_auto = self.env["privacy.activity"].create({ |
|
|
|
"name": "activity_auto", |
|
|
|
"description": "I'm activity auto", |
|
|
|
"subject_find": True, |
|
|
|
"subject_domain": repr([("id", "in", self.partners.ids)]), |
|
|
|
"consent_required": "auto", |
|
|
|
"default_consent": True, |
|
|
|
"server_action_id": self.sync_blacklist.id, |
|
|
|
}) |
|
|
|
self.activity_auto = self.env["privacy.activity"].create( |
|
|
|
{ |
|
|
|
"name": "activity_auto", |
|
|
|
"description": "I'm activity auto", |
|
|
|
"subject_find": True, |
|
|
|
"subject_domain": repr([("id", "in", self.partners.ids)]), |
|
|
|
"consent_required": "auto", |
|
|
|
"default_consent": True, |
|
|
|
"server_action_id": self.sync_blacklist.id, |
|
|
|
} |
|
|
|
) |
|
|
|
# Activity with manual consent, skipping partner 0 |
|
|
|
self.activity_manual = self.env["privacy.activity"].create({ |
|
|
|
"name": "activity_manual", |
|
|
|
"description": "I'm activity 3", |
|
|
|
"subject_find": True, |
|
|
|
"subject_domain": repr([("id", "in", self.partners[1:].ids)]), |
|
|
|
"consent_required": "manual", |
|
|
|
"default_consent": False, |
|
|
|
"server_action_id": self.sync_blacklist.id, |
|
|
|
}) |
|
|
|
self.activity_manual = self.env["privacy.activity"].create( |
|
|
|
{ |
|
|
|
"name": "activity_manual", |
|
|
|
"description": "I'm activity 3", |
|
|
|
"subject_find": True, |
|
|
|
"subject_domain": repr([("id", "in", self.partners[1:].ids)]), |
|
|
|
"consent_required": "manual", |
|
|
|
"default_consent": False, |
|
|
|
"server_action_id": self.sync_blacklist.id, |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
def check_activity_auto_properly_sent(self): |
|
|
|
"""Check emails sent by ``self.activity_auto``.""" |
|
|
|
consents = self.env["privacy.consent"].search([ |
|
|
|
("activity_id", "=", self.activity_auto.id), |
|
|
|
]) |
|
|
|
consents = self.env["privacy.consent"].search( |
|
|
|
[("activity_id", "=", self.activity_auto.id)] |
|
|
|
) |
|
|
|
# Check pending mails |
|
|
|
for consent in consents: |
|
|
|
self.assertEqual(consent.state, "draft") |
|
|
@ -86,36 +85,29 @@ 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 |
|
|
|
self.assertIn( |
|
|
|
"/privacy/consent/accept/", |
|
|
|
messages[expected_messages - 2].body) |
|
|
|
"/privacy/consent/accept/", messages[expected_messages - 2].body |
|
|
|
) |
|
|
|
self.assertIn( |
|
|
|
"/privacy/consent/reject/", |
|
|
|
messages[expected_messages - 2].body) |
|
|
|
"/privacy/consent/reject/", messages[expected_messages - 2].body |
|
|
|
) |
|
|
|
# Tokenized links shouldn't be logged |
|
|
|
self.assertNotIn( |
|
|
|
consent._url(True), |
|
|
|
messages[expected_messages - 2].body) |
|
|
|
self.assertNotIn( |
|
|
|
consent._url(False), |
|
|
|
messages[expected_messages - 2].body) |
|
|
|
self.assertNotIn(consent._url(True), messages[expected_messages - 2].body) |
|
|
|
self.assertNotIn(consent._url(False), messages[expected_messages - 2].body) |
|
|
|
# 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) |
|
|
@ -124,23 +116,21 @@ 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): |
|
|
|
"""If user wants to require consent, it needs subjects.""" |
|
|
|
# Test the onchange helper |
|
|
|
onchange_activity1 = self.env["privacy.activity"].new( |
|
|
|
self.activity_noconsent.copy_data()[0]) |
|
|
|
self.activity_noconsent.copy_data()[0] |
|
|
|
) |
|
|
|
self.assertFalse(onchange_activity1.subject_find) |
|
|
|
onchange_activity1.consent_required = "auto" |
|
|
|
onchange_activity1._onchange_consent_required_subject_find() |
|
|
@ -167,8 +157,7 @@ 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) |
|
|
@ -182,10 +171,15 @@ class ActivityCase(HttpCase): |
|
|
|
# Send one manual request |
|
|
|
action = consents[0].action_manual_ask() |
|
|
|
self.assertEqual(action["res_model"], "mail.compose.message") |
|
|
|
composer = self.env[action["res_model"]] \ |
|
|
|
.with_context(active_ids=consents[0].ids, |
|
|
|
active_model=consents._name, |
|
|
|
**action["context"]).create({}) |
|
|
|
composer = ( |
|
|
|
self.env[action["res_model"]] |
|
|
|
.with_context( |
|
|
|
active_ids=consents[0].ids, |
|
|
|
active_model=consents._name, |
|
|
|
**action["context"] |
|
|
|
) |
|
|
|
.create({}) |
|
|
|
) |
|
|
|
composer.onchange_template_id_wrapper() |
|
|
|
composer.send_mail() |
|
|
|
messages = consents.mapped("message_ids") - messages |
|
|
@ -193,8 +187,7 @@ 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"), |
|
|
|
[False, False, False], |
|
|
|
consents.mapped("partner_id.is_blacklisted"), [False, False, False], |
|
|
|
) |
|
|
|
# Placeholder links should be logged |
|
|
|
self.assertTrue("/privacy/consent/accept/" in messages[1].body) |
|
|
@ -214,11 +207,9 @@ class ActivityCase(HttpCase): |
|
|
|
self.assertEqual(consents.mapped("accepted"), [True, False, False]) |
|
|
|
self.assertTrue(consents[0].last_metadata) |
|
|
|
self.assertFalse(consents[0].partner_id.is_blacklisted) |
|
|
|
self.assertEqual(consents.mapped("state"), ["answered", "draft", "draft"]) |
|
|
|
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 |
|
|
@ -230,11 +221,9 @@ class ActivityCase(HttpCase): |
|
|
|
self.assertEqual(consents.mapped("accepted"), [False, False, False]) |
|
|
|
self.assertTrue(consents[0].last_metadata) |
|
|
|
self.assertTrue(consents[0].partner_id.is_blacklisted) |
|
|
|
self.assertEqual(consents.mapped("state"), ["answered", "draft", "draft"]) |
|
|
|
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) |
|
|
|
|
|
|
|