Files
odoo_source/addons/mail/models/ir_config_parameter.py
T
Martin Trigaux d3b3a30c84 [FIX] mail: remove group when unchecking the box
When activating the option "Restrict Template Rendering" the employee
group no longer gets the group automatically via the Implied Groups
field. However this did not have much effect because
- all the existing employees still had the group
- new users had the group via the template user

Remove the group with active_test=False to include the Default
Template User in the list.

Before this commit it was a bit confusing that new users still got the
group by default, even after deactivating the option in the settings.

closes odoo/odoo#110900

X-original-commit: ea0f674ac15964aaeb3def31758cec558b354a99
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2023-01-26 12:19:12 +01:00

40 lines
1.8 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_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')])[0]
return super().create(vals_list)
def write(self, vals):
for parameter in self:
if 'value' in vals and parameter.key in ['mail.bounce.alias', 'mail.catchall.alias'] and vals['value'] != parameter.value:
vals['value'] = self.env['mail.alias']._clean_and_check_unique([vals.get('value')])[0]
return super().write(vals)
@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:
group_user.implied_ids -= group_mail_template_editor
# remove existing users, including inactive template user
# admin will regain the right via implied_ids on group_system
group_mail_template_editor.with_context(active_test=False).users.write(
{'groups_id': [(3, group_mail_template_editor.id)]})
return super(IrConfigParameter, self).set_param(key, value)