Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] check if write on user are allowed, instead of static check on … #174

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions partner_hide_technical_user/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@

# Overload Section
def write(self, vals):
self._check_technical_partner_access_user()
self._check_technical_partner_access_user("write")
return super().write(vals)

def unlink(self):
self._check_technical_partner_access_user()
self._check_technical_partner_access_user("unlink")

Check warning on line 27 in partner_hide_technical_user/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

partner_hide_technical_user/models/res_partner.py#L27

Added line #L27 was not covered by tests
return super().unlink()

# Custom section
def _check_technical_partner_access_user(self):
def _check_technical_partner_access_user(self, operation):
# We use SUPERUSER_ID to be sure to not skip some users, due to
# some custom access rules deployed on databases
ResUsers = self.env["res.users"].sudo()
users = ResUsers.with_context(active_test=False).search(
[("partner_id", "in", self.ids)]
ResUsers = self.env["res.users"]
users = (
ResUsers.sudo()
.with_context(active_test=False)
.search([("partner_id", "in", self.ids)])
)
if not users:
return
Expand All @@ -49,13 +51,9 @@
return

# Check if current user has correct access right
if not self.env.user.has_group("base.group_erp_manager"):
if not ResUsers.check_access_rights(operation, raise_exception=False):
raise UserError(
_(
"You must be part of the group Administration / Access"
" Rights to update partners associated to"
" users.\n- %s"
)
_("You have no right to update partners associated to" " users.\n- %s")
% ("\n- ".join(users.mapped("name")))
)

Expand Down
Loading