Skip to content

Commit 8482edc

Browse files
[FIX] mail, portal: fix mail/view redirection parameters when not logged
When being not logged and receiving an internal link, user is redirected to an internal link with missing parameters (token, ... ). This leads to faulty URLs that are not usable. This issue is fixed by correctly redirecting using the original given URL. Task-4685166 X-original-commit: odoo/odoo@b24e9d6 Part-of: odoo#213889 Signed-off-by: Thibault Delavallee (tde) <[email protected]>
1 parent 0915628 commit 8482edc

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

addons/mail/controllers/mail.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,21 @@ def _redirect_to_record(cls, model, res_id, access_token=None, **kwargs):
140140
# the record has an URL redirection: use it directly
141141
if record_action['type'] == 'ir.actions.act_url':
142142
return request.redirect(record_action['url'])
143-
# other choice: act_window (no support of anything else currently)
143+
# anything else than an act_window is not supported
144144
elif record_action['type'] != 'ir.actions.act_window':
145145
return cls._redirect_to_messaging()
146146

147+
# backend act_window: when not logged, unless really readable as public,
148+
# user is going to be redirected to login -> keep mail/view as redirect
149+
# in that case. In case of readable record, we consider this might be
150+
# a customization and we do not change the behavior in stable
151+
if uid is None or request.env.user._is_public():
152+
has_access = record_sudo.with_user(request.env.user).has_access('read')
153+
if not has_access:
154+
return cls._redirect_to_login_with_mail_view(
155+
model, res_id, access_token=access_token, **kwargs,
156+
)
157+
147158
url_params = {}
148159
menu_id = request.env['ir.ui.menu']._get_best_backend_root_menu_id_for_model(model)
149160
if menu_id:

addons/test_mail_full/tests/test_portal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,10 @@ def test_portal_access_not_logged(self):
370370
"No access (portal enabled), invalid token", self.record_portal_url_auth_wrong_token,
371371
f'{login_url}?{url_encode({"redirect": self.record_portal_url_auth_wrong_token.replace(self.test_base_url, "")})}',
372372
),
373-
# std url, no access to record -> redirect to login, with internal backend redirect ending with a ? (???)
373+
# std url, no access to record -> redirect to login with redirect to original link, will be rejected after login
374374
(
375375
'No access record (internal)', self.record_internal_url_base,
376-
f'{login_url}?{url_encode({"redirect": self.internal_backend_local_url + "?"})}',
376+
f'{login_url}?{url_encode({"redirect": self.record_internal_url_base.replace(self.test_base_url, "")})}',
377377
),
378378
# std url, no access to record but portal -> redirect to login, original (local) URL kept as redirection post login to try again (even if faulty)
379379
(
@@ -382,7 +382,7 @@ def test_portal_access_not_logged(self):
382382
),
383383
(
384384
'No access record (portal can read, no customer portal)', self.record_read_url_base,
385-
f'{login_url}?{url_encode({"redirect": self.read_backend_local_url + "?"})}',
385+
f'{login_url}?{url_encode({"redirect": self.record_read_url_base.replace(self.test_base_url, "")})}',
386386
),
387387
# public_type act_url -> share users are redirected to frontend url
388388
(

0 commit comments

Comments
 (0)