PURPOSE Make aliases usage more unique, prevent re-using bounce or catchall aliases and remove auto-uniqueness of aliases. SPECIFICATIONS Before this commit, user could create an email alias having same name as catchall/bounce email alias, which should not happen. Also, while creating or duplicating alias, if the same name was already available, a new unique name was generated by adding a sequence number to existing name. This behavior is not considered as a good one as it magically creates aliases different from what user expects. User could even not own the newly-created alias, leading to a broken mail gateway. In this commit we improve that behavior by ensuring that no duplicate alias name should be entered while creation / updation for both catcall/bounce and mail alias. Also, while duplicating an alias, name will now be blank by default to force user to enter the name. Finally when creating an alias an error is raised if the name is already taken. Task ID 2160070
21 lines
765 B
Python
21 lines
765 B
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_create_multi
|
|
def create(self, vals_list):
|
|
for vals in vals_list:
|
|
if vals.get('key') in ['mail.bounce.alias', 'mail.catchall.alias']:
|
|
vals['value'] = self.env['mail.alias']._clean_and_check_unique(vals.get('value'))
|
|
return super().create(vals_list)
|
|
|
|
def write(self, vals):
|
|
if 'value' in vals and self.key in ['mail.bounce.alias', 'mail.catchall.alias']:
|
|
vals['value'] = self.env['mail.alias']._clean_and_check_unique(vals.get('value'))
|
|
return super().write(vals)
|