From ed116c735b17d71ae355d2e7d9904986b515ea61 Mon Sep 17 00:00:00 2001 From: Leonardo Pavan Rocha Date: Thu, 31 Mar 2022 15:56:41 +0000 Subject: [PATCH] [IMP] mail: add invitation_url on channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In mail we currently create the invitation URL by concatenating the values when needed. However this could be improved so that when this url is used in other places we don't need to create it again. Therefore it makes sense to have a computed field that does that for us. task-2685472 closes odoo/odoo#87701 Signed-off-by: Sébastien Theys (seb) --- addons/mail/models/mail_channel.py | 6 ++++++ addons/mail/tests/test_mail_channel_as_guest.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index dc67bb84d10..bc923c99cd2 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -89,6 +89,7 @@ class Channel(models.Model): required=True, default='groups', help='This group is visible by non members. Invisible groups can add members through the invite button.') group_public_id = fields.Many2one('res.groups', string='Authorized Group', compute='_compute_group_public_id', readonly=False, store=True) + invitation_url = fields.Char('Invitation URL', compute='_compute_invitation_url') _sql_constraints = [ ('channel_type_not_null', 'CHECK(channel_type IS NOT NULL)', 'The channel type cannot be empty'), @@ -183,6 +184,11 @@ class Channel(models.Model): channels.filtered(lambda channel: not channel.group_public_id).group_public_id = self.env.ref('base.group_user') (self - channels).group_public_id = None + @api.depends('uuid') + def _compute_invitation_url(self): + for channel in self: + channel.invitation_url = f"/chat/{channel.id}/{channel.uuid}" + # ONCHANGE @api.onchange('public') diff --git a/addons/mail/tests/test_mail_channel_as_guest.py b/addons/mail/tests/test_mail_channel_as_guest.py index 6315a6d94f1..554e70a998b 100644 --- a/addons/mail/tests/test_mail_channel_as_guest.py +++ b/addons/mail/tests/test_mail_channel_as_guest.py @@ -13,4 +13,4 @@ class TestMailGuestPages(HttpCase): 'name': 'Test channel', 'public': 'public', }) - self.start_tour(f"/chat/{channel.id}/{channel.uuid}", "mail/static/tests/tours/mail_channel_as_guest_tour.js") + self.start_tour(channel.invitation_url, "mail/static/tests/tours/mail_channel_as_guest_tour.js")