[IMP] mail: add invitation_url on channel

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) <seb@odoo.com>
This commit is contained in:
Leonardo Pavan Rocha
2022-03-31 19:11:44 +02:00
parent 593d2ae623
commit ed116c735b
2 changed files with 7 additions and 1 deletions
+6
View File
@@ -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')
@@ -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")