Skip to content

Commit

Permalink
[FIX] document_page_approval: Add rule to manager group users from hi…
Browse files Browse the repository at this point in the history
…story pages
  • Loading branch information
victoralmau committed Apr 7, 2021
1 parent e5b5fdd commit 5c2e7b1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
13 changes: 13 additions & 0 deletions document_page_approval/security/document_page_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@
<field name="perm_unlink" eval="True" />
<field name="perm_create" eval="True" />
</record>
<record model="ir.rule" id="rule_change_request_manager">
<field name="name">Change Request Manager</field>
<field name="model_id" ref="model_document_page_history" />
<field
name="groups"
eval="[(6, 0, [ref('document_page.group_document_manager')])]"
/>
<field name="domain_force">[(1, '=', 1)]</field>
<field name="perm_read" eval="True" />
<field name="perm_write" eval="True" />
<field name="perm_unlink" eval="True" />
<field name="perm_create" eval="True" />
</record>
</odoo>
40 changes: 40 additions & 0 deletions document_page_approval/tests/test_document_page_approval.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from odoo.exceptions import AccessError
from odoo.tests import common


Expand Down Expand Up @@ -25,6 +26,16 @@ def setUp(self):
],
}
)
self.manager_gid = self.env.ref("document_page.group_document_manager")
self.user_manager = self.env["res.users"].create(
{
"name": "Test document manager",
"login": "Test document manager",
"groups_id": [
(6, 0, [self.env.ref("base.group_user").id, self.manager_gid.id])
],
}
)
# demo_approval
self.category2 = self.page_obj.create(
{
Expand Down Expand Up @@ -136,6 +147,35 @@ def test_change_request_from_scratch(self):
self.assertEqual(page.approved_date, chreq.approved_date)
self.assertEqual(page.approved_uid, chreq.approved_uid)

def test_check_rules(self):
page = self.page2
# aprove everything
self.history_obj.search(
[("page_id", "=", page.id), ("state", "!=", "approved")]
).action_approve()
# new change request from scrath
chreq = self.history_obj.create(
{
"page_id": page.id,
"summary": "Changed something",
"content": "New content",
}
)
self.assertEqual(chreq.state, "draft")
chreq.action_to_approve()
self.assertEqual(chreq.state, "to approve")
chreq.action_cancel()
self.assertEqual(chreq.state, "cancelled")
chreq.sudo().action_draft()
chreq.invalidate_cache()
with self.assertRaises(AccessError):
self.assertEqual(chreq.with_user(self.user2).state, "draft")
self.assertEqual(chreq.state, "draft")
chreq.invalidate_cache()
self.assertEqual(chreq.with_user(self.user_manager).state, "draft")
chreq.action_approve()
self.assertEqual(chreq.state, "approved")

def test_get_approvers_guids(self):
"""Get approver guids."""
page = self.page2
Expand Down

0 comments on commit 5c2e7b1

Please sign in to comment.