[FIX] base_user_role: default user multi-company

When creating user, default roles are using `base.default_user`, which
in multi-company case, can be from different company than user is being
created for. If thats the case, user creating another user, will get
access error, when trying to read default template user.

To work around that, we use sudo, to make sure, template user data can
be read regardless of a company.

Also improved the way base_user_role tests are run. Changed base test
class from TransactionCase to SavepointCase.

From how tests are ran perspective, both classes behave the same: each
test uses set up which is roll backed after.

But the difference is that SavepointCase case is much faster, because
it calls setUpClass once and saves this case for all tests (reusing
saved state).
This commit is contained in:
Andrius Laukavičius
2020-02-25 15:22:03 +02:00
parent c414dbd0cd
commit 115aba15df
4 changed files with 77 additions and 57 deletions

View File

@@ -21,8 +21,7 @@ class ResUsers(models.Model):
@api.model
def _default_role_lines(self):
default_user = self.env.ref(
"base.default_user", raise_if_not_found=False
)
'base.default_user', raise_if_not_found=False).sudo()
default_values = []
if default_user:
for role_line in default_user.role_line_ids: