PURPOSE
Reorganize and lint mail.channel code. Purpose is to ease future modifications
linked to groups and channels in mail / Discuss.
SPECIFICATIONS
Move mail.channel.partner and mail.moderation models into their own file.
This makes some noise in diff but as channel is quite an heavy model let us
do this once for all.
Move mail.channel.partner views in their own file, as for python models.
Also containing
* separate and reorganize fields by main definition;
* separate and reorganize methods by categories, notably CRUD + orm, members
management, moderation, mailing, IM, commands;
* reorganize compute section: compute (by field order), constraints then
onchanges;
LINKS
Prepares Task ID-2070632 (Discuss channel task)
Prepares Task ID-2419762 (SM channel task)
COM PR odoo/odoo#64862
45 lines
2.1 KiB
Python
45 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.exceptions import AccessError
|
|
|
|
|
|
class ChannelPartner(models.Model):
|
|
_name = 'mail.channel.partner'
|
|
_description = 'Listeners of a Channel'
|
|
_table = 'mail_channel_partner'
|
|
_rec_name = 'partner_id'
|
|
|
|
custom_channel_name = fields.Char('Custom channel name')
|
|
partner_id = fields.Many2one('res.partner', string='Recipient', ondelete='cascade')
|
|
partner_email = fields.Char('Email', related='partner_id.email', readonly=False)
|
|
channel_id = fields.Many2one('mail.channel', string='Channel', ondelete='cascade')
|
|
fetched_message_id = fields.Many2one('mail.message', string='Last Fetched')
|
|
seen_message_id = fields.Many2one('mail.message', string='Last Seen')
|
|
fold_state = fields.Selection([('open', 'Open'), ('folded', 'Folded'), ('closed', 'Closed')], string='Conversation Fold State', default='open')
|
|
is_minimized = fields.Boolean("Conversation is minimized")
|
|
is_pinned = fields.Boolean("Is pinned on the interface", default=True)
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
"""Similar access rule as the access rule of the mail channel.
|
|
|
|
It can not be implemented in XML, because when the record will be created, the
|
|
partner will be added in the channel and the security rule will always authorize
|
|
the creation.
|
|
"""
|
|
if not self.env.is_admin():
|
|
for vals in vals_list:
|
|
if 'channel_id' in vals:
|
|
channel_id = self.env['mail.channel'].browse(vals['channel_id'])
|
|
if not channel_id._can_invite(vals.get('partner_id')):
|
|
raise AccessError(_('This user can not be added in this channel'))
|
|
return super(ChannelPartner, self).create(vals_list)
|
|
|
|
def write(self, vals):
|
|
if not self.env.is_admin():
|
|
if {'channel_id', 'partner_id', 'partner_email'} & set(vals):
|
|
raise AccessError(_('You can not write on this field'))
|
|
return super(ChannelPartner, self).write(vals)
|