diff --git a/base_menu_visibility_restriction/README.rst b/base_menu_visibility_restriction/README.rst new file mode 100644 index 0000000000..572364b9eb --- /dev/null +++ b/base_menu_visibility_restriction/README.rst @@ -0,0 +1,104 @@ +================================ +Base Menu Visibility Restriction +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:eb9f5f2eca3b8520ba152aac34d978b776132af5ecd2770ddb3eb6e99190070c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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%2Fserver--ux-lightgray.png?logo=github + :target: https://github.com/OCA/server-ux/tree/17.0/base_menu_visibility_restriction + :alt: OCA/server-ux +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-ux-17-0/server-ux-17-0-base_menu_visibility_restriction + :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/server-ux&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon lets you assign "excluded groups" to menu items. If a user +belongs to a group that is assigned to a menu item as an excluded group, +the user will not be able to see the menu item. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. Activate the developer mode +2. Go to *Settings > Technical > User interface > Menu Items*. +3. Search for any menu and edit it. +4. Update "Excluded groups" with one group. +5. Login with a user of that group, and you won't see such menu. + +You can try with demo data for the menu Apps > App Store and user demo. + +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 + +- Dhara Solanki +- Nedas Žilinskas + +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/server-ux `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_menu_visibility_restriction/__init__.py b/base_menu_visibility_restriction/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/base_menu_visibility_restriction/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_menu_visibility_restriction/__manifest__.py b/base_menu_visibility_restriction/__manifest__.py new file mode 100644 index 0000000000..a209a3093b --- /dev/null +++ b/base_menu_visibility_restriction/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Base Menu Visibility Restriction", + "version": "18.0.1.0.0", + "category": "Extra Tools", + "development_status": "Production/Stable", + "author": "Tecnativa, Odoo Community Association (OCA)", + "summary": "Restrict (with groups) menu visibilty", + "website": "https://github.com/OCA/server-ux", + "license": "AGPL-3", + "depends": ["web_tour"], + "maintainers": ["victoralmau"], + "data": ["views/ir_ui_menu.xml"], + "installable": True, +} diff --git a/base_menu_visibility_restriction/i18n/base_menu_visibility_restriction.pot b/base_menu_visibility_restriction/i18n/base_menu_visibility_restriction.pot new file mode 100644 index 0000000000..2f0de65fe6 --- /dev/null +++ b/base_menu_visibility_restriction/i18n/base_menu_visibility_restriction.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_menu_visibility_restriction +# +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: base_menu_visibility_restriction +#: model:ir.model.fields,field_description:base_menu_visibility_restriction.field_ir_ui_menu__excluded_group_ids +msgid "Excluded Groups" +msgstr "" + +#. module: base_menu_visibility_restriction +#: model:ir.model,name:base_menu_visibility_restriction.model_ir_ui_menu +msgid "Menu" +msgstr "" diff --git a/base_menu_visibility_restriction/i18n/es.po b/base_menu_visibility_restriction/i18n/es.po new file mode 100644 index 0000000000..e92e251c17 --- /dev/null +++ b/base_menu_visibility_restriction/i18n/es.po @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_menu_visibility_restriction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-09-03 13:43+0000\n" +"Last-Translator: kikopeiro \n" +"Language-Team: none\n" +"Language: es\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 4.17\n" + +#. module: base_menu_visibility_restriction +#: model:ir.model.fields,field_description:base_menu_visibility_restriction.field_ir_ui_menu__excluded_group_ids +msgid "Excluded Groups" +msgstr "Grupos excluidos" + +#. module: base_menu_visibility_restriction +#: model:ir.model,name:base_menu_visibility_restriction.model_ir_ui_menu +msgid "Menu" +msgstr "Menú" + +#~ msgid "Menu visibility restriction demo group" +#~ msgstr "Grupo demo de restricción de visibilidad de menús" diff --git a/base_menu_visibility_restriction/i18n/it.po b/base_menu_visibility_restriction/i18n/it.po new file mode 100644 index 0000000000..e0260a5acf --- /dev/null +++ b/base_menu_visibility_restriction/i18n/it.po @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_menu_visibility_restriction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-31 17:24+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 4.17\n" + +#. module: base_menu_visibility_restriction +#: model:ir.model.fields,field_description:base_menu_visibility_restriction.field_ir_ui_menu__excluded_group_ids +msgid "Excluded Groups" +msgstr "Gruppi esclusi" + +#. module: base_menu_visibility_restriction +#: model:ir.model,name:base_menu_visibility_restriction.model_ir_ui_menu +msgid "Menu" +msgstr "Menu" + +#~ msgid "Menu visibility restriction demo group" +#~ msgstr "Gruppo demo restrizione visibilità menu" diff --git a/base_menu_visibility_restriction/models/__init__.py b/base_menu_visibility_restriction/models/__init__.py new file mode 100644 index 0000000000..7930c4e29d --- /dev/null +++ b/base_menu_visibility_restriction/models/__init__.py @@ -0,0 +1 @@ +from . import ir_ui_menu diff --git a/base_menu_visibility_restriction/models/ir_ui_menu.py b/base_menu_visibility_restriction/models/ir_ui_menu.py new file mode 100644 index 0000000000..45af40fa39 --- /dev/null +++ b/base_menu_visibility_restriction/models/ir_ui_menu.py @@ -0,0 +1,26 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models, tools + + +class IrUiMenu(models.Model): + _inherit = "ir.ui.menu" + + excluded_group_ids = fields.Many2many( + comodel_name="res.groups", + relation="ir_ui_menu_excluded_group_rel", + column1="menu_id", + column2="gid", + string="Excluded Groups", + ) + + @api.model + @tools.ormcache("frozenset(self.env.user.groups_id.ids)", "debug") + def _visible_menu_ids(self, debug=False): + """Return the ids of the menu items visible to the user.""" + visible = super()._visible_menu_ids(debug=debug) + context = {"ir.ui.menu.full_list": True} + menus = self.with_context(**context).browse(visible) + groups = self.env.user.groups_id + visible = menus - menus.filtered(lambda menu: menu.excluded_group_ids & groups) + return set(visible.ids) diff --git a/base_menu_visibility_restriction/pyproject.toml b/base_menu_visibility_restriction/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/base_menu_visibility_restriction/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/base_menu_visibility_restriction/readme/CONTRIBUTORS.md b/base_menu_visibility_restriction/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..329fec65f1 --- /dev/null +++ b/base_menu_visibility_restriction/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [Tecnativa](https://www.tecnativa.com): + - Víctor Martínez +- Dhara Solanki \<\> +- Nedas Žilinskas \<\> diff --git a/base_menu_visibility_restriction/readme/DESCRIPTION.md b/base_menu_visibility_restriction/readme/DESCRIPTION.md new file mode 100644 index 0000000000..8916de1232 --- /dev/null +++ b/base_menu_visibility_restriction/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This addon lets you assign "excluded groups" to menu items. If a user +belongs to a group that is assigned to a menu item as an excluded group, +the user will not be able to see the menu item. diff --git a/base_menu_visibility_restriction/readme/USAGE.md b/base_menu_visibility_restriction/readme/USAGE.md new file mode 100644 index 0000000000..fe612297ea --- /dev/null +++ b/base_menu_visibility_restriction/readme/USAGE.md @@ -0,0 +1,9 @@ +To use this module, you need to: + +1. Activate the developer mode +2. Go to *Settings \> Technical \> User interface \> Menu Items*. +3. Search for any menu and edit it. +4. Update "Excluded groups" with one group. +5. Login with a user of that group, and you won't see such menu. + +You can try with demo data for the menu Apps \> App Store and user demo. diff --git a/base_menu_visibility_restriction/static/description/icon.png b/base_menu_visibility_restriction/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/base_menu_visibility_restriction/static/description/icon.png differ diff --git a/base_menu_visibility_restriction/static/description/index.html b/base_menu_visibility_restriction/static/description/index.html new file mode 100644 index 0000000000..e14362d725 --- /dev/null +++ b/base_menu_visibility_restriction/static/description/index.html @@ -0,0 +1,445 @@ + + + + + +Base Menu Visibility Restriction + + + +
+

Base Menu Visibility Restriction

+ + +

Production/Stable License: AGPL-3 OCA/server-ux Translate me on Weblate Try me on Runboat

+

This addon lets you assign “excluded groups” to menu items. If a user +belongs to a group that is assigned to a menu item as an excluded group, +the user will not be able to see the menu item.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Activate the developer mode
  2. +
  3. Go to Settings > Technical > User interface > Menu Items.
  4. +
  5. Search for any menu and edit it.
  6. +
  7. Update “Excluded groups” with one group.
  8. +
  9. Login with a user of that group, and you won’t see such menu.
  10. +
+

You can try with demo data for the menu Apps > App Store and user demo.

+
+
+

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

+ +
+
+

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/server-ux project on GitHub.

+

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

+
+
+
+ + diff --git a/base_menu_visibility_restriction/tests/__init__.py b/base_menu_visibility_restriction/tests/__init__.py new file mode 100644 index 0000000000..9d980865ad --- /dev/null +++ b/base_menu_visibility_restriction/tests/__init__.py @@ -0,0 +1 @@ +from . import test_ir_ui_menu diff --git a/base_menu_visibility_restriction/tests/test_ir_ui_menu.py b/base_menu_visibility_restriction/tests/test_ir_ui_menu.py new file mode 100644 index 0000000000..5619ee51d9 --- /dev/null +++ b/base_menu_visibility_restriction/tests/test_ir_ui_menu.py @@ -0,0 +1,23 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestIrUiMenuCase(TransactionCase): + def setUp(self): + super().setUp() + self.user_admin = self.browse_ref("base.user_admin").id + self.group_hide_menu = self.env["res.groups"].create( + {"name": "Hide menu items custom", "users": [(4, self.user_admin)]} + ) + self.model_ir_uir_menu = self.env["ir.ui.menu"] + self.ir_ui_menu = self.browse_ref("base.menu_management") + + def test_ir_ui_menu_admin(self): + items = self.model_ir_uir_menu.with_user(self.user_admin)._visible_menu_ids() + self.assertTrue(self.ir_ui_menu.id in items) + # Update ir_ui_menu to assign excluded_group_ids + self.ir_ui_menu.write({"excluded_group_ids": [(4, self.group_hide_menu.id)]}) + items = self.model_ir_uir_menu.with_user(self.user_admin)._visible_menu_ids() + self.assertTrue(self.ir_ui_menu.id not in items) diff --git a/base_menu_visibility_restriction/views/ir_ui_menu.xml b/base_menu_visibility_restriction/views/ir_ui_menu.xml new file mode 100644 index 0000000000..4916e3e8a6 --- /dev/null +++ b/base_menu_visibility_restriction/views/ir_ui_menu.xml @@ -0,0 +1,20 @@ + + + + + ir.ui.menu.restricted + ir.ui.menu + + + + + + + +