From 86e13b26acd12e2224c8b244f4d066aa94a357ad Mon Sep 17 00:00:00 2001 From: Mitchell Admin Date: Wed, 16 Jun 2021 10:37:51 +0000 Subject: [PATCH 1/3] :tada::one::three: web_website previous commits history: https://github.com/itpp-labs/misc-addons/commits/13.0/web_website > Made via .github/workflows/DINAR-PORT.yml --- web_website/README.rst | 72 +++++ web_website/__init__.py | 16 + web_website/__manifest__.py | 36 +++ web_website/api.py | 38 +++ web_website/demo/assets_demo.xml | 10 + web_website/demo/res_users_demo.xml | 9 + web_website/doc/changelog.rst | 83 ++++++ web_website/doc/index.rst | 48 +++ web_website/i18n/web_website.pot | 207 +++++++++++++ web_website/models/__init__.py | 6 + web_website/models/ir_http.py | 38 +++ web_website/models/ir_property.py | 277 ++++++++++++++++++ web_website/models/res_users.py | 81 +++++ web_website/models/test_website_dependent.py | 45 +++ web_website/models/website_dependent_mixin.py | 185 ++++++++++++ web_website/security/ir.model.access.csv | 3 + web_website/security/security.xml | 9 + web_website/static/description/icon.png | Bin 0 -> 3035 bytes web_website/static/description/index.html | 61 ++++ web_website/static/lib/js/session.js | 26 ++ .../static/lib/js/switch_website_menu.js | 151 ++++++++++ web_website/static/lib/js/web_client.js | 11 + web_website/static/src/js/tour.js | 28 ++ web_website/static/src/xml/qweb.xml | 79 +++++ web_website/tests/__init__.py | 2 + web_website/tests/test_ui.py | 30 ++ web_website/tests/test_website_dependent.py | 257 ++++++++++++++++ web_website/views/assets.xml | 21 ++ web_website/views/ir_property_views.xml | 35 +++ web_website/views/res_users_views.xml | 31 ++ 30 files changed, 1895 insertions(+) create mode 100644 web_website/README.rst create mode 100644 web_website/__init__.py create mode 100644 web_website/__manifest__.py create mode 100644 web_website/api.py create mode 100644 web_website/demo/assets_demo.xml create mode 100644 web_website/demo/res_users_demo.xml create mode 100644 web_website/doc/changelog.rst create mode 100644 web_website/doc/index.rst create mode 100644 web_website/i18n/web_website.pot create mode 100644 web_website/models/__init__.py create mode 100644 web_website/models/ir_http.py create mode 100644 web_website/models/ir_property.py create mode 100644 web_website/models/res_users.py create mode 100644 web_website/models/test_website_dependent.py create mode 100644 web_website/models/website_dependent_mixin.py create mode 100644 web_website/security/ir.model.access.csv create mode 100644 web_website/security/security.xml create mode 100644 web_website/static/description/icon.png create mode 100644 web_website/static/description/index.html create mode 100644 web_website/static/lib/js/session.js create mode 100644 web_website/static/lib/js/switch_website_menu.js create mode 100644 web_website/static/lib/js/web_client.js create mode 100644 web_website/static/src/js/tour.js create mode 100644 web_website/static/src/xml/qweb.xml create mode 100644 web_website/tests/__init__.py create mode 100644 web_website/tests/test_ui.py create mode 100644 web_website/tests/test_website_dependent.py create mode 100644 web_website/views/assets.xml create mode 100644 web_website/views/ir_property_views.xml create mode 100644 web_website/views/res_users_views.xml diff --git a/web_website/README.rst b/web_website/README.rst new file mode 100644 index 0000000000..f0476b6168 --- /dev/null +++ b/web_website/README.rst @@ -0,0 +1,72 @@ +.. image:: https://itpp.dev/images/infinity-readme.png + :alt: Tested and maintained by IT Projects Labs + :target: https://itpp.dev + +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg + :target: http://www.gnu.org/licenses/lgpl + :alt: License: LGPL-3.0 + +===================== + Multi-Brand Backend +===================== + +Technical module to properly handle multi-website setup. + +The modules sets context variable **allowed_website_ids**: + +* in backend: selected websites +* in frontend: current website (as a list) + +The module adds ``env`` properties: + +* ``env.website`` -- first website from the list: ``browse(context["allowed_website_ids"][0])`` +* ``env.websites`` -- all websites: ``browse(context["allowed_website_ids"])`` + +website_dependent +================= + +The module adds new field attribute ``website_dependent``, which is analog of ``company_dependent``, but for websites. + +See ``_ and ``_ to understand how it works. + +If you need to convert existing field to a website-dependent field it's not +enough just to add the attributes. You need additional stuff to make your module +safely installable and uninstallable. See module +``ir_config_parameter_multi_company`` as an example. Things to do: + +* extend ``ir.property``'s ``write`` to call ``_update_db_value_website_dependent`` +* Add to the field both ``company_dependent=True`` and ``website_dependent=True`` +* In the field's module extend following methods: + + * ``create`` -- call ``_force_default`` + * ``write`` -- call ``_update_properties_label`` + * ``_auto_init`` -- call ``_auto_init_website_dependent`` + +* In the field's module add ``uninstall_hook``: + + * remove field's properties + +Roadmap +======= + +* TODO: Since odoo 12, there is another switcher at ``[[ Website ]] >> Dashboard`` menu. It has to be syncronized with the switcher of this module, i.e. hide default one and use value of this module switcher. + +Questions? +========== + +To get an assistance on this module contact us by email :arrow_right: help@itpp.dev + +Contributors +============ +* `Ivan Yelizariev `__ + + +Further information +=================== + +Odoo Apps Store: https://apps.odoo.com/apps/modules/13.0/web_website/ + + +Notifications on updates: `via Atom `_, `by Email `_ + +Tested on `Odoo 13.0 `_ diff --git a/web_website/__init__.py b/web_website/__init__.py new file mode 100644 index 0000000000..44979cb486 --- /dev/null +++ b/web_website/__init__.py @@ -0,0 +1,16 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from . import models + + +def post_init_hook(cr, registry): + from odoo import api, SUPERUSER_ID + + env = api.Environment(cr, SUPERUSER_ID, {}) + + # emulate updating existing field to website-dependent one + env.cr.execute("ALTER TABLE test_website_dependent ADD COLUMN foo VARCHAR") + env.cr.execute("ALTER TABLE test_website_dependent ADD COLUMN user_id INTEGER") + + +def post_load(): + from . import api diff --git a/web_website/__manifest__.py b/web_website/__manifest__.py new file mode 100644 index 0000000000..36c66fe689 --- /dev/null +++ b/web_website/__manifest__.py @@ -0,0 +1,36 @@ +# Copyright 2018,2020 Ivan Yelizariev +# Copyright 2018 Kolushov Alexandr +# Copyright 2019 Eugene Molotov +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +{ + "name": """Multi-Brand Backend""", + "summary": """Technical module to switch Websites in Backend similarly to Company Switcher""", + "category": "Hidden", + # "live_test_url": "", + "images": [], + "version": "13.0.4.0.2", + "application": False, + "author": "IT-Projects LLC, Ivan Yelizariev", + "support": "apps@itpp.dev", + "website": "https://itpp.dev", + "license": "LGPL-3", + # "price": 0.00, + # "currency": "EUR", + "depends": ["web", "website", "base_setup"], + "external_dependencies": {"python": [], "bin": []}, + "data": [ + "views/res_users_views.xml", + "security/security.xml", + "security/ir.model.access.csv", + "views/ir_property_views.xml", + "views/assets.xml", + ], + "demo": ["demo/assets_demo.xml", "demo/res_users_demo.xml"], + "qweb": ["static/src/xml/qweb.xml"], + "post_load": "post_load", + "pre_init_hook": None, + "post_init_hook": "post_init_hook", + "uninstall_hook": None, + "auto_install": False, + "installable": True, +} diff --git a/web_website/api.py b/web_website/api.py new file mode 100644 index 0000000000..383d1f1c89 --- /dev/null +++ b/web_website/api.py @@ -0,0 +1,38 @@ +# Copyright 2020 Ivan Yelizariev +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from odoo import _ +from odoo.api import Environment +from odoo.exceptions import AccessError +from odoo.tools import lazy_property + + +@lazy_property +def website(self): + """Like env.company, but for website""" + website_ids = self.context.get("allowed_website_ids", []) + if website_ids: + if not self.su: + user_website_ids = self.user.backend_website_ids.ids + if any(cid not in user_website_ids for cid in website_ids): + raise AccessError(_("Access to unauthorized or invalid websites.")) + return self["website"].browse(website_ids[0]) + return self.user.backend_website_id + + +@lazy_property +def websites(self): + """Like env.companies, but for websites""" + website_ids = self.context.get("allowed_website_ids", []) + if website_ids: + if not self.su: + user_website_ids = self.user.website_ids.ids + if user_website_ids and any( + cid not in user_website_ids for cid in website_ids + ): + raise AccessError(_("Access to unauthorized or invalid websites.")) + return self["website"].browse(website_ids) + return self.user.backend_website_ids + + +Environment.website = website +Environment.websites = websites diff --git a/web_website/demo/assets_demo.xml b/web_website/demo/assets_demo.xml new file mode 100644 index 0000000000..3f314baf8f --- /dev/null +++ b/web_website/demo/assets_demo.xml @@ -0,0 +1,10 @@ + + + +