[FIX] base: Prevent user_admin deletion

Purpose
=======

Tremendous amount of support tickets (ex: 3800405) are opened because the user_admin
has been removed and is referenced everywhere, leading to tracebacks or
the impossibility to install a new application as res.group configurations
all relies on this, like:

<record id="group_helpdesk_manager" model="res.groups">
    <field name="name">Administrator</field>
    <field name="category_id" ref="base.module_category_services_helpdesk"/>
    <field name="implied_ids" eval="[(4, ref('group_helpdesk_user'))]"/>
    <field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>

We could adapt all the occurences (severeal hundreds) to ensure robustness
but this won't prevent developer from introducing new use cases + the user
can be archived instead if we want to remove him from the pricing.

closes odoo/odoo#158885

Taskid: 3802440
X-original-commit: b55994b4c5e737aae593eb0419f96347ad90bebb
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Yannick Tivisse
2024-03-25 08:33:15 +00:00
parent a654c78b94
commit c8456e2f3e
2 changed files with 12 additions and 0 deletions
+9
View File
@@ -31914,6 +31914,15 @@ msgstr ""
msgid "You cannot delete the %s record."
msgstr ""
#. module: base
#. odoo-python
#: code:addons/base/models/res_users.py:0
#, python-format
msgid ""
"You cannot delete the admin user because it is utilized in various places "
"(such as security configurations,...). Instead, archive it."
msgstr ""
#. module: base
#. odoo-python
#: code:addons/base/models/res_lang.py:0
+3
View File
@@ -701,6 +701,9 @@ class Users(models.Model):
default_user_template = self.env.ref('base.default_user', False)
if SUPERUSER_ID in self.ids:
raise UserError(_('You can not remove the admin user as it is used internally for resources created by Odoo (updates, module installation, ...)'))
user_admin = self.env.ref('base.user_admin', raise_if_not_found=False)
if user_admin and user_admin in self:
raise UserError(_('You cannot delete the admin user because it is utilized in various places (such as security configurations,...). Instead, archive it.'))
self.env.registry.clear_cache()
if (portal_user_template and portal_user_template in self) or (default_user_template and default_user_template in self):
raise UserError(_('Deleting the template users is not allowed. Deleting this profile will compromise critical functionalities.'))