Skip to content

Commit e1139f8

Browse files
committed
Merge PR OCA#1160 into 14.0
Signed-off-by ivs-cetmix
2 parents c12e358 + 64077be commit e1139f8

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

website_require_login/models/ir_http.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from odoo import models
99
from odoo.http import request
1010

11+
from odoo.addons.website.models import ir_http
12+
1113

1214
class IrHttp(models.AbstractModel):
1315
_inherit = "ir.http"
@@ -16,6 +18,9 @@ class IrHttp(models.AbstractModel):
1618
def _dispatch(cls):
1719
res = super(IrHttp, cls)._dispatch()
1820
# if not website request - skip
21+
if not ir_http.get_request_website():
22+
return res
23+
1924
website = request.env["website"].sudo().get_current_website()
2025
if not website:
2126
return res

website_require_login/tests/test_ir_http.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from odoo.tests import HttpCase
77
from odoo.tools import mute_logger
88

9+
from odoo.addons.bus.controllers.main import BusController
10+
911

1012
class TestIrHttp(HttpCase):
1113
def setUp(self):
@@ -70,3 +72,37 @@ def test_dispatch_failed_transaction(self):
7072
),
7173
)
7274
self.assertEqual(response.status_code, 200)
75+
76+
def test_dispatch_no_website(self):
77+
"""If the request is not `website`, do not interfere."""
78+
# Arrange
79+
path = "/longpolling/poll"
80+
routing = BusController().poll.routing
81+
self.auth_url = self.env["website.auth.url"].create(
82+
{
83+
"website_id": self.website.id,
84+
"path": path,
85+
}
86+
)
87+
# pre-condition
88+
self.assertFalse(routing.get("website"))
89+
self.assertIn(path, routing.get("routes", dict()))
90+
91+
# Act
92+
response = self.url_open(
93+
path,
94+
headers={
95+
"Content-Type": "application/json",
96+
},
97+
data=json.dumps(
98+
{
99+
"params": {
100+
"channels": ["Test channel"],
101+
"last": 0,
102+
},
103+
}
104+
),
105+
)
106+
107+
# Assert
108+
self.assertEqual(response.status_code, 200)

0 commit comments

Comments
 (0)