Skip to content

Commit ca24c1b

Browse files
committed
[IMP] base: ensure public user exists and prevent deletion
Steps to Reproduce: 1. Create a database without installing the Website module. 2. Navigate to archived users and delete the "Public User." 3. Attempt to log in to the database from another browser or incognito mode. 4. An internal server error occurs because the public user does not exist, making the login page inaccessible. Issue: Previously, it was possible to delete the public user, leading to an internal server error due to its absence, which prevented public access to the login page. Solution: - Implemented a restriction to prevent the deletion of the public user, similar to portal and default users. - Added a test case to validate this functionality and ensure the public user cannot be deleted. task-4423568 closes odoo#234285 X-original-commit: 0d5cf53 Signed-off-by: Raphael Collet <rco@odoo.com> Signed-off-by: Sanjay Sharma (shsa) <shsa@odoo.com>
1 parent 10586fe commit ca24c1b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

odoo/addons/base/models/res_users.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ def write(self, vals):
649649
@api.ondelete(at_uninstall=True)
650650
def _unlink_except_master_data(self):
651651
portal_user_template = self.env.ref('base.template_portal_user_id', False)
652+
public_user = self.env.ref('base.public_user', False)
652653
if SUPERUSER_ID in self.ids:
653654
raise UserError(_('You can not remove the admin user as it is used internally for resources created by Odoo (updates, module installation, ...)'))
654655
user_admin = self.env.ref('base.user_admin', raise_if_not_found=False)
@@ -657,6 +658,8 @@ def _unlink_except_master_data(self):
657658
self.env.registry.clear_cache()
658659
if portal_user_template and portal_user_template in self:
659660
raise UserError(_('Deleting the template users is not allowed. Deleting this profile will compromise critical functionalities.'))
661+
if public_user and public_user in self:
662+
raise UserError(_("Deleting the public user is not allowed. Deleting this profile will compromise critical functionalities."))
660663

661664
@api.model
662665
def name_search(self, name='', domain=None, operator='ilike', limit=100):

odoo/addons/base/tests/test_res_users.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ def test_deactivate_portal_users_archive_and_remove(self):
222222
self.assertTrue(portal_partner_2.exists(), 'Should have kept the partner')
223223
self.assertEqual(asked_deletion_2.state, 'fail', 'Should have marked the deletion as failed')
224224

225+
def test_delete_public_user(self):
226+
"""Test that the public user cannot be deleted."""
227+
public_user = self.env.ref('base.public_user')
228+
public_partner = public_user.partner_id
229+
230+
# Attempt to delete the public user
231+
with self.assertRaises(UserError, msg="Public user should not be deletable"):
232+
public_user.unlink()
233+
234+
# Ensure the public user still exists and is inactive
235+
self.assertTrue(public_user.exists() and not public_user.active, "Public user should still exist and be inactive")
236+
self.assertTrue(public_partner.exists() and not public_partner.active, "Public partner should still exist and be inactive")
237+
225238
def test_user_home_action_restriction(self):
226239
test_user = new_test_user(self.env, 'hello world')
227240

0 commit comments

Comments
 (0)