diff --git a/document_page_access_group_user_role/README.rst b/document_page_access_group_user_role/README.rst new file mode 100644 index 00000000..da78eeab --- /dev/null +++ b/document_page_access_group_user_role/README.rst @@ -0,0 +1,96 @@ +==================================== +Document Page Access Group User Role +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3dfd28474555ec556de2976f5339491a487ac211497f0396b3aa176dc457ec79 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github + :target: https://github.com/OCA/knowledge/tree/16.0/document_page_access_group_user_role + :alt: OCA/knowledge +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/knowledge-16-0/knowledge-16-0-document_page_access_group_user_role + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/knowledge&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Use of roles (module base_user_role) in Document Pages. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. Go to `Settings / Users & Companies / Roles` and create a new one. +#. 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. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +This module is part of the `OCA/knowledge `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/document_page_access_group_user_role/__init__.py b/document_page_access_group_user_role/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/document_page_access_group_user_role/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/document_page_access_group_user_role/__manifest__.py b/document_page_access_group_user_role/__manifest__.py new file mode 100644 index 00000000..45f5a0fc --- /dev/null +++ b/document_page_access_group_user_role/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "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", + "depends": ["document_page_access_group", "base_user_role"], + "license": "AGPL-3", + "category": "Knowledge", + "data": [ + "views/document_page_views.xml", + ], + "installable": True, + "maintainers": ["victoralmau"], +} diff --git a/document_page_access_group_user_role/i18n/document_page_access_group_user_role.pot b/document_page_access_group_user_role/i18n/document_page_access_group_user_role.pot new file mode 100644 index 00000000..b2c7f394 --- /dev/null +++ b/document_page_access_group_user_role/i18n/document_page_access_group_user_role.pot @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * document_page_access_group_user_role +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-05-31 10:50+0000\n" +"PO-Revision-Date: 2024-05-31 10:50+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: document_page_access_group_user_role +#: model:ir.model,name:document_page_access_group_user_role.model_document_page +msgid "Document Page" +msgstr "" + +#. module: document_page_access_group_user_role +#: model:ir.model.fields,field_description:document_page_access_group_user_role.field_document_page__role_ids +#: model_terms:ir.ui.view,arch_db:document_page_access_group_user_role.document_page_access_group_view_wiki_form +msgid "Roles" +msgstr "" diff --git a/document_page_access_group_user_role/i18n/es.po b/document_page_access_group_user_role/i18n/es.po new file mode 100644 index 00000000..4dd81ee1 --- /dev/null +++ b/document_page_access_group_user_role/i18n/es.po @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * document_page_access_group_user_role +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-05-31 10:50+0000\n" +"PO-Revision-Date: 2024-05-31 12:51+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 3.0.1\n" + +#. module: document_page_access_group_user_role +#: model:ir.model,name:document_page_access_group_user_role.model_document_page +msgid "Document Page" +msgstr "Página del documento" + +#. module: document_page_access_group_user_role +#: model:ir.model.fields,field_description:document_page_access_group_user_role.field_document_page__role_ids +#: model_terms:ir.ui.view,arch_db:document_page_access_group_user_role.document_page_access_group_view_wiki_form +msgid "Roles" +msgstr "Roles" diff --git a/document_page_access_group_user_role/models/__init__.py b/document_page_access_group_user_role/models/__init__.py new file mode 100644 index 00000000..14612b52 --- /dev/null +++ b/document_page_access_group_user_role/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import document_page diff --git a/document_page_access_group_user_role/models/document_page.py b/document_page_access_group_user_role/models/document_page.py new file mode 100644 index 00000000..f9bf89cf --- /dev/null +++ b/document_page_access_group_user_role/models/document_page.py @@ -0,0 +1,23 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class DocumentPage(models.Model): + _inherit = "document.page" + + groups_id = fields.Many2many(compute="_compute_groups_id", store=True) + role_ids = fields.Many2many( + comodel_name="res.users.role", + relation="document_page_user_roles_rel", + column1="page_id", + column2="role_id", + 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.""" + for item in self: + item.groups_id = item.mapped("role_ids.implied_ids") diff --git a/document_page_access_group_user_role/readme/CONTRIBUTORS.rst b/document_page_access_group_user_role/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..5fb71305 --- /dev/null +++ b/document_page_access_group_user_role/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza diff --git a/document_page_access_group_user_role/readme/DESCRIPTION.rst b/document_page_access_group_user_role/readme/DESCRIPTION.rst new file mode 100644 index 00000000..cceffd15 --- /dev/null +++ b/document_page_access_group_user_role/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Use of roles (module base_user_role) in Document Pages. diff --git a/document_page_access_group_user_role/readme/USAGE.rst b/document_page_access_group_user_role/readme/USAGE.rst new file mode 100644 index 00000000..568c9352 --- /dev/null +++ b/document_page_access_group_user_role/readme/USAGE.rst @@ -0,0 +1,5 @@ +#. Go to `Settings / Users & Companies / Roles` and create a new one. +#. 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. diff --git a/document_page_access_group_user_role/static/description/icon.png b/document_page_access_group_user_role/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/document_page_access_group_user_role/static/description/icon.png differ diff --git a/document_page_access_group_user_role/static/description/index.html b/document_page_access_group_user_role/static/description/index.html new file mode 100644 index 00000000..60c98a6a --- /dev/null +++ b/document_page_access_group_user_role/static/description/index.html @@ -0,0 +1,438 @@ + + + + + + +Document Page Access Group User Role + + + +
+

Document Page Access Group User Role

+ + +

Beta License: AGPL-3 OCA/knowledge Translate me on Weblate Try me on Runboat

+

Use of roles (module base_user_role) in Document Pages.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Settings / Users & Companies / Roles and create a new one.
  2. +
  3. Go to Knowledge / Pages and create or edit one.
  4. +
  5. Set in the “Roles” tab the one we have just created.
  6. +
  7. Go back to the role, edit it and add any group(s).
  8. +
  9. The role groups will have been added in the “Security” tab.
  10. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Víctor Martínez
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

victoralmau

+

This module is part of the OCA/knowledge project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/document_page_access_group_user_role/tests/__init__.py b/document_page_access_group_user_role/tests/__init__.py new file mode 100644 index 00000000..60b36044 --- /dev/null +++ b/document_page_access_group_user_role/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from . import test_document_page_access_group_user_role 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 new file mode 100644 index 00000000..f830ee1d --- /dev/null +++ b/document_page_access_group_user_role/tests/test_document_page_access_group_user_role.py @@ -0,0 +1,30 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.base.tests.common import BaseCommon + + +class TestDocumentPageAccessGroupUserRole(BaseCommon): + @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])]} + ) + + 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) 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 new file mode 100644 index 00000000..2a0fe5ae --- /dev/null +++ b/document_page_access_group_user_role/views/document_page_views.xml @@ -0,0 +1,31 @@ + + + + document.page.form + document.page + + + + + + + + + + + + + + + + + {'readonly': [('role_ids', '!=', [])]} + + + +