Skip to content

Commit

Permalink
[FIX] base_user_role: default roles
Browse files Browse the repository at this point in the history
When granting access to a contact, a copy from Portal User Template
is made for it. But applied default roles are the ones from Default
User Template, causing an error when trying to assign both internal
and portal types to new user.
  • Loading branch information
danielduqma committed Oct 30, 2024
1 parent 778242d commit c0b759a
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions base_user_role/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ def _default_role_lines(self):
default_user = self.env.ref("base.default_user", raise_if_not_found=False)
default_values = []
if default_user:
for role_line in default_user.with_context(active_test=False).role_line_ids:
default_values.append(
{
"role_id": role_line.role_id.id,
"date_from": role_line.date_from,
"date_to": role_line.date_to,
"is_enabled": role_line.is_enabled,
}
)
default_values = default_user._get_role_lines_vals_from_user()
return default_values

def _get_role_lines_vals_from_user(self):
self.ensure_one()
default_values = []
for role_line in self.with_context(active_test=False).role_line_ids:
default_values.append(
{
"role_id": role_line.role_id.id,
"date_from": role_line.date_from,
"date_to": role_line.date_to,
"is_enabled": role_line.is_enabled,
}
)
return default_values

@api.depends("role_line_ids.role_id")
Expand Down Expand Up @@ -97,3 +103,12 @@ def set_groups_from_roles(self, force=False):
vals = {"groups_id": groups}
super(ResUsers, user).write(vals)
return True

def copy(self, default=None):
self.ensure_one()
portal_user = self.env.ref(

Check warning on line 109 in base_user_role/models/user.py

View check run for this annotation

Codecov / codecov/patch

base_user_role/models/user.py#L108-L109

Added lines #L108 - L109 were not covered by tests
"base.template_portal_user_id", raise_if_not_found=False
)
if portal_user and self == portal_user:
default["role_line_ids"] = portal_user._get_role_lines_vals_from_user()
return super().copy(default=default)

Check warning on line 114 in base_user_role/models/user.py

View check run for this annotation

Codecov / codecov/patch

base_user_role/models/user.py#L113-L114

Added lines #L113 - L114 were not covered by tests

0 comments on commit c0b759a

Please sign in to comment.