<commit_before># Copyright 2022 Camptocamp SA (https://www.camptocamp.com).
# @author <NAME> <<EMAIL>>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import http
from odoo.exceptions import AccessDenied
from odoo.http import request
from odoo.tools import consteq

from odoo.addons.mass_mailing.controllers.main import MassMailController


class MassMailSubscriptionEmailController(MassMailController):
    @http.route(
        "/mail/mailing/contact/<int:res_id>/unsubscribe",
        type="http",
        website=True,
        auth="public",
    )
    def mailing_contact_unsubscribe(self, res_id, email=None, token="", **post):
        subscription = request.env["mailing.contact.subscription"].sudo().browse(res_id)
        if not subscription.exists():  # pragma: no cover
            return request.redirect("/web")
        if not consteq(subscription._unsubscribe_token(), token):  # pragma: no cover
            raise AccessDenied()
        subscription.opt_out = True
        return request.render("mass_mailing.page_unsubscribed")<commit_msg>[14.0][FIX] mass_mailing_subscription_email: fix unsubscribe<commit_after># Copyright 2022 Camptocamp SA (https://www.camptocamp.com).
# @author <NAME> <<EMAIL>>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import http
from odoo.exceptions import AccessDenied
from odoo.http import request
from odoo.tools import consteq

from odoo.addons.mass_mailing.controllers.main import MassMailController


class MassMailSubscriptionEmailController(MassMailController):
    @http.route(
        "/mail/mailing/contact/<int:res_id>/unsubscribe",
        type="http",
        website=True,
        auth="public",
    )
    def mailing_contact_unsubscribe(self, res_id, email=None, token="", **post):
        subscription = request.env["mailing.contact.subscription"].sudo().browse(res_id)
        if not subscription.exists():  # pragma: no cover
            return request.redirect("/web")
        if not consteq(subscription._unsubscribe_token(), token):  # pragma: no cover
            raise AccessDenied()
        subscription.opt_out = True
        values = {"email": email}
        return request.render("mass_mailing.page_unsubscribed", values)
{'fraction_non_alphanumeric': 0.11772545535317637, 'fraction_numerical': 0.006663705019991115, 'mean_word_length': 3.73109243697479, 'pattern_counts': {'":': 1, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6535319', 'n_tokens_mistral': 683, 'n_tokens_neox': 673, 'n_words': 146}