Files
odoo_source/addons/mail/models/ir_config_parameter.py
T
Thibault Delavallée e187ba1cb3 [FIX] mail: correctly override ICP set_param method for alias parameters
Currently ICP parameter clean and check is done at create / write override.
However it should be done at ``set_param`` level to avoid messing with the
specific behavior of ir.config_parameter with falsy values.

Task-3453343 (Mail: Cleanup Alias Usage)
Prepares Task-36879 (Mail: Support MultiCompany Aliases)

Part-of: odoo/odoo#130632
2023-08-09 17:04:25 +02:00

34 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
class IrConfigParameter(models.Model):
_inherit = 'ir.config_parameter'
@api.model
def set_param(self, key, value):
if key == 'mail.restrict.template.rendering':
group_user = self.env.ref('base.group_user')
group_mail_template_editor = self.env.ref('mail.group_mail_template_editor')
if not value and group_mail_template_editor not in group_user.implied_ids:
group_user.implied_ids |= group_mail_template_editor
elif value and group_mail_template_editor in group_user.implied_ids:
# remove existing users, including inactive template user
# admin will regain the right via implied_ids on group_system
group_user._remove_group(group_mail_template_editor)
# sanitize, normalize and check uniqueness of catchall / bounce aliases
# note that False = unlink ICP
elif key in {'mail.bounce.alias', 'mail.catchall.alias'} and value:
value = self.env['mail.alias']._sanitize_alias_name(value)
if value:
self.env['mail.alias']._check_unique([value], skip_icp_keys={key})
# sanitize and normalize allowed catchall domains
elif key == 'mail.catchall.domain.allowed' and value:
value = self.env['mail.alias']._clean_and_check_mail_catchall_allowed_domains(value)
return super().set_param(key, value)