[FIX] base: superuser cannot become active

This commit is contained in:
Raphael Collet
2018-09-27 09:54:28 +02:00
parent 13d3456791
commit 3a30391e9d
2 changed files with 15 additions and 7 deletions
+4 -6
View File
@@ -431,12 +431,10 @@ class Users(models.Model):
@api.multi
def write(self, values):
if values.get('active') == False:
for user in self:
if user.id == SUPERUSER_ID:
raise UserError(_("You cannot deactivate the admin user."))
elif user.id == self._uid:
raise UserError(_("You cannot deactivate the user you're currently logged in as."))
if values.get('active') and SUPERUSER_ID in self._ids:
raise UserError(_("You cannot activate the superuser."))
if values.get('active') == False and self._uid in self._ids:
raise UserError(_("You cannot deactivate the user you're currently logged in as."))
if values.get('active'):
for user in self:
+11 -1
View File
@@ -4,7 +4,8 @@
import ast
import unittest
from odoo.exceptions import ValidationError
from odoo import SUPERUSER_ID
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import TransactionCase, tagged
from odoo.tools import mute_logger
from odoo.tools.safe_eval import safe_eval, const_eval
@@ -556,3 +557,12 @@ class TestGroups(TransactionCase):
a = self.env['res.groups'].with_context(lang='en_US').create({'name': 'A'})
b = a.copy()
self.assertFalse(a.name == b.name)
class TestUsers(TransactionCase):
def test_superuser(self):
""" The superuser is inactive and must remain as such. """
user = self.env['res.users'].browse(SUPERUSER_ID)
self.assertFalse(user.active)
with self.assertRaises(UserError):
user.write({'active': True})