summaryrefslogtreecommitdiff
path: root/addons/website/controllers/backend.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website/controllers/backend.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website/controllers/backend.py')
-rw-r--r--addons/website/controllers/backend.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py
new file mode 100644
index 00000000..89355a74
--- /dev/null
+++ b/addons/website/controllers/backend.py
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import http
+from odoo.http import request
+from odoo.tools.translate import _
+
+
+class WebsiteBackend(http.Controller):
+
+ @http.route('/website/fetch_dashboard_data', type="json", auth='user')
+ def fetch_dashboard_data(self, website_id, date_from, date_to):
+ 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
+ },
+ 'currency': request.env.company.currency_id.id,
+ 'dashboards': {
+ 'visits': {},
+ }
+ }
+
+ 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 rec, website in zip(websites, dashboard_data['websites']):
+ website['domain'] = rec._get_http_domain()
+ if website['id'] == current_website.id:
+ website['selected'] = True
+
+ if has_group_designer:
+ if current_website.google_management_client_id and current_website.google_analytics_key:
+ dashboard_data['dashboards']['visits'] = dict(
+ ga_client_id=current_website.google_management_client_id or '',
+ ga_analytics_key=current_website.google_analytics_key or '',
+ )
+ return dashboard_data
+
+ @http.route('/website/dashboard/set_ga_data', type='json', auth='user')
+ def website_set_ga_data(self, website_id, ga_client_id, ga_analytics_key):
+ if not request.env.user.has_group('base.group_system'):
+ return {
+ 'error': {
+ 'title': _('Access Error'),
+ 'message': _('You do not have sufficient rights to perform that action.'),
+ }
+ }
+ if not ga_analytics_key or not ga_client_id.endswith('.apps.googleusercontent.com'):
+ return {
+ 'error': {
+ 'title': _('Incorrect Client ID / Key'),
+ 'message': _('The Google Analytics Client ID or Key you entered seems incorrect.'),
+ }
+ }
+ Website = request.env['website']
+ current_website = website_id and Website.browse(website_id) or Website.get_current_website()
+
+ request.env['res.config.settings'].create({
+ 'google_management_client_id': ga_client_id,
+ 'google_analytics_key': ga_analytics_key,
+ 'website_id': current_website.id,
+ }).execute()
+ return True