[FIX] website: fix restricted_editor test

See merge commit for more information.

task-2687506
This commit is contained in:
Younn Olivier
2022-06-24 10:28:07 +02:00
committed by qsm-odoo
parent 2781214d7e
commit 95c8f1a6a8
7 changed files with 31 additions and 18 deletions
@@ -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'));
@@ -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 }))
@@ -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) {
@@ -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 });
@@ -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",
@@ -13,9 +13,13 @@ function makeFakeWebsiteService() {
get context() {
return {};
},
isPublisher() {
get isPublisher() {
return true;
},
get hasMultiWebsites() {
return true;
},
async fetchUserGroups() {},
};
}
};
+1 -1
View File
@@ -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')