diff --git a/base_portal_type/README.rst b/base_portal_type/README.rst new file mode 100644 index 00000000..9345902d --- /dev/null +++ b/base_portal_type/README.rst @@ -0,0 +1,100 @@ +============ +Portal types +============ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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--backend-lightgray.png?logo=github + :target: https://github.com/OCA/server-backend/tree/16.0/base_portal_type + :alt: OCA/server-backend +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_portal_type + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/server-backend&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows administrator to configure groups for portal users. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. create a group of category ``base_portal_type.category_portal_type`` +#. observe the group shows up on a user form for users of type `Portal` +#. now you can use this group in your frontend templates and code to make some features accessible to this group + +Known issues / Roadmap +====================== + +* allowing to chose portal groups in the portal wizard would be nice + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Hunki Enterprises BV + +Contributors +~~~~~~~~~~~~ + +* Holger Brunn (https://hunki-enterprises.com) + +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-hbrunn| image:: https://github.com/hbrunn.png?size=40px + :target: https://github.com/hbrunn + :alt: hbrunn + +Current `maintainer `__: + +|maintainer-hbrunn| + +This module is part of the `OCA/server-backend `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_portal_type/__init__.py b/base_portal_type/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/base_portal_type/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_portal_type/__manifest__.py b/base_portal_type/__manifest__.py new file mode 100644 index 00000000..7f56624d --- /dev/null +++ b/base_portal_type/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2023 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +{ + "name": "Portal types", + "summary": "Base module to allow different types of portals", + "version": "16.0.1.0.0", + "development_status": "Alpha", + "category": "Technical", + "website": "https://github.com/OCA/server-backend", + "author": "Hunki Enterprises BV, Odoo Community Association (OCA)", + "maintainers": ["hbrunn"], + "license": "AGPL-3", + "depends": [ + "portal", + ], + "data": [ + "data/ir_module_category.xml", + ], + "demo": [ + "demo/res_groups.xml", + ], +} diff --git a/base_portal_type/data/ir_module_category.xml b/base_portal_type/data/ir_module_category.xml new file mode 100644 index 00000000..19185e84 --- /dev/null +++ b/base_portal_type/data/ir_module_category.xml @@ -0,0 +1,10 @@ + + + + + + Portal type + + + diff --git a/base_portal_type/demo/res_groups.xml b/base_portal_type/demo/res_groups.xml new file mode 100644 index 00000000..cd96b528 --- /dev/null +++ b/base_portal_type/demo/res_groups.xml @@ -0,0 +1,11 @@ + + + + + + A portal type + + + + diff --git a/base_portal_type/models/__init__.py b/base_portal_type/models/__init__.py new file mode 100644 index 00000000..9a3f975b --- /dev/null +++ b/base_portal_type/models/__init__.py @@ -0,0 +1 @@ +from . import res_groups diff --git a/base_portal_type/models/res_groups.py b/base_portal_type/models/res_groups.py new file mode 100644 index 00000000..995d4513 --- /dev/null +++ b/base_portal_type/models/res_groups.py @@ -0,0 +1,92 @@ +# Copyright 2023 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + + +from lxml import etree + +from odoo import api, models + +from odoo.addons.base.models.res_users import name_boolean_group, name_selection_groups + + +class ResGroups(models.Model): + _inherit = "res.groups" + + @api.model + def _update_user_groups_view(self): + result = super()._update_user_groups_view() + view = self.env.ref("base.user_groups_view") + arch = etree.fromstring(view.arch) + user_type_groups = [ + groups + for app, kind, groups, category in self.get_groups_by_application() + if app.xml_id == "base.module_category_user_type" + ][0] + portal_group = self.env.ref("base.group_portal") + internal_group = self.env.ref("base.group_user") + portal_groups = ( + self.env["res.groups"] + .with_context(lang=None) + .search( + [ + ( + "category_id", + "=", + self.env.ref("base_portal_type.category_portal_type").id, + ), + ] + ) + ) + user_type_field = name_selection_groups(user_type_groups.ids) + for node in arch.xpath("//group/field[@name='%s']" % user_type_field): + for group in portal_groups: + field_name = name_boolean_group(group.id) + for field_node in arch.xpath("//field[@name='%s']" % field_name): + field_node.attrib["attrs"] = str( + { + "readonly": [ + ( + user_type_field, + "not in", + (portal_group + internal_group).ids, + ) + ], + } + ) + node.addnext( + etree.Element( + "field", + { + "name": field_name, + "on_change": "1", + "attrs": str( + { + "invisible": [ + (user_type_field, "!=", portal_group.id), + ], + } + ), + }, + ) + ) + view_context = dict(self.env.context, lang=None) + view_context.pop("install_filename", None) + # pylint: disable=context-overridden + view.with_context(view_context).write( + {"arch": etree.tostring(arch, pretty_print=True, encoding="unicode")} + ) + return result + + @api.model + def get_groups_by_application(self): + return [ + ( + app, + kind + if app.xml_id != "base_portal_type.category_portal_type" + else "boolean", + groups, + category, + ) + for app, kind, groups, category in super().get_groups_by_application() + ] diff --git a/base_portal_type/readme/CONTRIBUTORS.rst b/base_portal_type/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..33b6eb2c --- /dev/null +++ b/base_portal_type/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Holger Brunn (https://hunki-enterprises.com) diff --git a/base_portal_type/readme/DESCRIPTION.rst b/base_portal_type/readme/DESCRIPTION.rst new file mode 100644 index 00000000..a3bb3f73 --- /dev/null +++ b/base_portal_type/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module allows administrator to configure groups for portal users, which is not possible with standard Odoo. + +That's useful for having different types of portal users (think differentiate vendors from customers) and leveraging Odoo's group mechanism for ie views instead having to cook up custom solutions. diff --git a/base_portal_type/readme/ROADMAP.rst b/base_portal_type/readme/ROADMAP.rst new file mode 100644 index 00000000..1245d181 --- /dev/null +++ b/base_portal_type/readme/ROADMAP.rst @@ -0,0 +1 @@ +* allowing to chose portal groups in the portal wizard would be nice diff --git a/base_portal_type/readme/USAGE.rst b/base_portal_type/readme/USAGE.rst new file mode 100644 index 00000000..403c2c12 --- /dev/null +++ b/base_portal_type/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module, you need to: + +#. create a group of category ``base_portal_type.category_portal_type`` +#. observe the group shows up on a user form for users of type `Portal` +#. now you can use this group in your frontend templates and code to make some features accessible to this group diff --git a/base_portal_type/static/description/icon.png b/base_portal_type/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/base_portal_type/static/description/icon.png differ diff --git a/base_portal_type/static/description/index.html b/base_portal_type/static/description/index.html new file mode 100644 index 00000000..2c1e5188 --- /dev/null +++ b/base_portal_type/static/description/index.html @@ -0,0 +1,444 @@ + + + + + + +Portal types + + + +
+

Portal types

+ + +

Alpha License: AGPL-3 OCA/server-backend Translate me on Weblate Try me on Runboat

+

This module allows administrator to configure groups for portal users.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. create a group of category base_portal_type.category_portal_type
  2. +
  3. observe the group shows up on a user form for users of type Portal
  4. +
  5. now you can use this group in your frontend templates and code to make some features accessible to this group
  6. +
+
+
+

Known issues / Roadmap

+
    +
  • allowing to chose portal groups in the portal wizard would be nice
  • +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Hunki Enterprises BV
  • +
+
+ +
+

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:

+

hbrunn

+

This module is part of the OCA/server-backend project on GitHub.

+

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

+
+
+
+ + diff --git a/base_portal_type/tests/__init__.py b/base_portal_type/tests/__init__.py new file mode 100644 index 00000000..e34149cc --- /dev/null +++ b/base_portal_type/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_portal_type diff --git a/base_portal_type/tests/test_base_portal_type.py b/base_portal_type/tests/test_base_portal_type.py new file mode 100644 index 00000000..42a60668 --- /dev/null +++ b/base_portal_type/tests/test_base_portal_type.py @@ -0,0 +1,20 @@ +# Copyright 2023 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + + +from lxml import etree + +from odoo.tests.common import TransactionCase + +from odoo.addons.base.models.res_users import name_boolean_group + + +class TestBasePortalGroup(TransactionCase): + def test_portal_group_view(self): + """Test that our group is added to the users form twice""" + group = self.env.ref("base_portal_type.group_portal_type").copy() + group_field_name = name_boolean_group(group.id) + groups_view = etree.fromstring(self.env.ref("base.user_groups_view").arch) + self.assertEqual( + len(groups_view.xpath("//field[@name='%s']" % group_field_name)), 3 + ) diff --git a/setup/base_portal_type/odoo/addons/base_portal_type b/setup/base_portal_type/odoo/addons/base_portal_type new file mode 120000 index 00000000..547d2a97 --- /dev/null +++ b/setup/base_portal_type/odoo/addons/base_portal_type @@ -0,0 +1 @@ +../../../../base_portal_type \ No newline at end of file diff --git a/setup/base_portal_type/setup.py b/setup/base_portal_type/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/base_portal_type/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)