[FIX] mail: improve public page error wording

Before this PR, the error displayed in the public page was quite
cryptic. It was hard for the user to understand that error and even
harder to report it if needed. This PR makes the error more user
friendly.

task-3850559

closes odoo/odoo#160947

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
tsm-odoo
2024-04-09 13:04:13 +00:00
parent 15cb8f58d3
commit 52f4e26076
2 changed files with 13 additions and 0 deletions
@@ -84,6 +84,9 @@ class PublicPageController(http.Controller):
return self._response_discuss_channel_invitation(channel_sudo.sudo(False), is_channel_token_secret=False)
def _response_discuss_channel_invitation(self, channel, is_channel_token_secret=True):
# group restriction takes precedence over token
if channel.group_public_id and channel.group_public_id not in request.env.user.groups_id:
raise request.not_found()
discuss_public_view_data = {
"isChannelTokenSecret": is_channel_token_secret,
}
@@ -89,3 +89,13 @@ class TestMailPublicPage(HttpCaseWithUserPortal, HttpCaseWithUserDemo):
self.url_open('/chat/xyz')
channel = self.env['discuss.channel'].search([('uuid', '=', 'xyz')])
self.assertEqual(len(channel), 1)
def test_channel_invitation_from_token(self):
public_channel = self.env["discuss.channel"].channel_create(name="Public Channel", group_id=None)
internal_channel = self.env["discuss.channel"].channel_create(name="Internal Channel", group_id=self.env.ref("base.group_user").id)
public_response = self.url_open(public_channel.invitation_url)
self.assertEqual(public_response.status_code, 200)
internal_response = self.url_open(internal_channel.invitation_url)
self.assertEqual(internal_response.status_code, 404)