Browse Source

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

pull/11/head
Jairo Llopis 6 years ago
parent
commit
46a44d28c0
  1. 18
      privacy_consent/models/mail_mail.py
  2. 92
      privacy_consent/templates/form.xml
  3. 17
      privacy_consent/wizards/mail_compose_message.py

18
privacy_consent/models/mail_mail.py

@ -8,6 +8,24 @@ from odoo import models
class MailMail(models.Model):
_inherit = "mail.mail"
def _postprocess_sent_message(self, mail_sent=True):
"""Write consent status after sending message."""
if mail_sent and self.env.context.get('mark_consent_sent'):
# Get all mails sent to consents
consent_mails = self.filtered(
lambda one: one.mail_message_id.model == "privacy.consent"
)
# Get related draft consents
consents = self.env["privacy.consent"].browse(
consent_mails.mapped("mail_message_id.res_id"),
self._prefetch
).filtered(lambda one: one.state == "draft")
# Set as sent
consents.write({
"state": "sent",
})
return super(MailMail, self)._postprocess_sent_message(mail_sent)
def send_get_mail_body(self, partner=None):
"""Replace privacy consent magic links.

92
privacy_consent/templates/form.xml

@ -9,51 +9,53 @@
by website layout if website is installed, and otherwise includes
all possibly needed assets -->
<t t-call="web.login_layout">
<div class="jumbotron">
<h1>Thank you!</h1>
<p>
Hello, <b t-esc="consent.partner_id.display_name"/>
</p>
<p>
We asked you to authorize us to process your data in this data processing activity:
<b t-esc="consent.activity_id.display_name"/>
</p>
<t t-raw="consent.activity_id.description or ''"/>
<p t-if="consent.accepted">
You have <b class="text-success">accepted</b> such processing.
</p>
<p t-else="">
You have <b class="text-danger">rejected</b> such processing.
</p>
<p>
We have recorded this action on your side.
</p>
<p>
If it was a mistake, you can undo it here:
<div class="text-center">
<a
t-if="consent.accepted"
t-att-href="consent._url(False)"
class="btn btn-danger btn-lg"
>
I <b>reject</b> this processing of my data
</a>
<a
t-else=""
t-att-href="consent._url(True)"
class="btn btn-success btn-lg"
>
I <b>accept</b> this processing of my data
</a>
</div>
</p>
<p>
Thanks for your response.
</p>
<p class="text-muted">
Sincerely,<br/>
<i t-raw="consent.activity_id.controller_id.with_context(show_address=True, html_format=True).name_get()[0][1]"/>
</p>
<div class="container readable">
<div class="jumbotron">
<h1>Thank you!</h1>
<p>
Hello, <b t-esc="consent.partner_id.display_name"/>
</p>
<p>
We asked you to authorize us to process your data in this data processing activity:
<b t-esc="consent.activity_id.display_name"/>
</p>
<t t-raw="consent.activity_id.description or ''"/>
<p t-if="consent.accepted">
You have <b class="text-success">accepted</b> such processing.
</p>
<p t-else="">
You have <b class="text-danger">rejected</b> such processing.
</p>
<p>
We have recorded this action on your side.
</p>
<p>
If it was a mistake, you can undo it here:
<div class="text-center">
<a
t-if="consent.accepted"
t-att-href="consent._url(False)"
class="btn btn-danger btn-lg"
>
I <b>reject</b> this processing of my data
</a>
<a
t-else=""
t-att-href="consent._url(True)"
class="btn btn-success btn-lg"
>
I <b>accept</b> this processing of my data
</a>
</div>
</p>
<p>
Thanks for your response.
</p>
<p class="text-muted">
Sincerely,<br/>
<i t-raw="consent.activity_id.controller_id.with_context(show_address=True, html_format=True).name_get()[0][1]"/>
</p>
</div>
</div>
</t>
</template>

17
privacy_consent/wizards/mail_compose_message.py

@ -10,16 +10,7 @@ class MailComposeMessage(models.TransientModel):
@api.multi
def send_mail(self, auto_commit=False):
"""Update consent state if needed."""
result = super(MailComposeMessage, self).send_mail(
auto_commit=auto_commit)
if (self.env.context.get('active_model') == 'privacy.consent' and
self.env.context.get('active_ids') and
self.env.context.get('mark_consent_sent')):
consents = self.env['privacy.consent'].browse(
self.env.context['active_ids'],
self._prefetch,
)
consents.filtered(lambda one: one.state == "draft") \
.write({"state": "sent"})
return result
"""Force auto commit when sending consent emails."""
if self.env.context.get('mark_consent_sent'):
auto_commit = True
return super(MailComposeMessage, self).send_mail(auto_commit)
Loading…
Cancel
Save