diff --git a/addons/web/static/src/legacy/js/core/cookie_utils.js b/addons/web/static/src/legacy/js/core/cookie_utils.js index 1696539b547..a8c3a3a8c78 100644 --- a/addons/web/static/src/legacy/js/core/cookie_utils.js +++ b/addons/web/static/src/legacy/js/core/cookie_utils.js @@ -39,15 +39,13 @@ const utils = { * @param {string} type the type of the cookies ('required' as default value) */ setCookie(name, value, ttl = 31536000, type = 'required') { - ttl = ttl || 24 * 60 * 60 * 365; - if (utils.isAllowedCookie(type)) { - document.cookie = [ - `${name}=${value}`, - 'path=/', - `max-age=${ttl}`, - `expires=${new Date(new Date().getTime() + ttl * 1000).toGMTString()}`, - ].join(';'); - } + ttl = utils.isAllowedCookie(type) ? ttl || 24 * 60 * 60 * 365 : -1; + document.cookie = [ + `${name}=${value}`, + 'path=/', + `max-age=${ttl}`, + `expires=${new Date(new Date().getTime() + ttl * 1000).toGMTString()}`, + ].join(';'); }, /** * Deletes a cookie. diff --git a/odoo/http.py b/odoo/http.py index a3bdf7cc6c5..7cd87c1af7a 100644 --- a/odoo/http.py +++ b/odoo/http.py @@ -1059,13 +1059,11 @@ class Response(werkzeug.wrappers.Response): self.response.append(self.render()) self.template = None - def set_cookie(self, *args, **kwargs): - cookie_type = kwargs.pop('cookie_type', None) - if request.db: - if not request.env['ir.http']._is_allowed_cookie(cookie_type): - kwargs['expires'] = 0 - kwargs['max_age'] = 0 - super().set_cookie(*args, **kwargs) + def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, samesite=None, cookie_type='required'): + if request.db and not request.env['ir.http']._is_allowed_cookie(cookie_type): + expires = 0 + max_age = 0 + super().set_cookie(key, value=value, max_age=max_age, expires=expires, path=path, domain=domain, secure=secure, httponly=httponly, samesite=samesite) class FutureResponse: @@ -1081,13 +1079,11 @@ class FutureResponse: self.headers = werkzeug.datastructures.Headers() @functools.wraps(werkzeug.Response.set_cookie) - def set_cookie(self, *args, **kwargs): - if 'cookie_type' in kwargs and request.db: - cookie_type = kwargs.pop('cookie_type', 'required') - if not request.env['ir.http']._is_allowed_cookie(cookie_type): - kwargs['expires'] = 0 - kwargs['max_age'] = 0 - werkzeug.Response.set_cookie(self, *args, **kwargs) + def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, samesite=None, cookie_type='required'): + if request.db and not request.env['ir.http']._is_allowed_cookie(cookie_type): + expires = 0 + max_age = 0 + werkzeug.Response.set_cookie(self, key, value=value, max_age=max_age, expires=expires, path=path, domain=domain, secure=secure, httponly=httponly, samesite=samesite) class Request: