Skip to content

Commit

Permalink
[document_page_approval] FIX BUG: am_i_approver was being run as sudo…
Browse files Browse the repository at this point in the history
…(), hence always giving the user Approving rights.
  • Loading branch information
ivantodorovich committed Sep 15, 2018
1 parent 3a142e7 commit 503e12a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
13 changes: 8 additions & 5 deletions document_page_approval/models/document_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ def can_user_approve_this_page(self, user):
# if it's not required, anyone can approve
if not self.is_approval_required:
return True
# to approve, you must have approver rights
approver_group_id = self.env.ref(
'document_page_approval.group_document_approver_user')
if approver_group_id not in user.groups_id:
# if user belongs to 'Knowledge / Manager', he can approve anything
if user.has_group('document_page.group_document_manager'):
return True
# to approve, user must have approver rights
if not user.has_group(
'document_page_approval.group_document_approver_user'):
return False
# and belong to at least one of the approver_groups (if any is set)
# if there aren't any approver_groups_defined, user can approve
if not self.approver_group_ids:
return True
# to approve, user must belong to any of the approver groups
return len(user.groups_id & self.approver_group_ids) > 0

@api.multi
Expand Down
10 changes: 2 additions & 8 deletions document_page_approval/models/document_page_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class DocumentPageHistory(models.Model):
)

am_i_approver = fields.Boolean(
compute='_compute_am_i_approver'
related='page_id.am_i_approver',
related_sudo=False,
)

page_url = fields.Text(
Expand Down Expand Up @@ -151,13 +152,6 @@ def _compute_am_i_owner(self):
for rec in self:
rec.am_i_owner = (rec.create_uid == self.env.user)

@api.multi
def _compute_am_i_approver(self):
"""check if current user is a approver"""
for rec in self:
rec.am_i_approver = rec.page_id.can_user_approve_this_page(
self.env.user)

@api.multi
def _compute_page_url(self):
"""Compute the page url."""
Expand Down

0 comments on commit 503e12a

Please sign in to comment.