-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] document_page_access_group_user_role: Users compatibility
TT48786
- Loading branch information
1 parent
5c153b9
commit e24658b
Showing
8 changed files
with
68 additions
and
42 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
13 changes: 13 additions & 0 deletions
13
document_page_access_group_user_role/migrations/16.0.1.1.0/post-migration.py
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,13 @@ | ||
# Copyright 2024 Tecnativa - Víctor Martínez | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
"""Pages that had roles should now have the correct users.""" | ||
pages = env["document.page"].sudo().search([("role_ids", "!=", False)]) | ||
for page in pages: | ||
users = page.mapped("role_ids.users") | ||
page.role_ids = False | ||
page.user_ids = users |
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
55 changes: 36 additions & 19 deletions
55
document_page_access_group_user_role/tests/test_document_page_access_group_user_role.py
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,30 +1,47 @@ | ||
# Copyright 2024 Tecnativa - Víctor Martínez | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo.tests.common import users | ||
|
||
from odoo.addons.base.tests.common import BaseCommon | ||
from odoo.addons.document_page_access_group.tests.common import ( | ||
TestDocumentPageAccessGroupBase, | ||
) | ||
|
||
|
||
class TestDocumentPageAccessGroupUserRole(BaseCommon): | ||
class TestDocumentPageAccessGroupUserRole(TestDocumentPageAccessGroupBase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.page = cls.env["document.page"].create( | ||
{"name": "Page 1", "type": "content"} | ||
) | ||
cls.group_a = cls.env["res.groups"].create({"name": "Test group A"}) | ||
cls.group_b = cls.env["res.groups"].create({"name": "Test group B"}) | ||
cls.user_role = cls.env["res.users.role"].create( | ||
{"name": "Test role", "implied_ids": [(6, 0, [cls.group_a.id])]} | ||
{ | ||
"name": "Test role", | ||
"implied_ids": [(6, 0, [cls.group.id])], | ||
"users": [(6, 0, [cls.manager_user.id])], | ||
} | ||
) | ||
cls.role_page = cls.env["document.page"].create( | ||
{ | ||
"name": "Role Page (test role)", | ||
"type": "content", | ||
"role_ids": [(6, 0, [cls.user_role.id])], | ||
} | ||
) | ||
|
||
def test_document_page_role(self): | ||
self.assertFalse(self.page.groups_id) | ||
self.page.role_ids = [(4, self.user_role.id)] | ||
self.assertIn(self.group_a, self.page.groups_id) | ||
self.assertNotIn(self.group_b, self.page.groups_id) | ||
self.user_role.implied_ids = [(4, self.group_b.id)] | ||
self.assertIn(self.group_a, self.page.groups_id) | ||
self.assertIn(self.group_b, self.page.groups_id) | ||
self.page.role_ids = [(6, 0, [])] | ||
self.assertNotIn(self.group_a, self.page.groups_id) | ||
self.assertNotIn(self.group_b, self.page.groups_id) | ||
def test_document_page_role_misc(self): | ||
self.assertFalse(self.role_page.groups_id) | ||
self.assertTrue(self.role_page.user_ids) | ||
|
||
@users("test-user") | ||
def test_document_page_role_access_01(self): | ||
pages = self.env["document.page"].search([]) | ||
self.assertIn(self.public_page, pages) | ||
self.assertNotIn(self.knowledge_page, pages) | ||
self.assertIn(self.user_page, pages) | ||
self.assertNotIn(self.role_page, pages) | ||
|
||
@users("test-manager-user") | ||
def test_document_page_role_access_02(self): | ||
pages = self.env["document.page"].search([]) | ||
self.assertIn(self.public_page, pages) | ||
self.assertIn(self.knowledge_page, pages) | ||
self.assertNotIn(self.user_page, pages) | ||
self.assertIn(self.role_page, pages) |
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