Search code examples
emailodoo

How to create private channel in odoo?


I am trying to create private channel programmatically in Discuss Odoo12 but while creating it is giving me error that: The requested operation cant be completed due to security restrictions.

Then I tried like:

self.env['mail.channel'].sudo().create({})

Then it is creating private channel as a superuser

But problem is that when I log in into my account I am unable to view that private channels because those were created by superuser.

How to display them or how to create private channel without sudo()?


Solution

  • Yes because there is a record rule that prevent user from creating channel that they are not member of it. So when you create it you need to include the partner of your user in channel members.

    self.env['mail.channel'].create({'name': 'Name of Channel', 
       'public': 'private', 
       'email_send': False, 
       # The user must join the group
       'channel_partner_ids': [(4, self.env.user.partner_id.id)]})
    

    ir.rules are not applied on super user this why he can create a private group that he is not one of its members.