Browse Source

fixup! [ADD] privacy_consent: Privacy explicit consent tracking tools

pull/11/head
Jairo Llopis 6 years ago
parent
commit
1b7af1647a
  1. 2
      privacy_consent/models/mail_template.py
  2. 28
      privacy_consent/models/privacy_activity.py
  3. 2
      privacy_consent/models/privacy_consent.py
  4. 8
      privacy_consent/models/res_partner.py
  5. 8
      privacy_consent/readme/DESCRIPTION.rst
  6. 4
      privacy_consent/security/ir.model.access.csv
  7. 16
      privacy_consent/tests/test_consent.py
  8. 2
      privacy_consent/views/privacy_activity.xml
  9. 4
      privacy_consent/views/res_partner.xml

2
privacy_consent/models/mail_template.py

@ -13,7 +13,7 @@ class MailTemplate(models.Model):
@api.constrains("body_html", "model")
def _check_consent_links_in_body_html(self):
"""Body for ``privacy.consent`` templates needs placehloder links."""
"""Body for ``privacy.consent`` templates needs placeholder links."""
links = [u"//a[@href='/privacy/consent/{}/']".format(action)
for action in ("accept", "reject")]
for one in self:

28
privacy_consent/models/privacy_activity.py

@ -24,9 +24,9 @@ class PrivacyActivity(models.Model):
"activity_id",
"Consents",
)
consent_ids_count = fields.Integer(
consent_count = fields.Integer(
"Consents",
compute="_compute_consent_ids_count",
compute="_compute_consent_count",
)
consent_required = fields.Selection(
[("auto", "Automatically"), ("manual", "Manually")],
@ -65,9 +65,15 @@ class PrivacyActivity(models.Model):
return self.env.ref("privacy_consent.template_consent", False)
@api.depends("consent_ids")
def _compute_consent_ids_count(self):
for one in self:
one.consent_ids_count = len(one.consent_ids)
def _compute_consent_count(self):
groups = self.env["privacy.consent"].read_group(
[("activity_id", "in", self.ids)],
["activity_id"],
["activity_id"],
)
for group in groups:
self.browse(group["activity_id"][0], self._prefetch) \
.consent_count = group["activity_id_count"]
def _compute_consent_template_defaults(self):
"""Used in context values, to help users design new templates."""
@ -87,10 +93,10 @@ class PrivacyActivity(models.Model):
"Specify a mail template to ask automated consent."
))
@api.constrains("consent_required", "subjects_find")
def _check_consent_required_subjects_find(self):
@api.constrains("consent_required", "subject_find")
def _check_consent_required_subject_find(self):
for one in self:
if one.consent_required and not one.subjects_find:
if one.consent_required and not one.subject_find:
raise ValidationError(_(
"Require consent is available only for subjects "
"in current database."
@ -103,10 +109,10 @@ class PrivacyActivity(models.Model):
automatic.action_new_consents()
@api.onchange("consent_required")
def _onchange_consent_required_subjects_find(self):
def _onchange_consent_required_subject_find(self):
"""Find subjects automatically if we require their consent."""
if self.consent_required:
self.subjects_find = True
self.subject_find = True
def action_new_consents(self):
"""Generate new consent requests."""
@ -114,7 +120,7 @@ class PrivacyActivity(models.Model):
# Skip activitys where consent is not required
for one in self.with_context(active_test=False) \
.filtered("consent_required"):
domain = safe_eval(one.subjects_domain)
domain = safe_eval(one.subject_domain)
domain += [
("id", "not in", one.mapped("consent_ids.partner_id").ids),
("email", "!=", False),

2
privacy_consent/models/privacy_consent.py

@ -87,7 +87,7 @@ class PrivacyConsent(models.Model):
).hexdigest()
def _url(self, accept):
"""Tokenized absolute URL to let subject decide consent.
"""Tokenized URL to let subject decide consent.
:param bool accept:
Indicates if you want the acceptance URL, or the rejection one.

8
privacy_consent/models/res_partner.py

@ -13,14 +13,14 @@ class ResPartner(models.Model):
"partner_id",
"Privacy consents",
)
privacy_consent_ids_count = fields.Integer(
privacy_consent_count = fields.Integer(
"Consents",
compute="_compute_privacy_consent_ids_count",
compute="_compute_privacy_consent_count",
help="Privacy consent requests amount",
)
@api.depends("privacy_consent_ids")
def _compute_privacy_consent_ids_count(self):
def _compute_privacy_consent_count(self):
"""Count consent requests."""
groups = self.env["privacy.consent"].read_group(
[("partner_id", "in", self.ids)],
@ -29,4 +29,4 @@ class ResPartner(models.Model):
)
for group in groups:
self.browse(group["partner_id"][0], self._prefetch) \
.privacy_consent_ids_count = group["partner_id_count"]
.privacy_consent_count = group["partner_id_count"]

8
privacy_consent/readme/DESCRIPTION.rst

@ -1,3 +1,7 @@
This module aims for GDPR compliance, enabling the user to define a set of
subjects (partners) affected by any data processing activity, and establish
This module allows the user to define a set of subjects (partners)
affected by any data processing activity, and establish
a process to ask them for consent to include them in that activity.
For those that need explicit consent as a lawfulness base for personal data
processing, as required by GDPR (article 6.1.a), this module provides the
needed tools to automate it.

4
privacy_consent/security/ir.model.access.csv

@ -1,3 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
read,Permission to read consents,model_privacy_consent,privacy.group_data_protection_user,1,0,0,0
write,Permission to write consents,model_privacy_consent,privacy.group_data_protection_manager,1,1,1,1
privacy_consent_read,Permission to read consents,model_privacy_consent,privacy.group_data_protection_user,1,0,0,0
privacy_consent_write,Permission to write consents,model_privacy_consent,privacy.group_data_protection_manager,1,1,1,1

16
privacy_consent/tests/test_consent.py

@ -59,8 +59,8 @@ class ActivityCase(HttpCase):
self.activity_auto = self.env["privacy.activity"].create({
"name": "activity_auto",
"description": "I'm activity auto",
"subjects_find": True,
"subjects_domain": repr([("id", "in", self.partners.ids)]),
"subject_find": True,
"subject_domain": repr([("id", "in", self.partners.ids)]),
"consent_required": "auto",
"default_consent": True,
"server_action_id": self.update_opt_out.id,
@ -69,8 +69,8 @@ class ActivityCase(HttpCase):
self.activity_manual = self.env["privacy.activity"].create({
"name": "activity_manual",
"description": "I'm activity 3",
"subjects_find": True,
"subjects_domain": repr([("id", "in", self.partners[1:].ids)]),
"subject_find": True,
"subject_domain": repr([("id", "in", self.partners[1:].ids)]),
"consent_required": "manual",
"default_consent": False,
"server_action_id": self.update_opt_out.id,
@ -141,17 +141,17 @@ class ActivityCase(HttpCase):
# Test the onchange helper
onchange_activity1 = self.env["privacy.activity"].new(
self.activity_noconsent.copy_data()[0])
self.assertFalse(onchange_activity1.subjects_find)
self.assertFalse(onchange_activity1.subject_find)
onchange_activity1.consent_required = "auto"
onchange_activity1._onchange_consent_required_subjects_find()
self.assertTrue(onchange_activity1.subjects_find)
onchange_activity1._onchange_consent_required_subject_find()
self.assertTrue(onchange_activity1.subject_find)
# Test very dumb user that forces an error
with self.assertRaises(ValidationError):
self.activity_noconsent.consent_required = "manual"
def test_template_required_auto(self):
"""Automatic consent activities need a template."""
self.activity_noconsent.subjects_find = True
self.activity_noconsent.subject_find = True
self.activity_noconsent.consent_template_id = False
self.activity_noconsent.consent_required = "manual"
with self.assertRaises(ValidationError):

2
privacy_consent/views/privacy_activity.xml

@ -19,7 +19,7 @@
type="action"
>
<field
name="consent_ids_count"
name="consent_count"
widget="statinfo"
/>
</button>

4
privacy_consent/views/res_partner.xml

@ -11,7 +11,7 @@
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
attrs='{"invisible": [("privacy_consent_ids_count", "=", 0)]}'
attrs='{"invisible": [("privacy_consent_count", "=", 0)]}'
class="oe_stat_button"
context='{"search_default_partner_id": active_id}'
icon="fa-envelope"
@ -19,7 +19,7 @@
type="action"
>
<field
name="privacy_consent_ids_count"
name="privacy_consent_count"
widget="statinfo"
/>
</button>

Loading…
Cancel
Save