Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion document_page_approval/models/document_page_history.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
# Copyright 2026 NuoBiT Solutions SL - Deniz Gallo <dgallo@nuobit.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


Expand Down Expand Up @@ -92,7 +93,11 @@ def action_approve(self):
"""Set a change request as approved."""
for rec in self:
if rec.state not in ["draft", "to approve"]:
self.env._("Can't approve page in '%(state)s' state.", state=rec.state)
raise UserError(
self.env._(
"Can't approve page in '%(state)s' state.", state=rec.state
)
)
if not rec.am_i_approver:
groups_str = ", ".join(
g.display_name for g in rec.page_id.approver_group_ids
Expand Down
18 changes: 18 additions & 0 deletions document_page_approval/tests/test_document_page_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,24 @@ def test_action_to_approve_only_from_draft(self):
with self.assertRaises(UserError):
chreq.action_to_approve()

def test_action_approve_only_from_draft_or_pending(self):
"""Ensure approved or cancelled requests cannot be approved"""
for state in ("approved", "cancelled"):
with self.subTest(state=state):
chreq = self.history_obj.create(
{
"page_id": self.page2.id,
"state": state,
}
)
with self.assertRaises(UserError) as error:
chreq.with_user(self.user2).action_approve()
self.assertEqual(
error.exception.args[0],
f"Can't approve page in '{state}' state.",
)
self.assertEqual(chreq.state, state)

def test_approval_permission_check(self):
"""Ensure approval is restricted to approvers"""
chreq = self.history_obj.create(
Expand Down