[FIX] base: prevent traceback while deleting Portal or Default User Template

When the user deletes the 'Portal User Template'  and when any new portal user
will do signup, then traceback will be generated.

If User deletes the 'Portal User Template', then no new portal user will be
created. Also, new portal user will see the traceback as it is generated in
UI.

Steps To Produce for Portal User Template:-

1) Install the 'auth_signup' module
2) Go to Settings > Users
3) Filter only 'Inactive Users'
4) Delete the 'Portal User Template'
5) Open the Incognito tab and click on 'Don't have an account?'
6) Fill required values and click on the 'Sign Up' button

Traceback will be generated on the portal user side as well as in the
backend (Terminal)

Steps To Produce for Default User Template:-

1) Go to Settings > Users
2) Filter only 'Inactive Users'
3) Delete the 'Default User Template'
4) Try to install 'website' or 'hr_timesheet' module

Traceback will be generated

Applying these changes will resolve this issue.

sentry-4184429514,4274176666,4147914005

closes odoo/odoo#127516

X-original-commit: c3e5bed9307498b435857f7736c20cefde3ed6a7
Signed-off-by: Vranckx Florian (flvr) <flvr@odoo.com>
Signed-off-by: Urvi Soni (uso) <uso@odoo.com>
This commit is contained in:
uso-odoo
2023-07-17 18:13:08 +02:00
committed by flvr-odoo
parent 000bf53251
commit 07f04e09f3
2 changed files with 12 additions and 1 deletions
+7
View File
@@ -30976,6 +30976,13 @@ msgstr ""
msgid "You can not create recursive tags."
msgstr ""
#. module: base
#. odoo-python
#: code:addons/base/models/res_users.py:0
#, python-format
msgid "Deleting the template users is not allowed. Deleting this profile will compromise critical functionalities."
msgstr ""
#. module: base
#: model:ir.model.constraint,message:base.constraint_res_users_login_key
msgid "You can not have two users with the same login!"
+5 -1
View File
@@ -661,10 +661,14 @@ class Users(models.Model):
return res
@api.ondelete(at_uninstall=True)
def _unlink_except_superuser(self):
def _unlink_except_master_data(self):
portal_user_template = self.env.ref('base.template_portal_user_id', False)
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, ...)'))
self.clear_caches()
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.'))
@api.model
def _name_search(self, name, domain=None, operator='ilike', limit=None, order=None):