From 59c932477edf0ccff68dfa18e97a3bd76b6e251d Mon Sep 17 00:00:00 2001 From: jke-openerp Date: Thu, 19 Dec 2013 17:50:11 +0100 Subject: [PATCH] [IMP] Redirect admin to configurations page for Google Calendar API when trying synchro but not still configured bzr revid: jke@openerp.com-20131219165011-xgy18qcr1n1q4jz1 --- addons/google_calendar/controllers/main.py | 7 ++++++- addons/google_calendar/google_calendar.py | 5 ++++- .../google_calendar/static/src/js/calendar_sync.js | 12 ++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/addons/google_calendar/controllers/main.py b/addons/google_calendar/controllers/main.py index a30ff0122fe..cc9fea91ed6 100644 --- a/addons/google_calendar/controllers/main.py +++ b/addons/google_calendar/controllers/main.py @@ -28,9 +28,14 @@ class google_calendar_controller(http.Controller): client_id = gs_obj.get_client_id(request.cr, request.uid,'calendar',context=kw.get('LocalContext')) if not client_id or client_id == '': + action = '' + if gc_obj.can_authorize_google(request.cr,request.uid): + dummy, action = request.registry.get('ir.model.data').get_object_reference(request.cr, request.uid, 'google_calendar', 'action_config_settings_google_calendar') + return { "status" : "NeedConfigFromAdmin", - "url" : '' + "url" : '', + "action" : action } # Checking that user have already accepted OpenERP to access his calendar ! diff --git a/addons/google_calendar/google_calendar.py b/addons/google_calendar/google_calendar.py index a0fc8f46732..eea8d83f1fb 100644 --- a/addons/google_calendar/google_calendar.py +++ b/addons/google_calendar/google_calendar.py @@ -663,7 +663,7 @@ class google_calendar(osv.osv): def need_authorize(self,cr,uid,context=None): current_user = self.pool.get('res.users').browse(cr,uid,uid,context=context) return current_user.google_calendar_rtoken == False - + def get_calendar_scope(self,RO=False): readonly = RO and '.readonly' or '' return 'https://www.googleapis.com/auth/calendar%s' % (readonly) @@ -671,6 +671,9 @@ class google_calendar(osv.osv): def authorize_google_uri(self,cr,uid,from_url='http://www.openerp.com',context=None): url = self.pool.get('google.service')._get_authorize_uri(cr,uid,from_url,self.STR_SERVICE,scope=self.get_calendar_scope(),context=context) return url + + def can_authorize_google(self,cr,uid,context=None): + return self.pool['res.users'].has_group(cr, uid, 'base.group_erp_manager') def set_all_tokens(self,cr,uid,authorization_code,context=None): gs_pool = self.pool.get('google.service') diff --git a/addons/google_calendar/static/src/js/calendar_sync.js b/addons/google_calendar/static/src/js/calendar_sync.js index dd5ae718e46..39bdb8144eb 100644 --- a/addons/google_calendar/static/src/js/calendar_sync.js +++ b/addons/google_calendar/static/src/js/calendar_sync.js @@ -32,8 +32,16 @@ openerp.google_calendar = function(instance) { window.location = o.url; } else if (o.status == "NeedConfigFromAdmin") { - alert(_t("Admin need to configure Google Synchronization before to use it !")); - window.location = o.url; + + if (typeof o.action !== 'undefined' && parseInt(o.action)) { + if (confirm(_t("An admin need to configure Google Synchronization before to use it, do you want to configure it now ? !"))) { + self.do_action(o.action); + } + } + else { + alert(_t("An admin need to configure Google Synchronization before to use it !")); + } + //window.location = o.url; } else if (o.status == "NeedRefresh"){ self.$calendar.fullCalendar('refetchEvents');