[REM] website_utm: website depends on utm already

`_post_dispatch` is a late addition to the httpocalypse. It can be used
to alter the response object e.g. to inject headers or cookies. The
function is automatically called for regular, fallback and error
responses. On the other hand, `_dispatch` is only called when an
endpoint is matched and might not return a response in case of error.

task-2839031

closes odoo/odoo#96651

Related: odoo/upgrade#3710
Signed-off-by: Julien Castiaux <juc@odoo.com>
This commit is contained in:
Julien Castiaux
2022-08-01 10:55:29 +02:00
committed by Julien Castiaux
parent 183a966ab5
commit ad71d6d3ee
5 changed files with 5 additions and 36 deletions
+5 -8
View File
@@ -12,16 +12,13 @@ class IrHttp(models.AbstractModel):
return request.httprequest.host
@classmethod
def _set_utm(cls):
def _set_utm(cls, response):
domain = cls.get_utm_domain_cookies()
for url_parameter, __, cookie_name in request.env['utm.mixin'].tracking_fields():
if url_parameter in request.params and request.httprequest.cookies.get(cookie_name) != request.params[url_parameter]:
request.future_response.set_cookie(cookie_name, request.params[url_parameter], domain=domain)
response.set_cookie(cookie_name, request.params[url_parameter], domain=domain)
@classmethod
def _dispatch(cls, endpoint):
# cannot override _pre_dispatch() as _set_utm() requires the
# params from the request's body.
cls._set_utm()
return super()._dispatch(endpoint)
def _post_dispatch(cls, response):
cls._set_utm(response)
super()._post_dispatch(response)
-2
View File
@@ -1,2 +0,0 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
-11
View File
@@ -1,11 +0,0 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': "Website UTM glue code",
'summary': "Technical module adding utm compatibility to website.",
'website': "https://www.odoo.com",
'category': 'Hidden',
'version': '1.0',
'depends': ['utm', 'website'],
'auto_install': True,
'license': 'LGPL-3',
}
-2
View File
@@ -1,2 +0,0 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import ir_http
-13
View File
@@ -1,13 +0,0 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class IrHttp(models.AbstractModel):
_inherit = 'ir.http'
@classmethod
def _serve_fallback(cls):
resp = super()._serve_fallback()
if resp:
cls._set_utm()
return resp