[TYPO] Rename google_base_account into google_account
bzr revid: jke@openerp.com-20131219142514-8epaqnt0mb16xd4n
This commit is contained in:
parent
3e5bb533dd
commit
3d04737ab1
|
@ -18,7 +18,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
import google_base_account
|
import google_account
|
||||||
import controllers
|
import controllers
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -32,7 +32,7 @@ The module adds google user in res user.
|
||||||
'website': 'http://www.openerp.com',
|
'website': 'http://www.openerp.com',
|
||||||
'depends': ['base_setup'],
|
'depends': ['base_setup'],
|
||||||
'data': [
|
'data': [
|
||||||
'google_base_account_data.xml',
|
'google_account_data.xml',
|
||||||
],
|
],
|
||||||
'demo': [],
|
'demo': [],
|
||||||
'installable': True,
|
'installable': True,
|
|
@ -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"))
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,8 @@ class google_service(osv.osv_memory):
|
||||||
'client_id': client_id,
|
'client_id': client_id,
|
||||||
'state' : simplejson.dumps(state_obj),
|
'state' : simplejson.dumps(state_obj),
|
||||||
'scope': scope or 'https://www.googleapis.com/auth/%s' % (service,),
|
'scope': scope or 'https://www.googleapis.com/auth/%s' % (service,),
|
||||||
'redirect_uri': base_url + '/googleauth/oauth2callback',
|
'redirect_uri': base_url + '/google_account/authentication',
|
||||||
'approval_prompt':'force',
|
#'approval_prompt':'force',
|
||||||
'access_type':'offline'
|
'access_type':'offline'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ class google_service(osv.osv_memory):
|
||||||
'client_id': client_id,
|
'client_id': client_id,
|
||||||
'client_secret': client_secret,
|
'client_secret': client_secret,
|
||||||
'grant_type' : 'authorization_code',
|
'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"}
|
headers = {"content-type": "application/x-www-form-urlencoded"}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<openerp>
|
||||||
|
<data noupdate="1">
|
||||||
|
<record id="config_google_redirect_uri" model="ir.config_parameter">
|
||||||
|
<field name="key">google_redirect_uri</field>
|
||||||
|
<field name="value">urn:ietf:wg:oauth:2.0:oob</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</openerp>
|
|
@ -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
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
import res_config
|
import res_config
|
||||||
import google_calendar
|
import google_calendar
|
||||||
|
import controllers
|
||||||
|
|
|
@ -30,7 +30,7 @@ The module adds the possibility to synchronize Google Calendar with OpenERP
|
||||||
""",
|
""",
|
||||||
'author': 'OpenERP SA',
|
'author': 'OpenERP SA',
|
||||||
'website': 'http://www.openerp.com',
|
'website': 'http://www.openerp.com',
|
||||||
'depends': ['google_base_account','base_calendar'],
|
'depends': ['google_account','base_calendar'],
|
||||||
'css': ['static/src/css/*.css'],
|
'css': ['static/src/css/*.css'],
|
||||||
'js': ['static/src/js/*.js'],
|
'js': ['static/src/js/*.js'],
|
||||||
'qweb': ['static/src/xml/*.xml'],
|
'qweb': ['static/src/xml/*.xml'],
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
import main
|
|
@ -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" }
|
||||||
|
|
|
@ -678,7 +678,7 @@ class google_calendar(osv.osv):
|
||||||
|
|
||||||
vals = {}
|
vals = {}
|
||||||
vals['google_%s_rtoken' % self.STR_SERVICE] = all_token.get('refresh_token')
|
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')
|
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)
|
self.pool.get('res.users').write(cr,SUPERUSER_ID,uid,vals,context=context)
|
||||||
|
|
||||||
|
|
|
@ -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_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)
|
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)
|
return dict(cal_client_id=cal_client_id,cal_client_secret=cal_client_secret,server_uri=server_uri)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
<li>
|
<li>
|
||||||
Now, you can click on <b>"OAuth 2.0 Client ID"</b> and see your <u><i>Client ID</i></u> and your <u><i>Client Secret</i></u>.
|
Now, you can click on <b>"OAuth 2.0 Client ID"</b> and see your <u><i>Client ID</i></u> and your <u><i>Client Secret</i></u>.
|
||||||
<br/> You should now configure the allowed pages on which you will be redirected. To do it, you need to complete the field <b>"Redirect RI"</b>
|
<br/> You should now configure the allowed pages on which you will be redirected. To do it, you need to complete the field <b>"Redirect RI"</b>
|
||||||
and set as value (your own domain followed by <i>"/googleauth/oauth2callback"</i>) :
|
and set as value (your own domain followed by <i>"/google_account/authentication"</i>) :
|
||||||
<br/>==> <b><field name="server_uri" readonly="1" style='display:inline'/></b>
|
<br/>==> <b><field name="server_uri" readonly="1" style='display:inline'/></b>
|
||||||
<br/><br/><img src='/google_calendar/static/src/img/setup_09.png' class='calendar_img_tuto'/>
|
<br/><br/><img src='/google_calendar/static/src/img/setup_09.png' class='calendar_img_tuto'/>
|
||||||
</li>
|
</li>
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 17 KiB |
|
@ -18,7 +18,7 @@ openerp.google_calendar = function(instance) {
|
||||||
//$('div.oe_cal_sync_button').hide();
|
//$('div.oe_cal_sync_button').hide();
|
||||||
$('div.oe_cal_sync_button').prop('disabled',true);
|
$('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,
|
arch: res.arch,
|
||||||
fields: res.fields,
|
fields: res.fields,
|
||||||
model:res.model,
|
model:res.model,
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
'demo': [
|
'demo': [
|
||||||
'google_drive_demo.xml'
|
'google_drive_demo.xml'
|
||||||
],
|
],
|
||||||
'depends': ['base_setup', 'google_base_account'],
|
'depends': ['base_setup', 'google_account'],
|
||||||
'description': """
|
'description': """
|
||||||
Integrate google document to OpenERP record.
|
Integrate google document to OpenERP record.
|
||||||
============================================
|
============================================
|
||||||
|
|
Loading…
Reference in New Issue