When installing a new module, the access of the Default Template User is propagated to any existing employee (introduced at aefb05eb497a8a16a). This can be problematic in companies that don't want all their employees to become manager by default. Allow to disable this behaviour in a settings. This is the version of the patch targetting stable version that is not configurable through the interface, manually creating an ICP base_setup.default_user_rights_minimal=True as the way to change the behaviour. Closes odoo/odoo#149224 Task-id 3685856 closes odoo/odoo#154816 X-original-commit: 70f66f147bb0c133be6ae3fd2b11438afe2366a5 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models, api
|
|
from odoo.tools.misc import str2bool
|
|
|
|
|
|
class ResUsers(models.Model):
|
|
_inherit = 'res.users'
|
|
|
|
@api.model
|
|
def web_create_users(self, emails):
|
|
|
|
# Reactivate already existing users if needed
|
|
deactivated_users = self.with_context(active_test=False).search([('active', '=', False), '|', ('login', 'in', emails), ('email', 'in', emails)])
|
|
for user in deactivated_users:
|
|
user.active = True
|
|
|
|
new_emails = set(emails) - set(deactivated_users.mapped('email'))
|
|
|
|
# Process new email addresses : create new users
|
|
for email in new_emails:
|
|
default_values = {'login': email, 'name': email.split('@')[0], 'email': email, 'active': True}
|
|
user = self.with_context(signup_valid=True).create(default_values)
|
|
|
|
return True
|
|
|
|
def _default_groups(self):
|
|
"""Default groups for employees
|
|
|
|
If base_setup.default_user_minimal is set, only the "Employee" group is used
|
|
"""
|
|
if str2bool(self.env['ir.config_parameter'].sudo().get_param("base_setup.default_user_rights_minimal"), default=False):
|
|
employee_group = self.env.ref("base.group_user")
|
|
# force the trans_implied_ids during default for consistency in the interface
|
|
return employee_group | employee_group.trans_implied_ids
|
|
return super()._default_groups()
|
|
|
|
def _apply_groups_to_existing_employees(self):
|
|
"""
|
|
If base_setup.default_user_rights_minimal is set, do not apply any new groups to existing employees
|
|
"""
|
|
if str2bool(self.env['ir.config_parameter'].sudo().get_param("base_setup.default_user_rights_minimal"), default=False):
|
|
return False
|
|
return super()._apply_groups_to_existing_employees()
|