diff --git a/document_page_access_group/README.rst b/document_page_access_group/README.rst new file mode 100644 index 00000000..5044ea3e --- /dev/null +++ b/document_page_access_group/README.rst @@ -0,0 +1,97 @@ +========================== +Document Page Access Group +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:28e06c90139270717bf9f3fbe04145a72fed721a256eb4d526ee229beaf1cc69 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.0/document_page_access_group + :alt: OCA/knowledge +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/knowledge-18-0/knowledge-18-0-document_page_access_group + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to select which users groups have access to the +document pages. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To select the users that have access to a given document page you need +to open a document, go to the 'Security' tab and you have 3 options: + +- Select a group: Only users with those groups will be able to see the + page. +- Select any user: Only the selected users will be able to see the page. +- Do not select group or user: All users will be able to see the page. + +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 +------- + +* Sygel + +Contributors +------------ + +- Manuel Regidor +- Alberto Martínez + +- ``Tecnativa ``\ \_: + + - Víctor Martínez + +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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. + +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/__init__.py b/document_page_access_group/__init__.py new file mode 100644 index 00000000..18143cb9 --- /dev/null +++ b/document_page_access_group/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/document_page_access_group/__manifest__.py b/document_page_access_group/__manifest__.py new file mode 100644 index 00000000..b0aed75f --- /dev/null +++ b/document_page_access_group/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2022 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Document Page Access Group", + "summary": "Choose groups to access document pages", + "version": "18.0.1.0.0", + "category": "document_knowledge", + "website": "https://github.com/OCA/knowledge", + "author": "Sygel, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "document_page", + "document_knowledge", + ], + "data": ["views/document_page.xml", "security/security.xml"], +} diff --git a/document_page_access_group/i18n/ca.po b/document_page_access_group/i18n/ca.po new file mode 100644 index 00000000..a975bc4e --- /dev/null +++ b/document_page_access_group/i18n/ca.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * document_page_access_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-09-04 18:06+0000\n" +"Last-Translator: Esteve Blanch Sanmartí <3501974+esteveblanch@users.noreply." +"github.com>\n" +"Language-Team: none\n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: document_page_access_group +#: model:ir.model,name:document_page_access_group.model_document_page +msgid "Document Page" +msgstr "Pàgina del document" + +#. module: document_page_access_group +#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Groups" +msgstr "Grups" + +#. module: document_page_access_group +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Security" +msgstr "Seguretat" + +#. module: document_page_access_group +#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__user_ids +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Users" +msgstr "Usuaris" + +#. module: document_page_access_group +#. odoo-python +#: code:addons/document_page_access_group/models/document_page.py:0 +#, python-format +msgid "You cannot set groups and users at the same time." +msgstr "No podeu establir grups i usuaris al mateix temps." diff --git a/document_page_access_group/i18n/document_page_access_group.pot b/document_page_access_group/i18n/document_page_access_group.pot new file mode 100644 index 00000000..7bb4b3ab --- /dev/null +++ b/document_page_access_group/i18n/document_page_access_group.pot @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * document_page_access_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \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 +#: model:ir.model,name:document_page_access_group.model_document_page +msgid "Document Page" +msgstr "" + +#. module: document_page_access_group +#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Groups" +msgstr "" + +#. module: document_page_access_group +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Security" +msgstr "" + +#. module: document_page_access_group +#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__user_ids +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Users" +msgstr "" + +#. module: document_page_access_group +#. odoo-python +#: code:addons/document_page_access_group/models/document_page.py:0 +#, python-format +msgid "You cannot set groups and users at the same time." +msgstr "" diff --git a/document_page_access_group/i18n/es.po b/document_page_access_group/i18n/es.po new file mode 100644 index 00000000..0ba00b9c --- /dev/null +++ b/document_page_access_group/i18n/es.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * document_page_access_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-24 07:09+0000\n" +"PO-Revision-Date: 2024-07-24 09:10+0200\n" +"Last-Translator: luis-ron \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Poedit 3.0.1\n" + +#. module: document_page_access_group +#: model:ir.model,name:document_page_access_group.model_document_page +msgid "Document Page" +msgstr "Página de documento" + +#. module: document_page_access_group +#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Groups" +msgstr "Grupos" + +#. module: document_page_access_group +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Security" +msgstr "Seguridad" + +#. module: document_page_access_group +#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__user_ids +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Users" +msgstr "Usuarios" + +#. module: document_page_access_group +#. odoo-python +#: code:addons/document_page_access_group/models/document_page.py:0 +#, python-format +msgid "You cannot set groups and users at the same time." +msgstr "No puedes definir grupos y usuarios al mismo tiempo." diff --git a/document_page_access_group/i18n/it.po b/document_page_access_group/i18n/it.po new file mode 100644 index 00000000..941a87c4 --- /dev/null +++ b/document_page_access_group/i18n/it.po @@ -0,0 +1,55 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * document_page_access_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-08-07 08:58+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: document_page_access_group +#: model:ir.model,name:document_page_access_group.model_document_page +msgid "Document Page" +msgstr "Pagina documento" + +#. module: document_page_access_group +#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Groups" +msgstr "Gruppi" + +#. module: document_page_access_group +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Security" +msgstr "Sicurezza" + +#. module: document_page_access_group +#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__user_ids +#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form +msgid "Users" +msgstr "Utenti" + +#. module: document_page_access_group +#. odoo-python +#: code:addons/document_page_access_group/models/document_page.py:0 +#, python-format +msgid "You cannot set groups and users at the same time." +msgstr "Non si possono impostare gruppi e utenti allo stesso tempo." + +#~ msgid "Display Name" +#~ msgstr "Nome visualizzato" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Ultima modifica il" diff --git a/document_page_access_group/models/__init__.py b/document_page_access_group/models/__init__.py new file mode 100644 index 00000000..5aedcf2a --- /dev/null +++ b/document_page_access_group/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import document_page diff --git a/document_page_access_group/models/document_page.py b/document_page_access_group/models/document_page.py new file mode 100644 index 00000000..58895c7f --- /dev/null +++ b/document_page_access_group/models/document_page.py @@ -0,0 +1,21 @@ +# Copyright 2022 Manuel Regidor +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class DocumentPage(models.Model): + _inherit = "document.page" + + groups_id = fields.Many2many(comodel_name="res.groups", string="Groups") + user_ids = fields.Many2many(comodel_name="res.users", string="Users") + + @api.constrains("groups_id", "user_ids") + def check_document_page_groups_users(self): + for _item in self.filtered(lambda x: x.groups_id and x.user_ids): + raise UserError( + self.env._("You cannot set groups and users at the same time.") + ) + return True diff --git a/document_page_access_group/pyproject.toml b/document_page_access_group/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/document_page_access_group/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/document_page_access_group/readme/CONTRIBUTORS.md b/document_page_access_group/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..4ddc3399 --- /dev/null +++ b/document_page_access_group/readme/CONTRIBUTORS.md @@ -0,0 +1,7 @@ +- Manuel Regidor \<\> +- Alberto Martínez \<\> +* `Tecnativa `_: + + * Víctor Martínez +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/document_page_access_group/readme/DESCRIPTION.md b/document_page_access_group/readme/DESCRIPTION.md new file mode 100644 index 00000000..ecf456b6 --- /dev/null +++ b/document_page_access_group/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows to select which users groups have access to the +document pages. diff --git a/document_page_access_group/readme/USAGE.md b/document_page_access_group/readme/USAGE.md new file mode 100644 index 00000000..bbe9bdb9 --- /dev/null +++ b/document_page_access_group/readme/USAGE.md @@ -0,0 +1,5 @@ +To select the users that have access to a given document page +you need to open a document, go to the 'Security' tab and you have 3 options: +- Select a group: Only users with those groups will be able to see the page. +- Select any user: Only the selected users will be able to see the page. +- Do not select group or user: All users will be able to see the page. diff --git a/document_page_access_group/security/security.xml b/document_page_access_group/security/security.xml new file mode 100644 index 00000000..cf3aaea7 --- /dev/null +++ b/document_page_access_group/security/security.xml @@ -0,0 +1,27 @@ + + + + + Document Page Access + + + + ['|', ('groups_id', 'in', [g.id for g in user.groups_id]), '|', ('user_ids', 'in', [user.id]), '&', ('groups_id', '=', False), ('user_ids', '=', False)] + + + Document Page Full Access + + + + [(1, '=', 1)] + + diff --git a/document_page_access_group/static/description/icon.png b/document_page_access_group/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/document_page_access_group/static/description/icon.png differ diff --git a/document_page_access_group/static/description/index.html b/document_page_access_group/static/description/index.html new file mode 100644 index 00000000..aaceaee1 --- /dev/null +++ b/document_page_access_group/static/description/index.html @@ -0,0 +1,445 @@ + + + + + +Document Page Access Group + + + +
+

Document Page Access Group

+ + +

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

+

This module allows to select which users groups have access to the +document pages.

+

Table of contents

+ +
+

Usage

+

To select the users that have access to a given document page you need +to open a document, go to the ‘Security’ tab and you have 3 options:

+
    +
  • Select a group: Only users with those groups will be able to see the +page.
  • +
  • Select any user: Only the selected users will be able to see the page.
  • +
  • Do not select group or user: All users will be able to see the page.
  • +
+
+
+

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

+
    +
  • Sygel
  • +
+
+
+

Contributors

+ +
+
+

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.

+

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/tests/__init__.py b/document_page_access_group/tests/__init__.py new file mode 100644 index 00000000..d2acbb67 --- /dev/null +++ b/document_page_access_group/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_document_page_access_group diff --git a/document_page_access_group/tests/common.py b/document_page_access_group/tests/common.py new file mode 100644 index 00000000..4feba377 --- /dev/null +++ b/document_page_access_group/tests/common.py @@ -0,0 +1,38 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import Command +from odoo.tests import new_test_user + +from odoo.addons.base.tests.common import BaseCommon + + +class TestDocumentPageAccessGroupBase(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.group = cls.env["res.groups"].create({"name": "Test group"}) + cls.user = new_test_user( + cls.env, login="test-user", groups="document_knowledge.group_document_user" + ) + cls.manager_user = new_test_user( + cls.env, + login="test-manager-user", + groups="document_knowledge.group_document_user", + ) + cls.manager_user.write({"groups_id": [Command.link(cls.group.id)]}) + cls.public_page = cls.env["document.page"].create( + {"name": "Public Page", "type": "content"} + ) + cls.knowledge_page = cls.env["document.page"].create( + { + "name": "Knowledge Page", + "type": "content", + "groups_id": [Command.set([cls.group.id])], + } + ) + cls.user_page = cls.env["document.page"].create( + { + "name": "User Page (basic user)", + "type": "content", + "user_ids": [Command.set([cls.user.id])], + } + ) diff --git a/document_page_access_group/tests/test_document_page_access_group.py b/document_page_access_group/tests/test_document_page_access_group.py new file mode 100644 index 00000000..c687244e --- /dev/null +++ b/document_page_access_group/tests/test_document_page_access_group.py @@ -0,0 +1,26 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import Command +from odoo.exceptions import UserError +from odoo.tests.common import users + +from .common import TestDocumentPageAccessGroupBase + + +class TestDocumentPageAccessGroup(TestDocumentPageAccessGroupBase): + def test_page_access_constrains(self): + with self.assertRaises(UserError): + self.knowledge_page.write({"user_ids": [Command.set([self.user.id])]}) + + @users("test-user") + def test_page_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) + + @users("test-manager-user") + def test_page_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) diff --git a/document_page_access_group/views/document_page.xml b/document_page_access_group/views/document_page.xml new file mode 100644 index 00000000..46c6e857 --- /dev/null +++ b/document_page_access_group/views/document_page.xml @@ -0,0 +1,27 @@ + + + + + document.page.access.group.view.wiki.form + document.page + + + + + + + + + + + + + + +