Skip to content

Commit 0915628

Browse files
[FIX] mail, portal: fix /mail/view generic fallback for portal
When mail/view asks for a generic redirect (no access, ...) portal users can be redirected to '/my' directly, instead of a '/my + discuss action'. Discuss action makes no sense for portal users. Task-4685166 X-original-commit: odoo/odoo@f06aa25 Part-of: odoo#213889 Signed-off-by: Thibault Delavallee (tde) <[email protected]>
1 parent 761e324 commit 0915628

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

addons/mail/controllers/mail.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def _redirect_to_record(cls, model, res_id, access_token=None, **kwargs):
9696
# the record has a window redirection: check access rights
9797
if uid is not None:
9898
if not RecordModel.with_user(uid).has_access('read'):
99-
return cls._redirect_to_messaging()
99+
return cls._redirect_to_generic_fallback(
100+
model, res_id, access_token=access_token, **kwargs,
101+
)
100102
try:
101103
# We need here to extend the "allowed_company_ids" to allow a redirection
102104
# to any record that the user can access, regardless of currently visible
@@ -121,7 +123,9 @@ def _redirect_to_record(cls, model, res_id, access_token=None, **kwargs):
121123
record_sudo.with_user(uid).with_context(allowed_company_ids=cids).check_access('read')
122124
request.future_response.set_cookie('cids', '-'.join([str(cid) for cid in cids]))
123125
except AccessError:
124-
return cls._redirect_to_messaging()
126+
return cls._redirect_to_generic_fallback(
127+
model, res_id, access_token=access_token, **kwargs,
128+
)
125129
else:
126130
record_action = record_sudo._get_access_action(access_uid=uid)
127131
else:

addons/portal/controllers/mail.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ def portal_message_update_is_internal(self, message_id, is_internal):
121121

122122
class MailController(mail.MailController):
123123

124+
@classmethod
125+
def _redirect_to_generic_fallback(cls, model, res_id, access_token=None, **kwargs):
126+
# Generic fallback for a share user is the customer portal
127+
if request.session.uid and request.env.user.share:
128+
return request.redirect('/my')
129+
return super()._redirect_to_generic_fallback(model, res_id, access_token=access_token, **kwargs)
130+
124131
@classmethod
125132
def _redirect_to_record(cls, model, res_id, access_token=None, **kwargs):
126133
""" If the current user doesn't have access to the document, but provided

addons/test_mail_full/tests/test_portal.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def test_employee_access(self):
299299
def test_portal_access_logged(self):
300300
""" Check portal behavior when accessing mail/view, notably check token
301301
support and propagation. """
302-
my_discuss_url = f'{self.test_base_url}/my?{url_encode({"subpath": "action-mail.action_discuss"})}'
302+
my_url = f'{self.test_base_url}/my'
303303

304304
self.authenticate(self.env.user.login, self.env.user.login)
305305
for url_name, url, exp_url in [
@@ -308,43 +308,43 @@ def test_portal_access_logged(self):
308308
"No access (portal enabled), token", self.record_portal_url_auth,
309309
self.portal_web_url_with_token,
310310
),
311-
# invalid token -> ko -> redirect to my with discuss action (???)
311+
# invalid token -> ko -> redirect to my
312312
(
313313
"No access (portal enabled), invalid token", self.record_portal_url_auth_wrong_token,
314-
my_discuss_url,
314+
my_url,
315315
),
316316
# std url, read record -> redirect to my with parameters being record portal action parameters (???)
317317
(
318318
'Access record (no customer portal)', self.record_read_url_base,
319319
f'{self.test_base_url}/my?{url_encode({"subpath": f"{self.record_read._name}/{self.record_read.id}"})}',
320320
),
321-
# std url, no access to record -> redirect to my with discuss action (???)
321+
# std url, no access to record -> redirect to my
322322
(
323323
'No access record (internal)', self.record_internal_url_base,
324-
my_discuss_url,
324+
my_url,
325325
),
326-
# missing token -> redirect to my with discuss action (???)
326+
# missing token -> redirect to my
327327
(
328328
'No access record (portal enabled)', self.record_portal_url_base,
329-
my_discuss_url,
329+
my_url,
330330
),
331331
# public_type act_url -> share users are redirected to frontend url
332332
(
333333
"Public with act_url -> frontend url", self.record_public_act_url_base,
334334
self.public_act_url_share
335335
),
336-
# not existing -> redirect to my with discuss action (???)
336+
# not existing -> redirect to my
337337
(
338338
'Not existing record (internal)', self.record_internal_url_no_exists,
339-
my_discuss_url,
339+
my_url,
340340
),
341341
(
342342
'Not existing record (portal enabled)', self.record_portal_url_no_exists,
343-
my_discuss_url,
343+
my_url,
344344
),
345345
(
346346
'Not existing model', self.record_url_no_model,
347-
my_discuss_url,
347+
my_url,
348348
),
349349
]:
350350
with self.subTest(name=url_name, url=url):

0 commit comments

Comments
 (0)