diff --git a/README.md b/README.md index e01fed8a35..d038b6a647 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Available addons ---------------- addon | version | maintainers | summary --- | --- | --- | --- +[website_conditional_visibility_user_group](website_conditional_visibility_user_group/) | 19.0.1.0.0 | | Only internal users will see the blocks you add this condition to [website_cookiefirst](website_cookiefirst/) | 19.0.1.0.0 | | Cookiefirst integration [website_form_require_legal](website_form_require_legal/) | 19.0.1.0.1 | | Add possibility to require confirm legal terms. [website_forum_subscription](website_forum_subscription/) | 19.0.1.0.0 | | Adds a button to allow subscription from the website diff --git a/setup/_metapackage/pyproject.toml b/setup/_metapackage/pyproject.toml index 02081d7fd4..0f184e6dd8 100644 --- a/setup/_metapackage/pyproject.toml +++ b/setup/_metapackage/pyproject.toml @@ -1,7 +1,8 @@ [project] name = "odoo-addons-oca-website" -version = "19.0.20260811.0" +version = "19.0.20260819.0" dependencies = [ + "odoo-addon-website_conditional_visibility_user_group==19.0.*", "odoo-addon-website_cookiefirst==19.0.*", "odoo-addon-website_form_require_legal==19.0.*", "odoo-addon-website_forum_subscription==19.0.*", diff --git a/website_conditional_visibility_user_group/README.rst b/website_conditional_visibility_user_group/README.rst new file mode 100644 index 0000000000..d9c369a2b6 --- /dev/null +++ b/website_conditional_visibility_user_group/README.rst @@ -0,0 +1,101 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +==================================================== +Conditional visibility for internal users in Website +==================================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2ec599ab98418df44eda5654653c5adaf26dc7c9dff29cdceefe969d7aed1ae4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fwebsite-lightgray.png?logo=github + :target: https://github.com/OCA/website/tree/19.0/website_conditional_visibility_user_group + :alt: OCA/website +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/website-19-0/website-19-0-website_conditional_visibility_user_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/website&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds extra granularity in the visibility of the website +snippets allowing to set if the users that can see a block are internal +or portal ones. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure the user group visibility: + +- With the frontend editor opened select the block you want to set the + visibility for. +- In *Style* tab of the editor panel set the *Visibility* option to + *Conditional* and unfold it. +- Set the *Users* option to *Visible for logged in*. +- Now you'll see the new *Groups* option. +- You can choose between *Only internal users*, *Only portal users* or + *No restriction*, which is the default value. + +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 `__ + + - David Vidal + - Pilar Vargas + - Carlos Roca + - Adasat Torres + +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/website `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_conditional_visibility_user_group/__init__.py b/website_conditional_visibility_user_group/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/website_conditional_visibility_user_group/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/website_conditional_visibility_user_group/__manifest__.py b/website_conditional_visibility_user_group/__manifest__.py new file mode 100644 index 0000000000..6e215be646 --- /dev/null +++ b/website_conditional_visibility_user_group/__manifest__.py @@ -0,0 +1,30 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Conditional visibility for internal users in Website", + "summary": "Only internal users will see the blocks you add this condition to", + "version": "19.0.1.0.0", + "category": "Product", + "website": "https://github.com/OCA/website", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["website"], + "assets": { + "web.assets_frontend_minimal": [ + "website_conditional_visibility_user_group/static/src/js/inject_dom.esm.js", + ], + "web.assets_frontend_lazy": [ + # Remove assets_frontend_minimal + ( + "remove", + "website_conditional_visibility_user_group/static/src/js/inject_dom.esm.js", + ), + ], + "web.assets_tests": [ + "website_conditional_visibility_user_group/static/src/tests/*.js" + ], + "website.website_builder_assets": [ + "website_conditional_visibility_user_group/static/src/website_builder/**" + ], + }, +} diff --git a/website_conditional_visibility_user_group/i18n/es.po b/website_conditional_visibility_user_group/i18n/es.po new file mode 100644 index 0000000000..b0c0c3eeeb --- /dev/null +++ b/website_conditional_visibility_user_group/i18n/es.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_conditional_visibility_user_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-12 05:20+0000\n" +"PO-Revision-Date: 2024-07-12 07:21+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: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.4.4\n" + +#. module: website_conditional_visibility_user_group +#: model:ir.model,name:website_conditional_visibility_user_group.model_ir_http +msgid "HTTP Routing" +msgstr "Ruta HTTP" + +#. module: website_conditional_visibility_user_group +#: model_terms:ir.ui.view,arch_db:website_conditional_visibility_user_group.snippet_options +msgid "No restriction" +msgstr "Sin restricciones" + +#. module: website_conditional_visibility_user_group +#: model_terms:ir.ui.view,arch_db:website_conditional_visibility_user_group.snippet_options +msgid "Only internal users" +msgstr "Solo usuarios internos" + +#. module: website_conditional_visibility_user_group +#: model_terms:ir.ui.view,arch_db:website_conditional_visibility_user_group.snippet_options +msgid "Only portal users" +msgstr "Solo usuarios de portal" + +#. module: website_conditional_visibility_user_group +#: model_terms:ir.ui.view,arch_db:website_conditional_visibility_user_group.snippet_options +msgid "⌙ Groups" +msgstr "⌙ Grupos" diff --git a/website_conditional_visibility_user_group/i18n/it.po b/website_conditional_visibility_user_group/i18n/it.po new file mode 100644 index 0000000000..2f1ef21e86 --- /dev/null +++ b/website_conditional_visibility_user_group/i18n/it.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_conditional_visibility_user_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-01-15 10:06+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: website_conditional_visibility_user_group +#: model:ir.model,name:website_conditional_visibility_user_group.model_ir_http +msgid "HTTP Routing" +msgstr "Instradamento HTTP" + +#. module: website_conditional_visibility_user_group +#: model_terms:ir.ui.view,arch_db:website_conditional_visibility_user_group.snippet_options +msgid "No restriction" +msgstr "Nessuna restrizione" + +#. module: website_conditional_visibility_user_group +#: model_terms:ir.ui.view,arch_db:website_conditional_visibility_user_group.snippet_options +msgid "Only internal users" +msgstr "Solo utenti interni" + +#. module: website_conditional_visibility_user_group +#: model_terms:ir.ui.view,arch_db:website_conditional_visibility_user_group.snippet_options +msgid "Only portal users" +msgstr "Solo utenti portale" + +#. module: website_conditional_visibility_user_group +#: model_terms:ir.ui.view,arch_db:website_conditional_visibility_user_group.snippet_options +msgid "⌙ Groups" +msgstr "⌙ Gruppi" diff --git a/website_conditional_visibility_user_group/i18n/website_conditional_visibility_user_group.pot b/website_conditional_visibility_user_group/i18n/website_conditional_visibility_user_group.pot new file mode 100644 index 0000000000..d5973856f6 --- /dev/null +++ b/website_conditional_visibility_user_group/i18n/website_conditional_visibility_user_group.pot @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_conditional_visibility_user_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.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: website_conditional_visibility_user_group +#: model:ir.model.fields,field_description:website_conditional_visibility_user_group.field_ir_http__display_name +msgid "Display Name" +msgstr "" + +#. module: website_conditional_visibility_user_group +#. odoo-javascript +#: code:addons/website_conditional_visibility_user_group/static/src/website_builder/visibility_option.xml:0 +msgid "Groups" +msgstr "" + +#. module: website_conditional_visibility_user_group +#: model:ir.model,name:website_conditional_visibility_user_group.model_ir_http +msgid "HTTP Routing" +msgstr "" + +#. module: website_conditional_visibility_user_group +#: model:ir.model.fields,field_description:website_conditional_visibility_user_group.field_ir_http__id +msgid "ID" +msgstr "" + +#. module: website_conditional_visibility_user_group +#. odoo-javascript +#: code:addons/website_conditional_visibility_user_group/static/src/website_builder/visibility_option.xml:0 +msgid "No restriction" +msgstr "" + +#. module: website_conditional_visibility_user_group +#. odoo-javascript +#: code:addons/website_conditional_visibility_user_group/static/src/website_builder/visibility_option.xml:0 +msgid "Only internal users" +msgstr "" + +#. module: website_conditional_visibility_user_group +#. odoo-javascript +#: code:addons/website_conditional_visibility_user_group/static/src/website_builder/visibility_option.xml:0 +msgid "Only portal users" +msgstr "" diff --git a/website_conditional_visibility_user_group/models/__init__.py b/website_conditional_visibility_user_group/models/__init__.py new file mode 100644 index 0000000000..9a5eb71871 --- /dev/null +++ b/website_conditional_visibility_user_group/models/__init__.py @@ -0,0 +1 @@ +from . import ir_http diff --git a/website_conditional_visibility_user_group/models/ir_http.py b/website_conditional_visibility_user_group/models/ir_http.py new file mode 100644 index 0000000000..5bbd10afbc --- /dev/null +++ b/website_conditional_visibility_user_group/models/ir_http.py @@ -0,0 +1,20 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, models +from odoo.http import request + + +class IrHttp(models.AbstractModel): + _inherit = "ir.http" + + @api.model + def get_frontend_session_info(self): + # Used for the visibility of the website snippets + session_info = super().get_frontend_session_info() + if request.env.user.has_group("base.group_user"): + session_info["user_group"] = "internal" + elif request.env.user.has_group("base.group_portal"): + session_info["user_group"] = "portal" + else: + session_info["user_group"] = "public" + return session_info diff --git a/website_conditional_visibility_user_group/pyproject.toml b/website_conditional_visibility_user_group/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_conditional_visibility_user_group/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_conditional_visibility_user_group/readme/CONFIGURE.md b/website_conditional_visibility_user_group/readme/CONFIGURE.md new file mode 100644 index 0000000000..b518af04f9 --- /dev/null +++ b/website_conditional_visibility_user_group/readme/CONFIGURE.md @@ -0,0 +1,9 @@ +To configure the user group visibility: + +- With the frontend editor opened select the block you want to set the visibility for. +- In *Style* tab of the editor panel set the *Visibility* option to *Conditional* and + unfold it. +- Set the *Users* option to *Visible for logged in*. +- Now you'll see the new *Groups* option. +- You can choose between *Only internal users*, *Only portal users* or *No restriction*, + which is the default value. diff --git a/website_conditional_visibility_user_group/readme/CONTRIBUTORS.md b/website_conditional_visibility_user_group/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..607084857a --- /dev/null +++ b/website_conditional_visibility_user_group/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- [Tecnativa](https://tecnativa.com) + - David Vidal + - Pilar Vargas + - Carlos Roca + - Adasat Torres diff --git a/website_conditional_visibility_user_group/readme/DESCRIPTION.md b/website_conditional_visibility_user_group/readme/DESCRIPTION.md new file mode 100644 index 0000000000..d97bd2b265 --- /dev/null +++ b/website_conditional_visibility_user_group/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module adds extra granularity in the visibility of the website snippets allowing +to set if the users that can see a block are internal or portal ones. diff --git a/website_conditional_visibility_user_group/static/description/icon.png b/website_conditional_visibility_user_group/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_conditional_visibility_user_group/static/description/icon.png differ diff --git a/website_conditional_visibility_user_group/static/description/index.html b/website_conditional_visibility_user_group/static/description/index.html new file mode 100644 index 0000000000..7f3695f746 --- /dev/null +++ b/website_conditional_visibility_user_group/static/description/index.html @@ -0,0 +1,452 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Conditional visibility for internal users in Website

+ +

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

+

This module adds extra granularity in the visibility of the website +snippets allowing to set if the users that can see a block are internal +or portal ones.

+

Table of contents

+ +
+

Configuration

+

To configure the user group visibility:

+
    +
  • With the frontend editor opened select the block you want to set the +visibility for.
  • +
  • In Style tab of the editor panel set the Visibility option to +Conditional and unfold it.
  • +
  • Set the Users option to Visible for logged in.
  • +
  • Now you’ll see the new Groups option.
  • +
  • You can choose between Only internal users, Only portal users or +No restriction, which is the default value.
  • +
+
+
+

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
      +
    • David Vidal
    • +
    • Pilar Vargas
    • +
    • Carlos Roca
    • +
    • Adasat Torres
    • +
    +
  • +
+
+
+

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

+

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

+
+
+
+
+ + diff --git a/website_conditional_visibility_user_group/static/src/js/inject_dom.esm.js b/website_conditional_visibility_user_group/static/src/js/inject_dom.esm.js new file mode 100644 index 0000000000..42dfa01f32 --- /dev/null +++ b/website_conditional_visibility_user_group/static/src/js/inject_dom.esm.js @@ -0,0 +1,9 @@ +/* Copyright 2024 Tecnativa - David Vidal + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ +import {session} from "@web/session"; + +// Transfer the session's user group as an HTML element attribute so that the +// conditional visibility CSS selectors can be based on it. It's done at import +// time (and not on DOMContentLoaded) so the attribute is already set when +// website's `unhideConditionalElements()` injects the visibility rules. +document.documentElement.dataset.user_group = session.user_group; diff --git a/website_conditional_visibility_user_group/static/src/tests/snippet_visibility_portal_tests.esm.js b/website_conditional_visibility_user_group/static/src/tests/snippet_visibility_portal_tests.esm.js new file mode 100644 index 0000000000..8a6f619d69 --- /dev/null +++ b/website_conditional_visibility_user_group/static/src/tests/snippet_visibility_portal_tests.esm.js @@ -0,0 +1,32 @@ +/* Copyright 2024 Tecnativa - David Vidal + Copyright 2026 Tecnativa - Adasat Torres + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ + +import {registerWebsitePreviewTour} from "@website/js/tours/tour_utils"; + +registerWebsitePreviewTour( + "conditional_visibility_portal", + { + url: "/", + }, + () => [ + { + content: "Go to '/'", + trigger: 'header#top a[href="/"]', + expectUnloadPage: true, + run: "click", + }, + { + content: "The content previously hidden should now be visible", + trigger: "body #wrapwrap", + run: function () { + const style = window.getComputedStyle( + this.anchor.getElementsByClassName("s_text_image")[0] + ); + if (style.display === "none") { + console.error("error"); + } + }, + }, + ] +); diff --git a/website_conditional_visibility_user_group/static/src/tests/snippet_visibility_tests.esm.js b/website_conditional_visibility_user_group/static/src/tests/snippet_visibility_tests.esm.js new file mode 100644 index 0000000000..8a7dd95857 --- /dev/null +++ b/website_conditional_visibility_user_group/static/src/tests/snippet_visibility_tests.esm.js @@ -0,0 +1,62 @@ +/* Copyright 2024 Tecnativa - David Vidal + Copyrigt 2026 Tecnativa - Adasat Torres + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ +import { + changeOptionInPopover, + clickOnEditAndWaitEditMode, + clickOnSave, + clickOnSnippet, + insertSnippet, + registerWebsitePreviewTour, +} from "@website/js/tours/tour_utils"; + +const snippets = [ + { + id: "s_text_image", + name: "Text - Image", + groupName: "Content", + }, +]; +registerWebsitePreviewTour( + "conditional_visibility_only_internal_user", + { + url: "/", + edition: true, + }, + () => [ + ...insertSnippet(snippets[0]), + ...clickOnSnippet(snippets[0]), + ...changeOptionInPopover("Text - Image", "Visibility", "Conditionally"), + ...changeOptionInPopover("Text - Image", "Users", "Visible for Logged In"), + ...changeOptionInPopover("Text - Image", "Groups", "Only portal users"), + ...clickOnSave(), + { + trigger: ".o_website_preview", + }, + { + content: "Check if the rule was applied", + trigger: ":iframe #wrap:not(:visible)", + run: function () { + const style = window.getComputedStyle( + this.anchor.getElementsByClassName("s_text_image")[0] + ); + if (style.display !== "none") { + console.error("error"); + } + }, + }, + ...clickOnEditAndWaitEditMode(), + { + content: + "Check if the element is visible as it should always be visible in edit view", + trigger: ":iframe #wrap .s_text_image", + run: function () { + const style = window.getComputedStyle(this.anchor); + if (style.display === "none") { + console.error("error"); + } + }, + }, + ...clickOnSave(), + ] +); diff --git a/website_conditional_visibility_user_group/static/src/website_builder/visibility_option.xml b/website_conditional_visibility_user_group/static/src/website_builder/visibility_option.xml new file mode 100644 index 0000000000..8870aeb0a5 --- /dev/null +++ b/website_conditional_visibility_user_group/static/src/website_builder/visibility_option.xml @@ -0,0 +1,37 @@ + + + + 'visibility_value_logged' + + + + + No restriction + Only portal users + Only internal users + + + + + diff --git a/website_conditional_visibility_user_group/static/src/website_builder/visibility_option_plugin.esm.js b/website_conditional_visibility_user_group/static/src/website_builder/visibility_option_plugin.esm.js new file mode 100644 index 0000000000..98200765dd --- /dev/null +++ b/website_conditional_visibility_user_group/static/src/website_builder/visibility_option_plugin.esm.js @@ -0,0 +1,60 @@ +/* + Copyrigt 2026 Tecnativa - Carlos Roca + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ +import {registry} from "@web/core/registry"; +import {Plugin} from "@html_editor/plugin"; +import {selectElements} from "@html_editor/utils/dom_traversal"; +import {withSequence} from "@html_editor/utils/resource"; +import {VisibilityOption} from "@website/builder/plugins/options/visibility_option"; + +const LOGGED_IN_VALUE = "true"; + +class VisibilityGroupOptionPlugin extends Plugin { + static id = "visibilityGroupOption"; + resources = { + visibility_selector_parameters: [ + { + saveAttribute: "visibilityUserGroup", + attributeName: "data-user_group", + callWith: "value", + }, + ], + normalize_handlers: withSequence(1, this.cleanUserGroup.bind(this)), + }; + + /** + * The group restriction only makes sense on top of "Visible for Logged In". + * Drop it as soon as that condition no longer holds, otherwise it would + * keep hiding the snippet with no visible option to undo it. + * + * @param {HTMLElement} rootEl + */ + cleanUserGroup(rootEl) { + for (const el of selectElements(rootEl, VisibilityOption.selector)) { + if (!el.dataset.visibilityUserGroup) { + continue; + } + if (el.dataset.visibility !== "conditional" || !this.isLoggedInOnly(el)) { + delete el.dataset.visibilityUserGroup; + } + } + } + + isLoggedInOnly(el) { + const logged = el.dataset.visibilityValueLogged; + if (!logged || el.dataset.visibilityValueLoggedRule === "hide") { + return false; + } + try { + return JSON.parse(logged).some( + (record) => String(record.value) === LOGGED_IN_VALUE + ); + } catch { + return false; + } + } +} + +registry + .category("website-plugins") + .add(VisibilityGroupOptionPlugin.id, VisibilityGroupOptionPlugin); diff --git a/website_conditional_visibility_user_group/tests/__init__.py b/website_conditional_visibility_user_group/tests/__init__.py new file mode 100644 index 0000000000..d1c4bc70cb --- /dev/null +++ b/website_conditional_visibility_user_group/tests/__init__.py @@ -0,0 +1 @@ +from . import test_conditional_visibility_user_group diff --git a/website_conditional_visibility_user_group/tests/test_conditional_visibility_user_group.py b/website_conditional_visibility_user_group/tests/test_conditional_visibility_user_group.py new file mode 100644 index 0000000000..d21c0546d3 --- /dev/null +++ b/website_conditional_visibility_user_group/tests/test_conditional_visibility_user_group.py @@ -0,0 +1,19 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import HttpCase, new_test_user, tagged + + +@tagged("-at_install", "post_install") +class TestConditionalVisibilityUserGroup(HttpCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + new_test_user(cls.env, login="portal_user", groups="base.group_portal") + + def test_snippet_for_internal_users(self): + """Only internal users can see the snippet""" + # We drag a new block, set its visibility to internal users and check that + # we can see it as internal users + self.start_tour("/", "conditional_visibility_only_internal_user", login="admin") + # The block is hidden for portal users + self.start_tour("/", "conditional_visibility_portal", login="portal_user")