Skip to content

Commit

Permalink
[FIX] container_accessibility : Changes to check for user limit only …
Browse files Browse the repository at this point in the history
…when restricted user are being created and changes to check for user limit when restricted group is added for a user

Changed group_ids to groups_id

Removed extra group assignment to a variable
  • Loading branch information
ByteMeAsap committed Feb 6, 2025
1 parent e3eae21 commit 79e80f0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions container_accessibility/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def get_view(self, view_id=None, view_type="form", **options):

def write(self, vals):
is_restricted = self.env.user.is_restricted_user()
group_restricted = self.env.ref("container_accessibility.group_restricted")
restricted_reified_field = "in_group_%s" % group_restricted.id
user_type_category = self.env.ref("base.module_category_user_type")
user_type_groups = self.env["res.groups"].search(
[("category_id", "=", user_type_category.id)], order="id ASC"
Expand All @@ -67,9 +69,7 @@ def write(self, vals):

# Automatically add the restricted group for ux
if is_restricted:
group_restricted = self.env.ref("container_accessibility.group_restricted")
group_user = self.env.ref("base.group_user")
restricted_reified_field = "in_group_%s" % group_restricted.id

internal_user = vals.get(user_type_reified_field) == group_user.id
if internal_user:
Expand Down Expand Up @@ -99,8 +99,9 @@ def write(self, vals):
if (
"active" in vals
and vals["active"]
or "group_ids" in vals
or "groups_id" in vals
or user_type_reified_field in vals
or restricted_reified_field in vals
) and self._get_user_limit():
self._check_user_limit_exceeded()

Expand All @@ -109,8 +110,8 @@ def write(self, vals):
@api.model_create_multi
def create(self, vals_list):
# Automatically add the restricted group for ux
group_restricted = self.env.ref("container_accessibility.group_restricted")
if self.env.user.is_restricted_user():
group_restricted = self.env.ref("container_accessibility.group_restricted")
group_user = self.env.ref("base.group_user")
user_type_category = self.env.ref("base.module_category_user_type")
user_type_groups = self.env["res.groups"].search(
Expand All @@ -131,8 +132,10 @@ def create(self, vals_list):
vals[restricted_reified_field] = True

res = super().create(vals_list)
if self._get_user_limit():
self._check_user_limit_exceeded()
for rec in res:
if rec.groups_id.filtered(lambda g_id: g_id == group_restricted):
if self._get_user_limit():
self._check_user_limit_exceeded()
return res

def _create_user_from_template(self, values):
Expand Down

0 comments on commit 79e80f0

Please # to comment.