diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.js b/addons/website/static/src/client_actions/website_preview/website_preview.js index 09d333e17a9..ba4df10f974 100644 --- a/addons/website/static/src/client_actions/website_preview/website_preview.js +++ b/addons/website/static/src/client_actions/website_preview/website_preview.js @@ -59,7 +59,6 @@ export class WebsitePreview extends Component { this.websiteContext = useState(this.websiteService.context); onWillStart(async () => { - this.isWebsitePublisher = await this.user.hasGroup('website.group_website_publisher'); await this.websiteService.fetchWebsites(); const encodedPath = encodeURIComponent(this.path); if (this.websiteDomain && this.websiteDomain !== window.location.origin) { @@ -151,7 +150,7 @@ export class WebsitePreview extends Component { } addWelcomeMessage() { - if (this.isWebsitePublisher) { + if (this.websiteService.isPublisher) { const $wrap = $(this.iframe.el.contentDocument.querySelector('#wrapwrap.homepage')).find('#wrap'); if ($wrap.length && $wrap.html().trim() === '') { this.$welcomeMessage = $(core.qweb.render('website.homepage_editor_welcome_message')); diff --git a/addons/website/static/src/components/navbar/navbar.js b/addons/website/static/src/components/navbar/navbar.js index 3dbb292448a..1ad5eae5872 100644 --- a/addons/website/static/src/components/navbar/navbar.js +++ b/addons/website/static/src/components/navbar/navbar.js @@ -10,7 +10,7 @@ import {WebsiteAceEditor, AceEditorAdapterComponent} from '@website/components/a import {PagePropertiesDialogWrapper} from '@website/components/dialog/page_properties'; const websiteSystrayRegistry = registry.category('website_systray'); -const { useState, onWillStart } = owl; +const { useState } = owl; patch(NavBar.prototype, 'website_navbar', { setup() { @@ -55,17 +55,13 @@ patch(NavBar.prototype, 'website_navbar', { isDisplayed: () => this.canShowPageProperties(), }, }; - - onWillStart(async () => { - this.isWebsitePublisher = await this.websiteService.isPublisher(); - }); }, filterWebsiteMenus(sections) { const filteredSections = []; for (const section of sections) { const isWebsiteCustomMenu = this.websiteEditingMenus[section.xmlid]; - const displayWebsiteCustomMenu = isWebsiteCustomMenu && this.isWebsitePublisher && this.websiteEditingMenus[section.xmlid].isDisplayed(); + const displayWebsiteCustomMenu = isWebsiteCustomMenu && this.websiteService.isPublisher && this.websiteEditingMenus[section.xmlid].isDisplayed(); if (!isWebsiteCustomMenu || displayWebsiteCustomMenu) { let subSections = []; if (section.childrenTree.length) { @@ -81,7 +77,7 @@ patch(NavBar.prototype, 'website_navbar', { * @override */ get systrayItems() { - if (this.websiteService.currentWebsite && this.isWebsitePublisher) { + if (this.websiteService.currentWebsite && this.websiteService.isPublisher) { return websiteSystrayRegistry .getEntries() .map(([key, value], index) => ({ key, ...value, index })) diff --git a/addons/website/static/src/services/website_service.js b/addons/website/static/src/services/website_service.js index 50cadc48a58..7b58cbcd242 100644 --- a/addons/website/static/src/services/website_service.js +++ b/addons/website/static/src/services/website_service.js @@ -34,6 +34,8 @@ export const websiteService = { let editedObjectPath; let websiteRootInstance; let Wysiwyg; + let isPublisher; + let hasMultiWebsites; const context = reactive({ showNewContentModal: false, showAceEditor: false, @@ -120,8 +122,11 @@ export const websiteService = { get editedObjectPath() { return editedObjectPath; }, - isPublisher() { - return user.hasGroup('website.group_website_publisher'); + get isPublisher() { + return isPublisher === true; + }, + get hasMultiWebsites() { + return hasMultiWebsites === true; }, openMenuDialog(Component, props) { return dialog.add(Component, props); @@ -140,12 +145,21 @@ export const websiteService = { }); }, async fetchWebsites() { + // Fetch user groups, before fetching the websites. + [isPublisher, hasMultiWebsites] = await Promise.all([ + user.hasGroup('website.group_website_publisher'), + user.hasGroup('website.group_multi_website'), + ]); + const [currentWebsiteRepr, allWebsites] = await Promise.all([ orm.call('website', 'get_current_website'), - orm.searchRead('website', []), + hasMultiWebsites ? orm.searchRead('website', [], ['domain', 'id', 'name']) : [], ]); websites = [...allWebsites]; setCurrentWebsiteId(unslugHtmlDataObject(currentWebsiteRepr).id); + if (!websites.length) { + websites = [{ id: currentWebsiteId }]; + } }, async loadWysiwyg() { if (!Wysiwyg) { diff --git a/addons/website/static/src/systray_items/website_switcher.js b/addons/website/static/src/systray_items/website_switcher.js index 87e74404369..ec01da957e3 100644 --- a/addons/website/static/src/systray_items/website_switcher.js +++ b/addons/website/static/src/systray_items/website_switcher.js @@ -36,6 +36,7 @@ WebsiteSwitcherSystray.components = { export const systrayItem = { Component: WebsiteSwitcherSystray, + isDisplayed: env => env.services.website.hasMultiWebsites, }; registry.category("website_systray").add("WebsiteSwitcher", systrayItem, { sequence: 11 }); diff --git a/addons/website/static/tests/tours/restricted_editor.js b/addons/website/static/tests/tours/restricted_editor.js index c1da7f5a279..187a1668a25 100644 --- a/addons/website/static/tests/tours/restricted_editor.js +++ b/addons/website/static/tests/tours/restricted_editor.js @@ -1,15 +1,14 @@ odoo.define("website.tour.restricted_editor", function (require) { "use strict"; -var tour = require("web_tour.tour"); +var wTourUtils = require("website.tour_utils"); -tour.register("restricted_editor", { +wTourUtils.registerEditionTour("restricted_editor", { test: true, url: "/", }, [{ - trigger: 'a.o_frontend_to_backend_edit_btn', + trigger: '.o_edit_website_container a', content: "Click \"EDIT\" button of website as Restricted Editor", - extra_trigger: ".homepage", }, { trigger: '#oe_snippets.o_loaded', content: "Check that the snippets loaded properly", diff --git a/addons/website/static/tests/website_service_mock.js b/addons/website/static/tests/website_service_mock.js index c89e167f041..87fb39adff9 100644 --- a/addons/website/static/tests/website_service_mock.js +++ b/addons/website/static/tests/website_service_mock.js @@ -13,9 +13,13 @@ function makeFakeWebsiteService() { get context() { return {}; }, - isPublisher() { + get isPublisher() { return true; }, + get hasMultiWebsites() { + return true; + }, + async fetchUserGroups() {}, }; } }; diff --git a/addons/website/tests/test_ui.py b/addons/website/tests/test_ui.py index d6aac693fc7..10ced6419db 100644 --- a/addons/website/tests/test_ui.py +++ b/addons/website/tests/test_ui.py @@ -138,7 +138,7 @@ class TestUi(odoo.tests.HttpCase): self.ref('website.group_website_publisher') ])] }) - self.start_tour("/", 'restricted_editor', login='restricted') + self.start_tour(self.env['website'].get_client_action_url('/'), 'restricted_editor', login='restricted') def test_03_backend_dashboard(self): self.start_tour("/", 'backend_dashboard', login='admin')