1212
1313from odoo import (
1414 SUPERUSER_ID ,
15- _ ,
1615 api ,
1716 exceptions ,
1817 http ,
1918 models ,
2019 modules ,
2120)
22- from odoo .http import request
21+ from odoo .http import Response , request
2322from odoo .tools .misc import clean_context
2423
2524from odoo .addons .web .controllers .home import Home
3534
3635def fragment_to_query_string (func ):
3736 @functools .wraps (func )
38- def wrapper (self , ** kw ):
37+ def wrapper (self , * a , ** kw ):
38+ kw .pop ("debug" , False )
3939 if not kw :
40- return """<html><head><script>
40+ return Response ( """<html><head><script>
4141 var l = window.location;
4242 var q = l.hash.substring(1);
43- var r = '/' + l.search;
43+ var r = l.pathname + l.search;
4444 if(q.length !== 0) {
4545 var s = l.search ? (l.search === '?' ? '' : '&') : '?';
4646 r = l.pathname + l.search + s + q;
4747 }
48+ if (r == l.pathname) {
49+ r = '/';
50+ }
4851 window.location = r;
49- </script></head><body></body></html>"""
50- return func (self , ** kw )
52+ </script></head><body></body></html>""" )
53+ return func (self , * a , * *kw )
5154
5255 return wrapper
5356
@@ -59,7 +62,7 @@ def wrapper(self, **kw):
5962
6063class SAMLLogin (Home ):
6164 # Disable pylint self use as the method is meant to be reused in other modules
62- def _list_saml_providers_domain (self ): # pylint: disable=no-self-use
65+ def _list_saml_providers_domain (self ):
6366 return []
6467
6568 def list_saml_providers (self , with_autoredirect : bool = False ) -> models .Model :
@@ -131,11 +134,11 @@ def web_login(self, *args, **kw):
131134 if response .is_qweb :
132135 error = request .params .get ("saml_error" )
133136 if error == "no-signup" :
134- error = _ ("Sign up is not allowed on this database." )
137+ error = request . env . _ ("Sign up is not allowed on this database." )
135138 elif error == "access-denied" :
136- error = _ ("Access Denied" )
139+ error = request . env . _ ("Access Denied" )
137140 elif error == "expired" :
138- error = _ (
141+ error = request . env . _ (
139142 "You do not have access to this database. Please contact support."
140143 )
141144 else :
@@ -179,8 +182,10 @@ def get_auth_request(self, pid):
179182 )
180183 if not redirect_url :
181184 raise Exception (
182- "Failed to get auth request from provider. "
183- "Either misconfigured SAML provider or unknown provider."
185+ request .env ._ (
186+ "Failed to get auth request from provider. "
187+ "Either misconfigured SAML provider or unknown provider."
188+ )
184189 )
185190
186191 redirect = werkzeug .utils .redirect (redirect_url , 303 )
@@ -227,25 +232,28 @@ def signin(self, **kw):
227232 request .httprequest .url_root .rstrip ("/" ),
228233 )
229234 )
235+ # The response needs to be saved otherwise login does not work.
236+ # auth_oauth has a similar code
237+ request .env .cr .commit ()
230238 action = state .get ("a" )
231239 menu = state .get ("m" )
232240 redirect = (
233241 werkzeug .urls .url_unquote_plus (state ["r" ]) if state .get ("r" ) else False
234242 )
235- url = "/web "
243+ url = "/odoo "
236244 if redirect :
237245 url = redirect
238246 elif action :
239- url = f"/# action= { action } "
247+ url = f"/odoo/ action- { action } "
240248 elif menu :
241- url = f"/# menu_id={ menu } "
249+ url = f"/odoo? menu_id={ menu } "
242250
243251 credentials_dict = {
244252 "login" : credentials [1 ],
245253 "token" : credentials [2 ],
246254 "type" : "saml_token" ,
247255 }
248- auth_info = request .session .authenticate (dbname , credentials_dict )
256+ auth_info = request .session .authenticate (request . env , credentials_dict )
249257 resp = request .redirect (_get_login_redirect_url (auth_info ["uid" ], url ), 303 )
250258 resp .autocorrect_location_header = False
251259 return resp
@@ -277,15 +285,15 @@ def saml_metadata(self, **kw):
277285
278286 if not dbname or not provider :
279287 _logger .debug ("Metadata page asked without database name or provider id" )
280- raise request .not_found (_ ("Missing parameters" ))
288+ raise request .not_found (request . env . _ ("Missing parameters" ))
281289
282290 provider = int (provider )
283291
284292 with modules .registry .Registry (dbname ).cursor () as cr :
285293 env = api .Environment (cr , SUPERUSER_ID , {})
286294 client = env ["auth.saml.provider" ].sudo ().browse (provider )
287295 if not client .exists ():
288- raise request .not_found (_ ("Unknown provider" ))
296+ raise request .not_found (request . env . _ ("Unknown provider" ))
289297
290298 return request .make_response (
291299 client ._metadata_string (
0 commit comments