Files
odoo_source/addons/website/controllers/backend.py
T
Arthur Detroux (ard) 4da1e0e0f0 [REF] website: update the dashboard widget to OWL
This commit converts the Website Dashboard to OWL.
The main goal of the Website Dashboard is to display the Plausible
Dashboard inside an iframe. Most of the code from the legacy widget was
actually used by website_sale and not website. Since Website Sale
dashboard is to be re-done in the dashboard app (by task-3222991), a lot
of the logic could be removed and simplified.

task-3164163

closes odoo/odoo#112819

Related: odoo/enterprise#44087
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2023-07-17 12:05:58 +02:00

57 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import werkzeug
from odoo import http
from odoo.http import request
class WebsiteBackend(http.Controller):
@http.route('/website/fetch_dashboard_data', type="json", auth='user')
def fetch_dashboard_data(self, website_id):
Website = request.env['website']
has_group_system = request.env.user.has_group('base.group_system')
has_group_designer = request.env.user.has_group('website.group_website_designer')
dashboard_data = {
'groups': {
'system': has_group_system,
'website_designer': has_group_designer
},
'dashboards': {}
}
current_website = website_id and Website.browse(website_id) or Website.get_current_website()
multi_website = request.env.user.has_group('website.group_multi_website')
websites = multi_website and request.env['website'].search([]) or current_website
dashboard_data['websites'] = websites.read(['id', 'name'])
for website in dashboard_data['websites']:
if website['id'] == current_website.id:
website['selected'] = True
if has_group_designer:
dashboard_data['dashboards']['plausible_share_url'] = current_website._get_plausible_share_url()
return dashboard_data
@http.route('/website/iframefallback', type="http", auth='user', website=True)
def get_iframe_fallback(self):
return request.render('website.iframefallback')
@http.route('/website/check_new_content_access_rights', type="json", auth='user')
def check_create_access_rights(self, models):
"""
TODO: In master, remove this route and method and find a better way
to do this. This route is only here to ensure that the "New Content"
modal displays the correct elements for each user, and there might be
a way to do it with the framework rather than having a dedicated
controller route. (maybe by using a template or a JS util)
"""
if not request.env.user.has_group('website.group_website_restricted_editor'):
raise werkzeug.exceptions.Forbidden()
return {
model: request.env[model].check_access_rights('create', raise_exception=False)
for model in models
}