diff --git a/addons/google_base_account/__init__.py b/addons/google_account/__init__.py similarity index 97% rename from addons/google_base_account/__init__.py rename to addons/google_account/__init__.py index ee900c8febc..640a9747f2d 100644 --- a/addons/google_base_account/__init__.py +++ b/addons/google_account/__init__.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # ############################################################################## -import google_base_account +import google_account import controllers # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/google_base_account/__openerp__.py b/addons/google_account/__openerp__.py similarity index 97% rename from addons/google_base_account/__openerp__.py rename to addons/google_account/__openerp__.py index 99678d2785d..5c3834ae65e 100644 --- a/addons/google_base_account/__openerp__.py +++ b/addons/google_account/__openerp__.py @@ -32,7 +32,7 @@ The module adds google user in res user. 'website': 'http://www.openerp.com', 'depends': ['base_setup'], 'data': [ - 'google_base_account_data.xml', + 'google_account_data.xml', ], 'demo': [], 'installable': True, diff --git a/addons/google_base_account/controllers/__init__.py b/addons/google_account/controllers/__init__.py similarity index 100% rename from addons/google_base_account/controllers/__init__.py rename to addons/google_account/controllers/__init__.py diff --git a/addons/google_account/controllers/main.py b/addons/google_account/controllers/main.py new file mode 100644 index 00000000000..7576351e470 --- /dev/null +++ b/addons/google_account/controllers/main.py @@ -0,0 +1,34 @@ +import simplejson +import urllib +import openerp +import openerp.addons.web.http as http +from openerp.addons.web.http import request +import openerp.addons.web.controllers.main as webmain +from openerp.addons.web.http import SessionExpiredException +from werkzeug.exceptions import BadRequest +import werkzeug.utils + +class google_auth(http.Controller): + + @http.route('/google_account/authentication', type='http', auth="none") + def oauth2callback(self, **kw): + """ This route/function is called by Google when user Accept/Refuse the consent of Google """ + + state = simplejson.loads(kw['state']) + dbname = state.get('d') + service = state.get('s') + url_return = state.get('from') + + registry = openerp.modules.registry.RegistryManager.get(dbname) + with registry.cursor() as cr: + if kw.get('code'): + registry.get('google.%s' % service).set_all_tokens(cr,request.session.uid,kw['code']) + return werkzeug.utils.redirect(url_return) + + #TODO - Display error at customer if url contains ?Error= + elif kw.get('error'): + return werkzeug.utils.redirect("%s%s%s" % (url_return ,"?Error=" , kw.get('error'))) + else: + return werkzeug.utils.redirect("%s%s%s" % (url_return ,"?Error=Unknown_error")) + + diff --git a/addons/google_base_account/google_base_account.py b/addons/google_account/google_account.py similarity index 98% rename from addons/google_base_account/google_base_account.py rename to addons/google_account/google_account.py index ab4364ad52d..35a3da54971 100644 --- a/addons/google_base_account/google_base_account.py +++ b/addons/google_account/google_account.py @@ -81,8 +81,8 @@ class google_service(osv.osv_memory): 'client_id': client_id, 'state' : simplejson.dumps(state_obj), 'scope': scope or 'https://www.googleapis.com/auth/%s' % (service,), - 'redirect_uri': base_url + '/googleauth/oauth2callback', - 'approval_prompt':'force', + 'redirect_uri': base_url + '/google_account/authentication', + #'approval_prompt':'force', 'access_type':'offline' } @@ -100,7 +100,7 @@ class google_service(osv.osv_memory): 'client_id': client_id, 'client_secret': client_secret, 'grant_type' : 'authorization_code', - 'redirect_uri': base_url + '/googleauth/oauth2callback' + #'redirect_uri': base_url + '/google_account/authentication' } headers = {"content-type": "application/x-www-form-urlencoded"} diff --git a/addons/google_base_account/google_base_account_data.xml b/addons/google_account/google_account.xml similarity index 100% rename from addons/google_base_account/google_base_account_data.xml rename to addons/google_account/google_account.xml diff --git a/addons/google_account/google_account_data.xml b/addons/google_account/google_account_data.xml new file mode 100644 index 00000000000..c6748df7dc9 --- /dev/null +++ b/addons/google_account/google_account_data.xml @@ -0,0 +1,9 @@ + + + + + google_redirect_uri + urn:ietf:wg:oauth:2.0:oob + + + \ No newline at end of file diff --git a/addons/google_base_account/i18n/ar.po b/addons/google_account/i18n/ar.po similarity index 100% rename from addons/google_base_account/i18n/ar.po rename to addons/google_account/i18n/ar.po diff --git a/addons/google_base_account/i18n/cs.po b/addons/google_account/i18n/cs.po similarity index 100% rename from addons/google_base_account/i18n/cs.po rename to addons/google_account/i18n/cs.po diff --git a/addons/google_base_account/i18n/de.po b/addons/google_account/i18n/de.po similarity index 100% rename from addons/google_base_account/i18n/de.po rename to addons/google_account/i18n/de.po diff --git a/addons/google_base_account/i18n/es.po b/addons/google_account/i18n/es.po similarity index 100% rename from addons/google_base_account/i18n/es.po rename to addons/google_account/i18n/es.po diff --git a/addons/google_base_account/i18n/es_CR.po b/addons/google_account/i18n/es_CR.po similarity index 100% rename from addons/google_base_account/i18n/es_CR.po rename to addons/google_account/i18n/es_CR.po diff --git a/addons/google_base_account/i18n/fi.po b/addons/google_account/i18n/fi.po similarity index 100% rename from addons/google_base_account/i18n/fi.po rename to addons/google_account/i18n/fi.po diff --git a/addons/google_base_account/i18n/fr.po b/addons/google_account/i18n/fr.po similarity index 100% rename from addons/google_base_account/i18n/fr.po rename to addons/google_account/i18n/fr.po diff --git a/addons/google_base_account/i18n/google_base_account.pot b/addons/google_account/i18n/google_base_account.pot similarity index 100% rename from addons/google_base_account/i18n/google_base_account.pot rename to addons/google_account/i18n/google_base_account.pot diff --git a/addons/google_base_account/i18n/hr.po b/addons/google_account/i18n/hr.po similarity index 100% rename from addons/google_base_account/i18n/hr.po rename to addons/google_account/i18n/hr.po diff --git a/addons/google_base_account/i18n/hu.po b/addons/google_account/i18n/hu.po similarity index 100% rename from addons/google_base_account/i18n/hu.po rename to addons/google_account/i18n/hu.po diff --git a/addons/google_base_account/i18n/it.po b/addons/google_account/i18n/it.po similarity index 100% rename from addons/google_base_account/i18n/it.po rename to addons/google_account/i18n/it.po diff --git a/addons/google_base_account/i18n/ja.po b/addons/google_account/i18n/ja.po similarity index 100% rename from addons/google_base_account/i18n/ja.po rename to addons/google_account/i18n/ja.po diff --git a/addons/google_base_account/i18n/mk.po b/addons/google_account/i18n/mk.po similarity index 100% rename from addons/google_base_account/i18n/mk.po rename to addons/google_account/i18n/mk.po diff --git a/addons/google_base_account/i18n/mn.po b/addons/google_account/i18n/mn.po similarity index 100% rename from addons/google_base_account/i18n/mn.po rename to addons/google_account/i18n/mn.po diff --git a/addons/google_base_account/i18n/nb.po b/addons/google_account/i18n/nb.po similarity index 100% rename from addons/google_base_account/i18n/nb.po rename to addons/google_account/i18n/nb.po diff --git a/addons/google_base_account/i18n/nl.po b/addons/google_account/i18n/nl.po similarity index 100% rename from addons/google_base_account/i18n/nl.po rename to addons/google_account/i18n/nl.po diff --git a/addons/google_base_account/i18n/pl.po b/addons/google_account/i18n/pl.po similarity index 100% rename from addons/google_base_account/i18n/pl.po rename to addons/google_account/i18n/pl.po diff --git a/addons/google_base_account/i18n/pt.po b/addons/google_account/i18n/pt.po similarity index 100% rename from addons/google_base_account/i18n/pt.po rename to addons/google_account/i18n/pt.po diff --git a/addons/google_base_account/i18n/pt_BR.po b/addons/google_account/i18n/pt_BR.po similarity index 100% rename from addons/google_base_account/i18n/pt_BR.po rename to addons/google_account/i18n/pt_BR.po diff --git a/addons/google_base_account/i18n/ro.po b/addons/google_account/i18n/ro.po similarity index 100% rename from addons/google_base_account/i18n/ro.po rename to addons/google_account/i18n/ro.po diff --git a/addons/google_base_account/i18n/ru.po b/addons/google_account/i18n/ru.po similarity index 100% rename from addons/google_base_account/i18n/ru.po rename to addons/google_account/i18n/ru.po diff --git a/addons/google_base_account/i18n/sl.po b/addons/google_account/i18n/sl.po similarity index 100% rename from addons/google_base_account/i18n/sl.po rename to addons/google_account/i18n/sl.po diff --git a/addons/google_base_account/i18n/sr@latin.po b/addons/google_account/i18n/sr@latin.po similarity index 100% rename from addons/google_base_account/i18n/sr@latin.po rename to addons/google_account/i18n/sr@latin.po diff --git a/addons/google_base_account/i18n/sv.po b/addons/google_account/i18n/sv.po similarity index 100% rename from addons/google_base_account/i18n/sv.po rename to addons/google_account/i18n/sv.po diff --git a/addons/google_base_account/i18n/tr.po b/addons/google_account/i18n/tr.po similarity index 100% rename from addons/google_base_account/i18n/tr.po rename to addons/google_account/i18n/tr.po diff --git a/addons/google_base_account/i18n/zh_CN.po b/addons/google_account/i18n/zh_CN.po similarity index 100% rename from addons/google_base_account/i18n/zh_CN.po rename to addons/google_account/i18n/zh_CN.po diff --git a/addons/google_base_account/controllers/main.py b/addons/google_base_account/controllers/main.py deleted file mode 100644 index 30e72a86b82..00000000000 --- a/addons/google_base_account/controllers/main.py +++ /dev/null @@ -1,144 +0,0 @@ -import simplejson -import urllib -import openerp -import openerp.addons.web.http as http -from openerp.addons.web.http import request -import openerp.addons.web.controllers.main as webmain -from openerp.addons.web.http import SessionExpiredException -from werkzeug.exceptions import BadRequest -import werkzeug.utils - -class google_auth(http.Controller): - - @http.route('/googleauth/oauth2callback', type='http', auth="none") - def oauth2callback(self, **kw): - """ This route/function is called by Google when user Accept/Refuse the consent of Google """ - - state = simplejson.loads(kw['state']) - dbname = state.get('d') - service = state.get('s') - url_return = state.get('from') - - registry = openerp.modules.registry.RegistryManager.get(dbname) - with registry.cursor() as cr: - if kw.get('code'): - registry.get('google.%s' % service).set_all_tokens(cr,request.session.uid,kw['code']) - return werkzeug.utils.redirect(url_return) - - #TODO - Display error at customer if url contains ?Error= - elif kw.get('error'): - return werkzeug.utils.redirect("%s%s%s" % (url_return ,"?Error=" , kw.get('error'))) - else: - return werkzeug.utils.redirect("%s%s%s" % (url_return ,"?Error=Unknown_error")) - - - @http.route('/web_calendar_sync/sync_calendar/sync_data', type='json', auth='user') - def sync_data(self, arch, fields, model,**kw): - """ - This route/function is called when we want to synchronize openERP calendar with Google Calendar - - Function return a dictionary with the status : NeedConfigFromAdmin, NeedAuth, NeedRefresh, NoNewEventFromGoogle, SUCCESS if not crm meeting - The dictionary may contains an url, to allow OpenERP Client to redirect user on this URL for authorization for example - - """ - - if model == 'crm.meeting': - gs_obj = request.registry.get('google.service') - gc_obj = request.registry.get('google.calendar') - - # Checking that admin have already configured Google API for google synchronization ! - client_id = gs_obj.get_client_id(request.cr, request.uid,'calendar',context=kw.get('LocalContext')) - - if not client_id or client_id == '': - return { - "status" : "NeedConfigFromAdmin", - "url" : '' - } - - # Checking that user have already accepted OpenERP to access his calendar ! - if gc_obj.need_authorize(request.cr, request.uid,context=kw.get('LocalContext')): - url = gc_obj.authorize_google_uri(request.cr, request.uid, from_url=kw.get('fromurl'),context=kw.get('LocalContext')) - return { - "status" : "NeedAuth", - "url" : url - } - - # If App authorized, and user access accepted, We launch the synchronization - return gc_obj.synchronize_events(request.cr, request.uid, [], kw.get('LocalContext')) - - return { "status" : "SUCCESS" } - - - - - - - - - - - - - - - - - - - - - - - - - @http.route('/gmail/delete_all', type='http', auth='user') - def delete_all(self, **kw): - gs_obj = request.registry.get('google.service') - gc_obj = request.registry.get('google.calendar') - - #We check that admin has already configure api for google synchronization ! - client_id = gs_obj.get_client_id(request.cr, request.uid,'calendar',context=kw.get('LocalContext')) - - if not client_id or client_id == '': - return { - "status" : "NeedConfigFromAdmin", - "url" : '' - } - - #We check that user has already accepted openerp to access his calendar ! - if gc_obj.need_authorize(request.cr, request.uid,context=kw.get('LocalContext')): - url = gc_obj.authorize_google_uri(request.cr, request.uid, from_url=kw.get('fromurl'),context=kw.get('LocalContext')) - return { - "status" : "NeedAuth", - "url" : url - } - - #We launch the synchronization - gc_obj.delete_all(request.cr, request.uid, kw.get('LocalContext')) - - - - @http.route('/googleauth/AuthorizeMe', type='http', auth="none") - def authorize_app(self,**val): - if val.get('done'): - return; - registry = openerp.modules.registry.RegistryManager.get(request.session.get('db')) - gs_pool = registry.get('google.service') - with registry.cursor() as cr: - url = gs_pool._get_authorize_uri(cr,request.session.uid,service='calendar',from_url='') - return werkzeug.utils.redirect(url) ##REDIRECT WHERE THE USER WAS BEFORE (with state) - - - @http.route('/googleauth/GiveMeAToken', type='http', auth="none") - def authorize_me(self,**val): - registry = openerp.modules.registry.RegistryManager.get(request.session.get('db')) - gs_pool = registry.get('google.service') - with registry.cursor() as cr: - token = gs_pool._get_google_token_json(cr, request.session.uid, 'api_code') - - print '#####################################' - print '## YOUR TOKEN : ',token, " ##" - print '#####################################' - #return werkzeug.utils.redirect(url) - return - diff --git a/addons/google_calendar/__init__.py b/addons/google_calendar/__init__.py index 9311a17b228..addb295d7c1 100644 --- a/addons/google_calendar/__init__.py +++ b/addons/google_calendar/__init__.py @@ -1,2 +1,3 @@ import res_config import google_calendar +import controllers diff --git a/addons/google_calendar/__openerp__.py b/addons/google_calendar/__openerp__.py index fd885b406db..c85870f9dfd 100644 --- a/addons/google_calendar/__openerp__.py +++ b/addons/google_calendar/__openerp__.py @@ -30,7 +30,7 @@ The module adds the possibility to synchronize Google Calendar with OpenERP """, 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', - 'depends': ['google_base_account','base_calendar'], + 'depends': ['google_account','base_calendar'], 'css': ['static/src/css/*.css'], 'js': ['static/src/js/*.js'], 'qweb': ['static/src/xml/*.xml'], diff --git a/addons/google_calendar/controllers/__init__.py b/addons/google_calendar/controllers/__init__.py new file mode 100644 index 00000000000..8ee9bae18d9 --- /dev/null +++ b/addons/google_calendar/controllers/__init__.py @@ -0,0 +1 @@ +import main diff --git a/addons/google_calendar/controllers/main.py b/addons/google_calendar/controllers/main.py new file mode 100644 index 00000000000..a30ff0122fe --- /dev/null +++ b/addons/google_calendar/controllers/main.py @@ -0,0 +1,48 @@ +import simplejson +import urllib +import openerp +import openerp.addons.web.http as http +from openerp.addons.web.http import request +import openerp.addons.web.controllers.main as webmain +from openerp.addons.web.http import SessionExpiredException +from werkzeug.exceptions import BadRequest +import werkzeug.utils + +class google_calendar_controller(http.Controller): + + @http.route('/google_calendar/sync_data', type='json', auth='user') + def sync_data(self, arch, fields, model,**kw): + """ + This route/function is called when we want to synchronize openERP calendar with Google Calendar + + Function return a dictionary with the status : NeedConfigFromAdmin, NeedAuth, NeedRefresh, NoNewEventFromGoogle, SUCCESS if not crm meeting + The dictionary may contains an url, to allow OpenERP Client to redirect user on this URL for authorization for example + + """ + + if model == 'crm.meeting': + gs_obj = request.registry.get('google.service') + gc_obj = request.registry.get('google.calendar') + + # Checking that admin have already configured Google API for google synchronization ! + client_id = gs_obj.get_client_id(request.cr, request.uid,'calendar',context=kw.get('LocalContext')) + + if not client_id or client_id == '': + return { + "status" : "NeedConfigFromAdmin", + "url" : '' + } + + # Checking that user have already accepted OpenERP to access his calendar ! + if gc_obj.need_authorize(request.cr, request.uid,context=kw.get('LocalContext')): + url = gc_obj.authorize_google_uri(request.cr, request.uid, from_url=kw.get('fromurl'),context=kw.get('LocalContext')) + return { + "status" : "NeedAuth", + "url" : url + } + + # If App authorized, and user access accepted, We launch the synchronization + return gc_obj.synchronize_events(request.cr, request.uid, [], kw.get('LocalContext')) + + return { "status" : "SUCCESS" } + diff --git a/addons/google_calendar/google_calendar.py b/addons/google_calendar/google_calendar.py index 059207a562f..a0fc8f46732 100644 --- a/addons/google_calendar/google_calendar.py +++ b/addons/google_calendar/google_calendar.py @@ -678,7 +678,7 @@ class google_calendar(osv.osv): vals = {} vals['google_%s_rtoken' % self.STR_SERVICE] = all_token.get('refresh_token') - vals['google_%s_token_validity' % self.STR_SERVICE] = datetime.now() + timedelta(seconds=all_token.get('expires_in')) #NEED A CALCUL + vals['google_%s_token_validity' % self.STR_SERVICE] = datetime.now() + timedelta(seconds=all_token.get('expires_in')) vals['google_%s_token' % self.STR_SERVICE] = all_token.get('access_token') self.pool.get('res.users').write(cr,SUPERUSER_ID,uid,vals,context=context) diff --git a/addons/google_calendar/res_config.py b/addons/google_calendar/res_config.py index c86ae7824c4..a4ff58b6761 100644 --- a/addons/google_calendar/res_config.py +++ b/addons/google_calendar/res_config.py @@ -45,7 +45,7 @@ class calendar_config_settings(osv.osv_memory): cal_client_id = params.get_param(cr, uid, 'google_calendar_client_id',default='',context=context) cal_client_secret = params.get_param(cr, uid, 'google_calendar_client_secret',default='',context=context) - server_uri= "%s/googleauth/oauth2callback" % params.get_param(cr, uid, 'web.base.url',default="http://yourcompany.my.openerp.com",context=context) + server_uri= "%s/google_account/authentication" % params.get_param(cr, uid, 'web.base.url',default="http://yourcompany.my.openerp.com",context=context) return dict(cal_client_id=cal_client_id,cal_client_secret=cal_client_secret,server_uri=server_uri) diff --git a/addons/google_calendar/res_config_view.xml b/addons/google_calendar/res_config_view.xml index 41377c3ee57..7dbdf99103b 100644 --- a/addons/google_calendar/res_config_view.xml +++ b/addons/google_calendar/res_config_view.xml @@ -38,7 +38,7 @@
  • Now, you can click on "OAuth 2.0 Client ID" and see your Client ID and your Client Secret.
    You should now configure the allowed pages on which you will be redirected. To do it, you need to complete the field "Redirect RI" - and set as value (your own domain followed by "/googleauth/oauth2callback") : + and set as value (your own domain followed by "/google_account/authentication") :
    ==>

  • diff --git a/addons/google_calendar/static/src/img/setup_09.png b/addons/google_calendar/static/src/img/setup_09.png index f94c1e8c0f9..e8cb4d8084d 100644 Binary files a/addons/google_calendar/static/src/img/setup_09.png and b/addons/google_calendar/static/src/img/setup_09.png differ diff --git a/addons/google_calendar/static/src/js/calendar_sync.js b/addons/google_calendar/static/src/js/calendar_sync.js index 59f6ddef19c..dd5ae718e46 100644 --- a/addons/google_calendar/static/src/js/calendar_sync.js +++ b/addons/google_calendar/static/src/js/calendar_sync.js @@ -18,7 +18,7 @@ openerp.google_calendar = function(instance) { //$('div.oe_cal_sync_button').hide(); $('div.oe_cal_sync_button').prop('disabled',true); - self.rpc('/web_calendar_sync/sync_calendar/sync_data', { + self.rpc('/google_calendar/sync_data', { arch: res.arch, fields: res.fields, model:res.model, diff --git a/addons/google_drive/__openerp__.py b/addons/google_drive/__openerp__.py index 9e6c73d2649..8f135c5f9d1 100644 --- a/addons/google_drive/__openerp__.py +++ b/addons/google_drive/__openerp__.py @@ -39,7 +39,7 @@ 'demo': [ 'google_drive_demo.xml' ], - 'depends': ['base_setup', 'google_base_account'], + 'depends': ['base_setup', 'google_account'], 'description': """ Integrate google document to OpenERP record. ============================================