[FIX] im_livechat: use correct url to find rules that apply
The problem was that, when calling 'match_rules()' from the loader template, we compared the wrong url with the url regexp defined in rules. Indeed, we used the url of the page we were leaving, not the one we were going to. We thus need to know if we are coming from the controller, or from the loader template directly as the way to get the correct url differs. Courtesy of JEM
This commit is contained in:
@@ -29,7 +29,7 @@ class LivechatController(http.Controller):
|
||||
def loader(self, channel_id, **kwargs):
|
||||
username = kwargs.get("username", _("Visitor"))
|
||||
channel = request.env['im_livechat.channel'].sudo().browse(channel_id)
|
||||
info = request.env['im_livechat.channel'].match_rules(request, channel.id, username=username)
|
||||
info = request.env['im_livechat.channel'].with_context(from_external_page=True).match_rules(request, channel.id, username=username)
|
||||
return request.render('im_livechat.loader', {'info': info, 'web_session_required': True}) if info else False
|
||||
|
||||
@http.route('/im_livechat/available', type='json', auth="public")
|
||||
|
||||
@@ -207,7 +207,10 @@ class ImLivechatChannel(models.Model):
|
||||
if country_ids:
|
||||
country_id = country_ids[0].id
|
||||
# extract url
|
||||
url = request.httprequest.headers.get('Referer') or request.httprequest.base_url
|
||||
if self.env.context.get('from_external_page', False):
|
||||
url = request.httprequest.headers.get('Referer')
|
||||
else:
|
||||
url = request.httprequest.base_url
|
||||
# find the match rule for the given country and url
|
||||
rule = self.env['im_livechat.channel.rule'].sudo().match_rule(channel_id, url, country_id)
|
||||
if rule:
|
||||
|
||||
Reference in New Issue
Block a user