[IMP] website: improve setting ga_client_id from dashboard
It now update the website settings parameter use_google_analytics_dashboard so that the settings are correctly updated with the user choice. Implementation is changed so that the dashboard uses a jsonRpc call instead of directly calling ir_config_parameter set_param.
This commit is contained in:
committed by
Yannick Tivisse
parent
ac23ca499e
commit
e331c0bd19
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user