diff --git a/document_page_access_group_user_role/README.rst b/document_page_access_group_user_role/README.rst index da78eeab3e5..8b160bc9fc7 100644 --- a/document_page_access_group_user_role/README.rst +++ b/document_page_access_group_user_role/README.rst @@ -42,7 +42,7 @@ Usage #. Go to `Knowledge / Pages` and create or edit one. #. Set in the "Roles" tab the one we have just created. #. Go back to the role, edit it and add any group(s). -#. The role groups will have been added in the "Security" tab. +#. The role users will have been added in the "Security" tab. Bug Tracker =========== diff --git a/document_page_access_group_user_role/__manifest__.py b/document_page_access_group_user_role/__manifest__.py index 45f5a0fc22c..54a075cb804 100644 --- a/document_page_access_group_user_role/__manifest__.py +++ b/document_page_access_group_user_role/__manifest__.py @@ -4,7 +4,7 @@ "name": "Document Page Access Group User Role", "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/knowledge", - "version": "16.0.1.0.0", + "version": "16.0.1.1.0", "depends": ["document_page_access_group", "base_user_role"], "license": "AGPL-3", "category": "Knowledge", diff --git a/document_page_access_group_user_role/migrations/16.0.1.1.0/post-migration.py b/document_page_access_group_user_role/migrations/16.0.1.1.0/post-migration.py new file mode 100644 index 00000000000..cd6bbf60b77 --- /dev/null +++ b/document_page_access_group_user_role/migrations/16.0.1.1.0/post-migration.py @@ -0,0 +1,12 @@ +# 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", "!=", [])]) + for page in pages: + page.role_ids = False + page._compute_user_ids() diff --git a/document_page_access_group_user_role/models/document_page.py b/document_page_access_group_user_role/models/document_page.py index f9bf89cfc3c..a4db0ed05cd 100644 --- a/document_page_access_group_user_role/models/document_page.py +++ b/document_page_access_group_user_role/models/document_page.py @@ -7,7 +7,7 @@ class DocumentPage(models.Model): _inherit = "document.page" - groups_id = fields.Many2many(compute="_compute_groups_id", store=True) + user_ids = fields.Many2many(compute="_compute_user_ids", store=True, readonly=False) role_ids = fields.Many2many( comodel_name="res.users.role", relation="document_page_user_roles_rel", @@ -16,8 +16,8 @@ class DocumentPage(models.Model): string="Roles", ) - @api.depends("role_ids", "role_ids.implied_ids") - def _compute_groups_id(self): - """Create a compute to auto-set all the groups of the related roles.""" + @api.depends("role_ids", "role_ids.users") + def _compute_user_ids(self): + """Create a compute to auto-set all the users of the related roles.""" for item in self: - item.groups_id = item.mapped("role_ids.implied_ids") + item.user_ids += item.mapped("role_ids.users") diff --git a/document_page_access_group_user_role/readme/USAGE.rst b/document_page_access_group_user_role/readme/USAGE.rst index 568c9352f98..4d593dcabd3 100644 --- a/document_page_access_group_user_role/readme/USAGE.rst +++ b/document_page_access_group_user_role/readme/USAGE.rst @@ -2,4 +2,4 @@ #. Go to `Knowledge / Pages` and create or edit one. #. Set in the "Roles" tab the one we have just created. #. Go back to the role, edit it and add any group(s). -#. The role groups will have been added in the "Security" tab. +#. The role users will have been added in the "Security" tab. diff --git a/document_page_access_group_user_role/static/description/index.html b/document_page_access_group_user_role/static/description/index.html index 60c98a6a493..f725f4beb2c 100644 --- a/document_page_access_group_user_role/static/description/index.html +++ b/document_page_access_group_user_role/static/description/index.html @@ -1,4 +1,3 @@ - @@ -391,7 +390,7 @@

Usage

  • Go to Knowledge / Pages and create or edit one.
  • Set in the “Roles” tab the one we have just created.
  • Go back to the role, edit it and add any group(s).
  • -
  • The role groups will have been added in the “Security” tab.
  • +
  • The role users will have been added in the “Security” tab.
  • diff --git a/document_page_access_group_user_role/tests/test_document_page_access_group_user_role.py b/document_page_access_group_user_role/tests/test_document_page_access_group_user_role.py index f830ee1d4ce..777e2eaa24f 100644 --- a/document_page_access_group_user_role/tests/test_document_page_access_group_user_role.py +++ b/document_page_access_group_user_role/tests/test_document_page_access_group_user_role.py @@ -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) diff --git a/document_page_access_group_user_role/views/document_page_views.xml b/document_page_access_group_user_role/views/document_page_views.xml index 2a0fe5ae7f9..615e30f58c1 100644 --- a/document_page_access_group_user_role/views/document_page_views.xml +++ b/document_page_access_group_user_role/views/document_page_views.xml @@ -8,20 +8,25 @@ ref="document_page_access_group.document_page_access_group_view_wiki_form" /> - - - + + + - + - - + + - + {'readonly': [('role_ids', '!=', [])]}