-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] automation_oca: Add some security filters
- Loading branch information
Showing
4 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from . import test_automation_action | ||
from . import test_automation_base | ||
from . import test_automation_mail | ||
from . import test_automation_security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Copyright 2024 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests.common import users | ||
|
||
from odoo.addons.mail.tests.common import mail_new_test_user | ||
|
||
from .common import AutomationTestCase | ||
|
||
|
||
class TestAutomationSecurity(AutomationTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
# Removing rules in order to check only what we expect | ||
cls.env["ir.rule"].search( | ||
[("model_id", "=", cls.env.ref("base.model_res_partner").id)] | ||
).toggle_active() | ||
|
||
cls.user_automation_01 = mail_new_test_user( | ||
cls.env, | ||
login="user_automation_01", | ||
name="User automation 01", | ||
email="[email protected]", | ||
company_id=cls.env.user.company_id.id, | ||
notification_type="inbox", | ||
groups="base.group_user,automation_oca.group_automation_user", | ||
) | ||
cls.user_automation_02 = mail_new_test_user( | ||
cls.env, | ||
login="user_automation_02", | ||
name="User automation 01", | ||
email="[email protected]", | ||
company_id=cls.env.user.company_id.id, | ||
notification_type="inbox", | ||
groups="base.group_user,automation_oca.group_automation_user", | ||
) | ||
cls.group_1 = cls.env["res.groups"].create( | ||
{ | ||
"name": "G1", | ||
"users": [(4, cls.user_automation_01.id)], | ||
"rule_groups": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Rule 01", | ||
"model_id": cls.env.ref("base.model_res_partner").id, | ||
"domain_force": "[('id', '!=', %s)]" % cls.partner_01.id, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
cls.group_2 = cls.env["res.groups"].create( | ||
{ | ||
"name": "G2", | ||
"users": [(4, cls.user_automation_02.id)], | ||
"rule_groups": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Rule 01", | ||
"model_id": cls.env.ref("base.model_res_partner").id, | ||
"domain_force": "[('id', '!=', %s)]" % cls.partner_02.id, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
cls.configuration.editable_domain = [ | ||
("id", "in", (cls.partner_01 | cls.partner_02).ids) | ||
] | ||
cls.configuration.start_automation() | ||
cls.env["automation.configuration"].cron_automation() | ||
|
||
@users("user_automation_01") | ||
def test_security_01(self): | ||
record = self.env["automation.record"].search( | ||
[("configuration_id", "=", self.configuration.id)] | ||
) | ||
self.assertEqual(1, len(record)) | ||
self.assertEqual(self.partner_02, record.resource_ref) | ||
|
||
@users("user_automation_02") | ||
def test_security_02(self): | ||
record = self.env["automation.record"].search( | ||
[("configuration_id", "=", self.configuration.id)] | ||
) | ||
self.assertEqual(1, len(record)) | ||
self.assertEqual(self.partner_01, record.resource_ref) |