diff --git a/my_compassion/controllers/my_account.py b/my_compassion/controllers/my_account.py index 751a6a9a..0185f236 100644 --- a/my_compassion/controllers/my_account.py +++ b/my_compassion/controllers/my_account.py @@ -20,6 +20,7 @@ from odoo.exceptions import UserError from odoo.http import local_redirect, request, route +from odoo.addons.http_routing.models.ir_http import slug from odoo.addons.portal.controllers.portal import CustomerPortal from odoo.addons.web.controllers.main import content_disposition @@ -251,6 +252,8 @@ def _create_magic_user_from_partner(partner): _, login, _ = res_users.signup(values=values, token=partner.signup_token) return login + ############################# REDIRECTS ################################ + @route(["/my", "/my/home"], type="http", auth="user", website=True) def home(self, redirect=None, **post): """ @@ -335,6 +338,38 @@ def redirect_old_my_information(self, form_id=None, privacy_policy=None, **kw): partner.legal_agreement_date = datetime.now() return request.render("my_compassion.my_information_page_template", values) + @route( + "/child//sponsor", + type="http", + auth="public", + website=True, + sitemap=False, + ) + def redirect_old_child_sponsor(self, child_identifier, **kw): + """ + This is a deprecated route of MyCompassion 1.0. + From MyCompassion 2.0, we ensured a proper redirection + for users using old links. + """ + + # If the URL provided is a basic integer (e.g., "241011"), + # fetch the record with sudo() and convert it to a proper slug + if child_identifier.isdigit(): + child_record = ( + request.env["compassion.child"].sudo().browse(int(child_identifier)) + ) + if child_record.exists(): + child_identifier = slug(child_record) + + new_url = f"/my2/new-sponsorship/{child_identifier}" + + # Extract and append any query parameters (like UTMs) + query_string = request.httprequest.query_string.decode("utf-8") + if query_string: + new_url = f"{new_url}?{query_string}" + + return request.redirect(new_url, code=301) + @route("/my/download/", type="http", auth="user", website=True) def download_file(self, source, **kw): """