Skip to content
Snippets Groups Projects
Commit f5fe11cf authored by Ipsita Borisagar's avatar Ipsita Borisagar Committed by Thibault Delavallée
Browse files

[IMP] mail: add current user by default on new channel


Before this commit, when a user creates a private channel without adding himself
as a member of it, it raises an access error. After this commit, user will be
automatically added as a member by default when creating a channel.

It makes sense the creator is a member of its channel. Moreover it avoids
issues on private channels.

Task 2172420
PR odoo/odoo#44454

Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent 5a166fc4
No related branches found
No related tags found
No related merge requests found
......@@ -61,10 +61,6 @@ class Channel(models.Model):
MAX_BOUNCE_LIMIT = 10
def _get_default_image(self):
image_path = modules.get_module_resource('mail', 'static/src/img', 'groupdefault.png')
return base64.b64encode(open(image_path, 'rb').read())
@api.model
def default_get(self, fields):
res = super(Channel, self).default_get(fields)
......@@ -72,6 +68,13 @@ class Channel(models.Model):
res['alias_contact'] = 'everyone' if res.get('public', 'private') == 'public' else 'followers'
return res
def _default_channel_last_seen_partner_ids(self):
return [(0, 0, {"partner_id": self.env.user.partner_id.id})]
def _get_default_image(self):
image_path = modules.get_module_resource('mail', 'static/src/img', 'groupdefault.png')
return base64.b64encode(open(image_path, 'rb').read())
name = fields.Char('Name', required=True, translate=True)
active = fields.Boolean(default=True, help="Set active to false to hide the channel without removing it.")
channel_type = fields.Selection([
......@@ -84,7 +87,7 @@ class Channel(models.Model):
email_send = fields.Boolean('Send messages by email', default=False)
# multi users channel
# depends=['...'] is for `test_mail/tests/common.py`, class Moderation, `setUpClass`
channel_last_seen_partner_ids = fields.One2many('mail.channel.partner', 'channel_id', string='Last Seen', depends=['channel_partner_ids'])
channel_last_seen_partner_ids = fields.One2many('mail.channel.partner', 'channel_id', string='Last Seen', depends=['channel_partner_ids'], default=_default_channel_last_seen_partner_ids)
channel_partner_ids = fields.Many2many('res.partner', 'mail_channel_partner', 'channel_id', 'partner_id', string='Listeners', depends=['channel_last_seen_partner_ids'])
channel_message_ids = fields.Many2many('mail.message', 'mail_message_mail_channel_rel')
is_member = fields.Boolean('Is a member', compute='_compute_is_member')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment