diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py index 0aeb2540133..8a59d730714 100644 --- a/addons/website/controllers/backend.py +++ b/addons/website/controllers/backend.py @@ -35,3 +35,25 @@ class WebsiteBackend(http.Controller): ga_client_id = request.env['ir.config_parameter'].sudo().get_param('google_management_client_id', default='') dashboard_data['dashboards']['visits']['ga_client_id'] = ga_client_id return dashboard_data + + @http.route('/website/dashboard/set_ga_client_id', type='json', auth='user') + def website_set_ga_client_id(self, ga_client_id): + 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_client_id.endswith('.apps.googleusercontent.com') or ga_client_id.startswith(" "): + return { + 'error': { + 'title': 'Incorrect Client ID', + 'message': 'The Google Analytics Client ID you have entered seems incorrect.', + } + } + request.env['website.config.setting'].create({ + 'use_google_analytics_dashboard': True, + 'google_management_client_id': ga_client_id, + }) + return True diff --git a/addons/website/static/src/js/website.backendDashboard.js b/addons/website/static/src/js/website.backendDashboard.js index 9c6416da4ac..f5c9c6b7b2f 100644 --- a/addons/website/static/src/js/website.backendDashboard.js +++ b/addons/website/static/src/js/website.backendDashboard.js @@ -96,21 +96,19 @@ var Dashboard = Widget.extend(ControlPanelMixin, { }, on_save_ga_client_id: function(ga_client_id) { - - if (!ga_client_id.endsWith(".apps.googleusercontent.com") || ga_client_id.startsWith(" ")) { - this.do_warn(_t('Incorrect Client ID'), _t('The Google Analytics Client ID you have entered seems incorrect.')); - return; - } - var self = this; - this._rpc({ - model: 'ir.config_parameter', - method: 'set_param', - args: ['google_management_client_id', ga_client_id], - }) - .then(function(){ - self.on_date_range_button('week'); - }); + return this._rpc({ + route: '/website/dashboard/set_ga_client_id', + params: { + 'ga_client_id': ga_client_id + }, + }).then(function (result) { + if (result.error) { + self.do_warn(result.error.title, result.error.message); + return; + } + self.on_date_range_button('week'); + }); }, render_dashboards: function() {