From c8456e2f3e49066af2b85e4a04acd24b89ab05d2 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Tue, 19 Mar 2024 12:23:51 +0000 Subject: [PATCH] [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: Administrator 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) --- odoo/addons/base/i18n/base.pot | 9 +++++++++ odoo/addons/base/models/res_users.py | 3 +++ 2 files changed, 12 insertions(+) diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index 2f11cc7427c..198c0fa7b7d 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -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 diff --git a/odoo/addons/base/models/res_users.py b/odoo/addons/base/models/res_users.py index 141aeec193e..49faa4d71ab 100644 --- a/odoo/addons/base/models/res_users.py +++ b/odoo/addons/base/models/res_users.py @@ -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.'))