privacy_consent: Separate automated emails send process
Before https://github.com/OCA/data-protection/pull/29 there was a race condition where an email could be sent while the same transaction that created the `privacy.consent` record still wasn't committed, producing a 404 error if the user clicked on "Accept" or "Reject" before all mails were sent.
To avoid that, a raw `cr.commit()` was issued, but this produced another situation where the user had to wait until the full email queue is cleared to get his page loaded. It wasn't an error, but a long queue meant several minutes waiting, and it's ulikely that an average human is so patient.
So, here's the final fix (I hope!). The main problem was that I was looking in the wrong place to send the email. It turns out that the `self.post_message_with_template()` method is absolutely helpless in the case at hand, where these criteria must be met:
* E-mail must be enqueued, no matter if there are less or more than 50 consents to send.
* The template must be processed per record.
* In an ideal world, a `cr.commit()` must be issued after each sent mail.
The metod that was being used:
* Didn't allow to use `auto_commit` mode.
* Only allowed to render the template per record if called with `composition_mode="mass_mail"`.
* Only allowed to enqueue emails if called with `composition_mode="mass_post"`.
Obviously, I cannot set 2 different values for `composition_mode`, so a different strategy had to be used.
I discovered that the `mail.template` model has a helpful method called `send_mail()` that, by default:
* Renders the template per record
* Enqueues the email
* The email queue is cleared in `auto_commit=True` mode.
So, from now on, problems are gone:
* The user click, or the cron run, will just generate the missing `privacy.consent` records and enqueue mails for them.
* The mail queue manager will send them later, in `auto_commit` mode.
* After sending the e-mail, this module will set the `privacy.consent` record as `sent`.
* Thanks to *not* sending the email, the process the user faces when he hits the "generate" button is faster.
* Instructions in the README and text in the "generate" button are updated to reflect this new behavior.
* Thanks to the `auto_commit` feature, if Odoo is rebooted in the middle of a mail queue clearance, the records that were sent remain properly marked as sent, and the missing mails will be sent after the next boot.
* No hardcoded commits.
* No locked transactions.
* BTW I discovered that 2 different emails were created when creating a new consent. I started using `mail_create_nolog=True` to avoid that problem and only log a single creation message.
Note to self: never use again `post_message_with_template()`.
6 years ago privacy_consent: Separate automated emails send process
Before https://github.com/OCA/data-protection/pull/29 there was a race condition where an email could be sent while the same transaction that created the `privacy.consent` record still wasn't committed, producing a 404 error if the user clicked on "Accept" or "Reject" before all mails were sent.
To avoid that, a raw `cr.commit()` was issued, but this produced another situation where the user had to wait until the full email queue is cleared to get his page loaded. It wasn't an error, but a long queue meant several minutes waiting, and it's ulikely that an average human is so patient.
So, here's the final fix (I hope!). The main problem was that I was looking in the wrong place to send the email. It turns out that the `self.post_message_with_template()` method is absolutely helpless in the case at hand, where these criteria must be met:
* E-mail must be enqueued, no matter if there are less or more than 50 consents to send.
* The template must be processed per record.
* In an ideal world, a `cr.commit()` must be issued after each sent mail.
The metod that was being used:
* Didn't allow to use `auto_commit` mode.
* Only allowed to render the template per record if called with `composition_mode="mass_mail"`.
* Only allowed to enqueue emails if called with `composition_mode="mass_post"`.
Obviously, I cannot set 2 different values for `composition_mode`, so a different strategy had to be used.
I discovered that the `mail.template` model has a helpful method called `send_mail()` that, by default:
* Renders the template per record
* Enqueues the email
* The email queue is cleared in `auto_commit=True` mode.
So, from now on, problems are gone:
* The user click, or the cron run, will just generate the missing `privacy.consent` records and enqueue mails for them.
* The mail queue manager will send them later, in `auto_commit` mode.
* After sending the e-mail, this module will set the `privacy.consent` record as `sent`.
* Thanks to *not* sending the email, the process the user faces when he hits the "generate" button is faster.
* Instructions in the README and text in the "generate" button are updated to reflect this new behavior.
* Thanks to the `auto_commit` feature, if Odoo is rebooted in the middle of a mail queue clearance, the records that were sent remain properly marked as sent, and the missing mails will be sent after the next boot.
* No hardcoded commits.
* No locked transactions.
* BTW I discovered that 2 different emails were created when creating a new consent. I started using `mail_create_nolog=True` to avoid that problem and only log a single creation message.
Note to self: never use again `post_message_with_template()`.
6 years ago |
|
# Translation of Odoo Server. # This file contains the translation of the following modules: # * privacy_consent # msgid "" msgstr "" "Project-Id-Version: Odoo Server 11.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" "Plural-Forms: \n"
#. module: privacy_consent #: model:mail.template,body_html:privacy_consent.template_consent msgid "<?xml version=\"1.0\"?>\n" "<div style=\"background:#F3F5F6;color:#515166;padding:25px 0px;font-family:Arial,Helvetica,sans-serif;font-size:14px;\">\n" " <table style=\"width:600px;margin:5px auto;\">\n" " <tbody>\n" " <tr>\n" " <td>\n" " <a href=\"/\">\n" " <img src=\"/logo\" alt=\"${object.activity_id.controller_id.display_name|safe}\" style=\"vertical-align:baseline;max-width:100px;\"/>\n" " </a>\n" " </td>\n" " </tr>\n" " </tbody>\n" " </table>\n" " <table style=\"width:600px;margin:0px auto;background:white;border:1px solid #e1e1e1;\">\n" " <tbody>\n" " <tr>\n" " <td colspan=\"2\" style=\"padding:15px 20px 0px 20px; font-size:16px;\">\n" " <p>\n" " Hello, ${object.partner_id.name|safe}\n" " </p>\n" " <p>\n" " We contacted you to ask you to give us your explicit consent to include your data in a data processing activity called\n" " <b>${object.activity_id.display_name|safe}</b>, property of\n" " <i>${object.activity_id.controller_id.display_name|safe}</i>\n" " </p>\n" " ${object.description or \"\"}\n" " <p>\n" " % if object.state == \"answered\":\n" " The last time you answered, you\n" " % elif object.state == \"sent\":\n" " If you do nothing, we will assume you have\n" " % endif\n" "\n" " % if object.accepted:\n" " <b>accepted</b>\n" " % else:\n" " <b>rejected</b>\n" " % endif\n" " such data processing.\n" " </p>\n" " <p>\n" " You can update your preferences below:\n" " </p>\n" " </td>\n" " </tr>\n" " <tr>\n" " <td style=\"padding:15px 20px 0px 20px; font-size:16px; text-align:right;\">\n" " <a href=\"/privacy/consent/accept/\" style=\"background-color: #449d44; padding: 12px; font-weight: 12px; text-decoration: none; color: #fff; border-radius: 5px; font-size:16px;\">\n" " Accept\n" " </a>\n" " </td>\n" " <td style=\"padding:15px 20px 0px 20px; font-size:16px; text-align:left;\">\n" " <a href=\"/privacy/consent/reject/\" style=\"background-color: #d9534f; padding: 12px; font-weight: 12px; text-decoration: none; color: #fff; border-radius: 5px; font-size:16px;\">\n" " Reject\n" " </a>\n" " </td>\n" " </tr>\n" " <tr>\n" " <td colspan=\"2\" style=\"padding:15px 20px 15px 20px; font-size:16px;\">\n" " <p>\n" " If you need further information, please respond to this email and we will attend your request as soon as possible.\n" " </p>\n" " <p>\n" " Thank you!\n" " </p>\n" " </td>\n" " </tr>\n" " </tbody>\n" " </table>\n" " <table style=\"width:600px;margin:0px auto;text-align:center;\">\n" " <tbody>\n" " <tr>\n" " <td style=\"padding-top:10px;font-size: 12px;\">\n" " <p>\n" " Sent by\n" " <a href=\"/\" style=\"color:#717188;\">${object.activity_id.controller_id.display_name|safe}</a>.\n" " </p>\n" " </td>\n" " </tr>\n" " </tbody>\n" " </table>\n" " </div>\n" " " msgstr ""
#. module: privacy_consent #: model:mail.message.subtype,name:privacy_consent.mt_activity_acceptance_changed msgid "Acceptance Changed" msgstr ""
#. module: privacy_consent #: model:mail.message.subtype,name:privacy_consent.mt_consent_acceptance_changed msgid "Acceptance Changed by Subject" msgstr ""
#. module: privacy_consent #: model:mail.message.subtype,description:privacy_consent.mt_consent_acceptance_changed msgid "Acceptance status updated by subject" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_accepted #: model:ir.ui.view,arch_db:privacy_consent.consent_search msgid "Accepted" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_activity_default_consent msgid "Accepted by default" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_active msgid "Active" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_activity_id #: model:ir.ui.view,arch_db:privacy_consent.consent_search msgid "Activity" msgstr ""
#. module: privacy_consent #: selection:privacy.consent,state:0 msgid "Answered" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.consent_search msgid "Archived" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.consent_form msgid "Ask for consent" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_activity_consent_required msgid "Ask subjects for consent" msgstr ""
#. module: privacy_consent #: selection:privacy.activity,consent_required:0 msgid "Automatically" msgstr ""
#. module: privacy_consent #: selection:privacy.consent,state:0 msgid "Awaiting response" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.activity_form msgid "Consent" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_activity_consent_template_default_body_html msgid "Consent Template Default Body Html" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_activity_consent_template_default_subject msgid "Consent Template Default Subject" msgstr ""
#. module: privacy_consent #: model:ir.model,name:privacy_consent.model_privacy_consent msgid "Consent of data processing" msgstr ""
#. module: privacy_consent #: model:ir.actions.act_window,name:privacy_consent.consent_action #: model:ir.model.fields,field_description:privacy_consent.field_privacy_activity_consent_count #: model:ir.model.fields,field_description:privacy_consent.field_privacy_activity_consent_ids #: model:ir.model.fields,field_description:privacy_consent.field_res_partner_privacy_consent_count #: model:ir.model.fields,field_description:privacy_consent.field_res_users_privacy_consent_count #: model:ir.ui.menu,name:privacy_consent.menu_privacy_consent msgid "Consents" msgstr ""
#. module: privacy_consent #: model:ir.model,name:privacy_consent.model_res_partner msgid "Contact" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_create_uid msgid "Created by" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_create_date msgid "Created on" msgstr ""
#. module: privacy_consent #: model:ir.model,name:privacy_consent.model_privacy_activity msgid "Data processing activities" msgstr ""
#. module: privacy_consent #: model:mail.template,subject:privacy_consent.template_consent msgid "Data processing consent request for ${object.activity_id.display_name|safe}" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_display_name msgid "Display Name" msgstr ""
#. module: privacy_consent #: selection:privacy.consent,state:0 msgid "Draft" msgstr ""
#. module: privacy_consent #: sql_constraint:privacy.consent:0 msgid "Duplicated partner in this data processing activity" msgstr ""
#. module: privacy_consent #: model:ir.model,name:privacy_consent.model_mail_template msgid "Email Templates" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_activity_consent_template_id msgid "Email template" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,help:privacy_consent.field_privacy_activity_consent_template_id msgid "Email to be sent to subjects to ask for consent. A good template should include details about the current consent request status, how to change it, and where to get more information." msgstr ""
#. module: privacy_consent #: model:ir.model.fields,help:privacy_consent.field_privacy_activity_consent_required msgid "Enable if you need to track any kind of consent from the affected subjects" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.activity_form msgid "Generate and enqueue missing consent requests" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.activity_form msgid "Generate missing draft consent requests" msgstr ""
#. module: privacy_consent #: code:addons/privacy_consent/models/privacy_activity.py:138 #, python-format msgid "Generated consents" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.consent_search msgid "Group By" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "Hello," msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "I <b>accept</b> this processing of my data" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "I <b>reject</b> this processing of my data" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_id msgid "ID" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "If it was a mistake, you can undo it here:" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,help:privacy_consent.field_privacy_consent_accepted msgid "Indicates current acceptance status, which can come from subject's last answer, or from the default specified in the related data processing activity." msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_last_metadata msgid "Last Metadata" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent___last_update msgid "Last Modified on" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_write_uid msgid "Last Updated by" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_write_date msgid "Last Updated on" msgstr ""
#. module: privacy_consent #: selection:privacy.activity,consent_required:0 msgid "Manually" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,help:privacy_consent.field_privacy_consent_last_metadata msgid "Metadata from the last acceptance or rejection by the subject" msgstr ""
#. module: privacy_consent #: code:addons/privacy_consent/models/mail_template.py:24 #, python-format msgid "Missing privacy consent link placeholders. You need at least these two links:\n" "<a href=\"%s\">Accept</a>\n" "<a href=\"%s\">Reject</a>" msgstr ""
#. module: privacy_consent #: model:mail.message.subtype,name:privacy_consent.mt_activity_consent_new #: model:mail.message.subtype,name:privacy_consent.mt_consent_consent_new msgid "New Consent" msgstr ""
#. module: privacy_consent #: model:ir.model,name:privacy_consent.model_mail_mail msgid "Outgoing Mails" msgstr ""
#. module: privacy_consent #: model:mail.message.subtype,description:privacy_consent.mt_activity_acceptance_changed msgid "Privacy consent request acceptance status changed" msgstr ""
#. module: privacy_consent #: model:mail.message.subtype,description:privacy_consent.mt_activity_consent_new #: model:mail.message.subtype,description:privacy_consent.mt_consent_consent_new msgid "Privacy consent request created" msgstr ""
#. module: privacy_consent #: model:mail.message.subtype,description:privacy_consent.mt_activity_state_changed #: model:mail.message.subtype,description:privacy_consent.mt_consent_state_changed msgid "Privacy consent request state changed" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,help:privacy_consent.field_res_partner_privacy_consent_count #: model:ir.model.fields,help:privacy_consent.field_res_users_privacy_consent_count msgid "Privacy consent requests amount" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_res_partner_privacy_consent_ids #: model:ir.model.fields,field_description:privacy_consent.field_res_users_privacy_consent_ids msgid "Privacy consents" msgstr ""
#. module: privacy_consent #: model:ir.actions.server,name:privacy_consent.cron_auto_consent_ir_actions_server #: model:ir.cron,cron_name:privacy_consent.cron_auto_consent #: model:ir.cron,name:privacy_consent.cron_auto_consent msgid "Request automatic data processing consents" msgstr ""
#. module: privacy_consent #: code:addons/privacy_consent/models/privacy_activity.py:99 #, python-format msgid "Require consent is available only for subjects in current database." msgstr ""
#. module: privacy_consent #: model:ir.model.fields,help:privacy_consent.field_privacy_activity_server_action_id msgid "Run this action when a new consent request is created or its acceptance status is updated." msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_activity_server_action_id msgid "Server action" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,help:privacy_consent.field_privacy_activity_default_consent msgid "Should we assume the subject has accepted if we receive no response?" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "Sincerely,<br/>" msgstr ""
#. module: privacy_consent #: code:addons/privacy_consent/models/privacy_activity.py:91 #, python-format msgid "Specify a mail template to ask automated consent." msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_state #: model:ir.ui.view,arch_db:privacy_consent.consent_search msgid "State" msgstr ""
#. module: privacy_consent #: model:mail.message.subtype,name:privacy_consent.mt_activity_state_changed #: model:mail.message.subtype,name:privacy_consent.mt_consent_state_changed msgid "State Changed" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,field_description:privacy_consent.field_privacy_consent_partner_id msgid "Subject" msgstr ""
#. module: privacy_consent #: model:ir.model.fields,help:privacy_consent.field_privacy_consent_partner_id msgid "Subject asked for consent." msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "Thank you!" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "Thanks for your response." msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.activity_form msgid "This could enqueue many consent emails, are you sure to proceed?" msgstr ""
#. module: privacy_consent #: model:ir.actions.server,name:privacy_consent.update_opt_out msgid "Update partner's opt out" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "We asked you to authorize us to process your data in this data processing activity:" msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "We have recorded this action on your side." msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "You have <b class=\"text-danger\">rejected</b> such processing." msgstr ""
#. module: privacy_consent #: model:ir.ui.view,arch_db:privacy_consent.form msgid "You have <b class=\"text-success\">accepted</b> such processing." msgstr ""
|