[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
# Copyright 2015 Antiun Ingeniería S.L. (http://www.antiun.com)
|
|
|
|
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
|
2020-06-19 12:47:06 +02:00
|
|
|
# Copyright 2020 Tecnativa - Pedro M. Baeza
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
2016-07-25 12:50:32 +02:00
|
|
|
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
import logging
|
2016-07-25 12:50:32 +02:00
|
|
|
|
2018-05-25 18:49:55 +02:00
|
|
|
from odoo.http import request, route
|
2020-08-24 10:36:19 +02:00
|
|
|
|
2019-04-06 01:39:55 +02:00
|
|
|
from odoo.addons.mass_mailing.controllers.main import MassMailController
|
2016-07-25 12:50:32 +02:00
|
|
|
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
_logger = logging.getLogger(__name__)
|
2016-07-25 12:50:32 +02:00
|
|
|
|
|
|
|
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
class CustomUnsubscribe(MassMailController):
|
2019-04-06 01:39:55 +02:00
|
|
|
def reason_form(self, mailing_id, email, res_id, reasons, token):
|
2016-07-25 12:50:32 +02:00
|
|
|
"""Get the unsubscription reason form.
|
|
|
|
|
2020-08-26 08:57:06 +02:00
|
|
|
:param mailing.mailing mailing:
|
2016-07-25 12:50:32 +02:00
|
|
|
Mailing where the unsubscription is being processed.
|
|
|
|
|
|
|
|
:param str email:
|
|
|
|
Email to be unsubscribed.
|
|
|
|
|
|
|
|
:param int res_id:
|
|
|
|
ID of the unsubscriber.
|
|
|
|
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
:param str token:
|
|
|
|
Security token for unsubscriptions.
|
2016-07-25 12:50:32 +02:00
|
|
|
"""
|
2017-07-05 11:07:28 +02:00
|
|
|
return request.render(
|
2016-07-25 12:50:32 +02:00
|
|
|
"mass_mailing_custom_unsubscribe.reason_form",
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
{
|
|
|
|
"email": email,
|
2019-04-06 01:39:55 +02:00
|
|
|
"mailing_id": mailing_id,
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
"reasons": reasons,
|
|
|
|
"res_id": res_id,
|
|
|
|
"token": token,
|
2020-08-24 10:36:19 +02:00
|
|
|
},
|
|
|
|
)
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
|
|
|
|
@route()
|
|
|
|
def mailing(self, mailing_id, email=None, res_id=None, token="", **post):
|
|
|
|
"""Ask/save unsubscription reason."""
|
|
|
|
_logger.debug(
|
2020-08-24 10:36:19 +02:00
|
|
|
"Called `mailing()` with: %r", (mailing_id, email, res_id, token, post)
|
|
|
|
)
|
2019-04-06 01:39:55 +02:00
|
|
|
reasons = request.env["mail.unsubscription.reason"].search([])
|
2020-08-26 08:57:06 +02:00
|
|
|
if not res_id:
|
|
|
|
res_id = "0"
|
2020-06-19 12:47:06 +02:00
|
|
|
res_id = res_id and int(res_id)
|
2016-07-25 12:50:32 +02:00
|
|
|
try:
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
# Check if we already have a reason for unsubscription
|
|
|
|
reason_id = int(post["reason_id"])
|
|
|
|
except (KeyError, ValueError):
|
|
|
|
# No reasons? Ask for them
|
2019-04-06 01:39:55 +02:00
|
|
|
return self.reason_form(mailing_id, email, res_id, reasons, token)
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
else:
|
|
|
|
# Unsubscribe, saving reason and details by context
|
2019-04-06 01:39:55 +02:00
|
|
|
details = post.get("details", False)
|
|
|
|
self._add_extra_context(mailing_id, res_id, reason_id, details)
|
2020-08-26 08:57:06 +02:00
|
|
|
mailing_obj = request.env["mailing.mailing"]
|
2020-06-19 12:47:06 +02:00
|
|
|
mass_mailing = mailing_obj.sudo().browse(mailing_id)
|
|
|
|
model = mass_mailing.mailing_model_real
|
2020-08-26 08:57:06 +02:00
|
|
|
if "opt_out" in request.env[model]._fields and model != "mailing.contact":
|
2020-06-19 12:47:06 +02:00
|
|
|
mass_mailing.update_opt_out_other(email, [res_id], True)
|
2020-08-24 10:36:19 +02:00
|
|
|
result = request.render(
|
|
|
|
"mass_mailing.page_unsubscribed",
|
|
|
|
{
|
|
|
|
"email": email,
|
|
|
|
"mailing_id": mailing_id,
|
|
|
|
"res_id": res_id,
|
|
|
|
"show_blacklist_button": request.env["ir.config_parameter"]
|
|
|
|
.sudo()
|
|
|
|
.get_param("mass_mailing.show_blacklist_buttons"),
|
|
|
|
},
|
|
|
|
)
|
2020-06-19 12:47:06 +02:00
|
|
|
result.qcontext.update({"reasons": reasons})
|
|
|
|
else:
|
|
|
|
# You could get a DetailsRequiredError here, but only if HTML5
|
|
|
|
# validation fails, which should not happen in modern browsers
|
2020-08-24 10:36:19 +02:00
|
|
|
result = super().mailing(mailing_id, email, res_id, token=token, **post)
|
2020-08-26 08:57:06 +02:00
|
|
|
if model == "mailing.contact":
|
2020-06-19 12:47:06 +02:00
|
|
|
# update list_ids taking into account
|
|
|
|
# not_cross_unsubscriptable field
|
2020-08-24 10:36:19 +02:00
|
|
|
result.qcontext.update(
|
|
|
|
{
|
|
|
|
"reasons": reasons,
|
|
|
|
"list_ids": result.qcontext["list_ids"].filtered(
|
|
|
|
lambda m_list: not m_list.not_cross_unsubscriptable
|
|
|
|
or m_list in mass_mailing.contact_list_ids
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
2019-04-06 01:39:55 +02:00
|
|
|
return result
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
|
|
|
|
@route()
|
2020-08-24 10:36:19 +02:00
|
|
|
def unsubscribe(
|
|
|
|
self,
|
|
|
|
mailing_id,
|
|
|
|
opt_in_ids,
|
|
|
|
opt_out_ids,
|
|
|
|
email,
|
|
|
|
res_id,
|
|
|
|
token,
|
|
|
|
reason_id=None,
|
|
|
|
details=None,
|
|
|
|
):
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
"""Store unsubscription reasons when unsubscribing from RPC."""
|
2019-04-06 01:39:55 +02:00
|
|
|
# Update request context
|
|
|
|
self._add_extra_context(mailing_id, res_id, reason_id, details)
|
|
|
|
_logger.debug(
|
|
|
|
"Called `unsubscribe()` with: %r",
|
2020-08-24 10:36:19 +02:00
|
|
|
(
|
|
|
|
mailing_id,
|
|
|
|
opt_in_ids,
|
|
|
|
opt_out_ids,
|
|
|
|
email,
|
|
|
|
res_id,
|
|
|
|
token,
|
|
|
|
reason_id,
|
|
|
|
details,
|
|
|
|
),
|
|
|
|
)
|
2019-04-06 01:39:55 +02:00
|
|
|
return super().unsubscribe(
|
2020-08-24 10:36:19 +02:00
|
|
|
mailing_id, opt_in_ids, opt_out_ids, email, res_id, token
|
|
|
|
)
|
2019-04-06 01:39:55 +02:00
|
|
|
|
|
|
|
@route()
|
2020-08-24 10:36:19 +02:00
|
|
|
def blacklist_add(
|
|
|
|
self, mailing_id, res_id, email, token, reason_id=None, details=None
|
|
|
|
):
|
2019-04-06 01:39:55 +02:00
|
|
|
self._add_extra_context(mailing_id, res_id, reason_id, details)
|
2020-08-24 10:36:19 +02:00
|
|
|
return super().blacklist_add(mailing_id, res_id, email, token)
|
2019-04-06 01:39:55 +02:00
|
|
|
|
|
|
|
@route()
|
2020-08-24 10:36:19 +02:00
|
|
|
def blacklist_remove(
|
|
|
|
self, mailing_id, res_id, email, token, reason_id=None, details=None
|
|
|
|
):
|
2019-04-06 01:39:55 +02:00
|
|
|
self._add_extra_context(mailing_id, res_id, reason_id, details)
|
2020-08-24 10:36:19 +02:00
|
|
|
return super().blacklist_remove(mailing_id, res_id, email, token)
|
2019-04-06 01:39:55 +02:00
|
|
|
|
|
|
|
def _add_extra_context(self, mailing_id, res_id, reason_id, details):
|
2018-05-10 12:17:04 +02:00
|
|
|
environ = request.httprequest.headers.environ
|
2019-04-06 01:39:55 +02:00
|
|
|
# Add mailing_id and res_id to request.context to be used in the
|
|
|
|
# redefinition of _add and _remove methods of the mail.blacklist class
|
2018-05-10 12:17:04 +02:00
|
|
|
extra_context = {
|
|
|
|
"default_metadata": "\n".join(
|
2020-08-24 10:36:19 +02:00
|
|
|
"{}: {}".format(val, environ.get(val))
|
|
|
|
for val in ("REMOTE_ADDR", "HTTP_USER_AGENT", "HTTP_ACCEPT_LANGUAGE")
|
2018-05-10 12:17:04 +02:00
|
|
|
),
|
2019-04-06 01:39:55 +02:00
|
|
|
"mailing_id": mailing_id,
|
|
|
|
"unsubscription_res_id": int(res_id),
|
2018-05-10 12:17:04 +02:00
|
|
|
}
|
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate.
- Imported last updates from v8.
- Adapted to v9.
- Added a saner default to `mass_mailing.salt` configuration parameter by
reusing `database.secret` if available, hoping that some day
https://github.com/odoo/odoo/pull/12040 gets merged.
- Updated README.
- Increase security, drop backwards compatibility.
Security got improved upstream, which would again break compatibility among current addon and future master upstream.
I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features.
- Includes tour tests.
- Removes outdated tests.
- Extends the mailing list management form when unsubscriber is a contact.
- Adds a reason form even if he is not.
- Avoids all methods that were not model-agnostic.
[FIX][mass_mailing_custom_unsubscribe] Reasons noupdate
After this fix, when you update the addon, you will not lose your customized reasons.
[FIX] Compatibilize with mass_mailing_partner
Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets.
Now records are created from an empty recordset, and thus tests work everywhere.
Update instructions
If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon.
[FIX] Use the right operator to preserve recordsets order
Using `|=` sorts records at will each time (treating them as Python's `set`).
Using `+=` always appends a record to the end of the set.
Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
2016-11-11 14:41:20 +01:00
|
|
|
if reason_id:
|
2018-05-10 12:17:04 +02:00
|
|
|
extra_context["default_reason_id"] = int(reason_id)
|
|
|
|
if details:
|
|
|
|
extra_context["default_details"] = details
|
|
|
|
request.context = dict(request.context, **extra_context)
|