[FIX&DEL]google_*: remove of now useless views and code from google_base_account, and move generic function from google_docs to google_base_account
bzr revid: dle@openerp.com-20130625161922-3u1m5qeqcj84rmq5
This commit is contained in:
parent
0bca00c42c
commit
3afc97f451
|
@ -20,7 +20,6 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import google_base_account
|
import google_base_account
|
||||||
import wizard
|
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
||||||
|
|
|
@ -32,8 +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_view.xml',
|
'google_base_account_data.xml',
|
||||||
'wizard/google_login_view.xml',
|
|
||||||
],
|
],
|
||||||
'demo': [],
|
'demo': [],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import fields, osv
|
from openerp.osv import osv
|
||||||
from openerp import SUPERUSER_ID
|
from openerp import SUPERUSER_ID
|
||||||
|
|
||||||
from httplib2 import Http
|
from httplib2 import Http
|
||||||
|
@ -27,14 +27,6 @@ import urllib
|
||||||
import simplejson
|
import simplejson
|
||||||
|
|
||||||
|
|
||||||
class res_users(osv.osv):
|
|
||||||
_inherit = "res.users"
|
|
||||||
_columns = {
|
|
||||||
'gmail_user': fields.char('Username', size=64,),
|
|
||||||
'gmail_password': fields.char('Password', size=64),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class base_config_settings(osv.osv):
|
class base_config_settings(osv.osv):
|
||||||
_inherit = "base.config.settings"
|
_inherit = "base.config.settings"
|
||||||
|
|
||||||
|
@ -56,13 +48,16 @@ class base_config_settings(osv.osv):
|
||||||
ir_config.set_param(cr, uid, 'google_%s_refresh_token' % service, content['refresh_token'])
|
ir_config.set_param(cr, uid, 'google_%s_refresh_token' % service, content['refresh_token'])
|
||||||
return res
|
return res
|
||||||
|
|
||||||
# def get_default_google_authorization_code(self, cr, uid, ids, service, context=None):
|
def _get_google_token_uri(self, cr, uid, service, context=None):
|
||||||
# authorization_code = self.pool.get("ir.config_parameter").get_param(cr, uid, "google_%s_authorization_code" % service, context=context)
|
ir_config = self.pool['ir.config_parameter']
|
||||||
# return {'authorization_code': authorization_code}
|
params = {
|
||||||
|
'scope': 'https://www.googleapis.com/auth/drive',
|
||||||
# def set_google_authorization_code(self, cr, uid, ids, service, context=None):
|
'redirect_uri': ir_config.get_param(cr, SUPERUSER_ID, 'google_redirect_uri'),
|
||||||
# config_parameters = self.pool.get("ir.config_parameter")
|
'client_id': ir_config.get_param(cr, SUPERUSER_ID, 'google_%s_client_id' % service),
|
||||||
# for record in self.read(cr, uid, ids, ['google_%s_authorization_code' % service], context=context):
|
'response_type': 'code',
|
||||||
# config_parameters.set_param(cr, uid, "google_%s_authorization_code" % service, record['google_%s_authorization_code' % service] or '', context=context)
|
'client_id': ir_config.get_param(cr, SUPERUSER_ID, 'google_%s_client_id' % service),
|
||||||
|
}
|
||||||
|
uri = 'https://accounts.google.com/o/oauth2/auth?%s' % urllib.urlencode(params)
|
||||||
|
return uri
|
||||||
|
|
||||||
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -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,33 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<openerp>
|
|
||||||
<data>
|
|
||||||
<record id="view_users_google_form" model="ir.ui.view">
|
|
||||||
<field name="name">res.users.google.form1</field>
|
|
||||||
<field name="model">res.users</field>
|
|
||||||
<field name="inherit_id" ref="base.view_users_form"/>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<xpath expr="//notebook" position="inside">
|
|
||||||
<page string="Google Account">
|
|
||||||
<group string="Google Account" colspan="4">
|
|
||||||
<field name="gmail_user"/>
|
|
||||||
<field name="gmail_password" password="True"/>
|
|
||||||
</group>
|
|
||||||
</page>
|
|
||||||
</xpath>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
<record id="view_users_google_preference" model="ir.ui.view">
|
|
||||||
<field name="name">res.users.google.form2</field>
|
|
||||||
<field name="model">res.users</field>
|
|
||||||
<field name="inherit_id" ref="base.view_users_form_simple_modif"/>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<xpath expr="//group[@name='preferences']" position="after">
|
|
||||||
<group string="Google Account" colspan="4">
|
|
||||||
<field name="gmail_user" readonly="0"/>
|
|
||||||
<field name="gmail_password" password="True" readonly="0"/>
|
|
||||||
</group>
|
|
||||||
</xpath>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
</data>
|
|
||||||
</openerp>
|
|
|
@ -1,25 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# OpenERP, Open Source Management Solution
|
|
||||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
import google_login
|
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# OpenERP, Open Source Management Solution
|
|
||||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
from openerp.osv import fields,osv
|
|
||||||
from openerp.tools.translate import _
|
|
||||||
try:
|
|
||||||
import gdata.contacts.service
|
|
||||||
import gdata.contacts.client
|
|
||||||
import gdata.calendar.service
|
|
||||||
except ImportError:
|
|
||||||
raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
|
||||||
|
|
||||||
class google_login(osv.osv_memory):
|
|
||||||
_description ='Google Contact'
|
|
||||||
_name = 'google.login'
|
|
||||||
_columns = {
|
|
||||||
'user': fields.char('Google Username', size=64, required=True),
|
|
||||||
'password': fields.char('Google Password', size=64),
|
|
||||||
}
|
|
||||||
|
|
||||||
def google_login(self, user, password, type='', context=None):
|
|
||||||
if type == 'group':
|
|
||||||
gd_client = gdata.contacts.service.ContactsService()
|
|
||||||
elif type == 'contact':
|
|
||||||
gd_client = gdata.contacts.service.ContactsService()
|
|
||||||
elif type == 'calendar':
|
|
||||||
gd_client = gdata.calendar.service.CalendarService()
|
|
||||||
elif type =='docs_client':
|
|
||||||
gd_client = gdata.docs.client.DocsClient()
|
|
||||||
else:
|
|
||||||
gd_client = gdata.contacts.service.ContactsService()
|
|
||||||
try:
|
|
||||||
gd_client.ClientLogin(user, password, gd_client.source)
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
return gd_client
|
|
||||||
|
|
||||||
|
|
||||||
def default_get(self, cr, uid, fields, context=None):
|
|
||||||
res = super(google_login, self).default_get(cr, uid, fields, context=context)
|
|
||||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
|
||||||
if 'user' in fields:
|
|
||||||
res.update({'user': user_obj.gmail_user})
|
|
||||||
if 'password' in fields:
|
|
||||||
res.update({'password': user_obj.gmail_password})
|
|
||||||
return res
|
|
||||||
|
|
||||||
def login(self, cr, uid, ids, context=None):
|
|
||||||
data = self.read(cr, uid, ids)[0]
|
|
||||||
user = data['user']
|
|
||||||
password = data['password']
|
|
||||||
if self.google_login(user, password):
|
|
||||||
res = {
|
|
||||||
'gmail_user': user,
|
|
||||||
'gmail_password': password
|
|
||||||
}
|
|
||||||
self.pool.get('res.users').write(cr, uid, uid, res, context=context)
|
|
||||||
else:
|
|
||||||
raise osv.except_osv(_('Error!'), _("Authentication failed. Check the user and password."))
|
|
||||||
|
|
||||||
return self._get_next_action(cr, uid, context=context)
|
|
||||||
|
|
||||||
def _get_next_action(self, cr, uid, context=None):
|
|
||||||
return {'type': 'ir.actions.act_window_close'}
|
|
||||||
|
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<openerp>
|
|
||||||
<data>
|
|
||||||
<record model="ir.ui.view" id="view_google_login_form">
|
|
||||||
<field name="name">google.login.form</field>
|
|
||||||
<field name="model">google.login</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<form string="Google login" version="7.0">
|
|
||||||
<group>
|
|
||||||
<field name="user" placeholder="e.g. user@gmail.com"/>
|
|
||||||
<field name="password" password="True"/>
|
|
||||||
</group>
|
|
||||||
<footer>
|
|
||||||
<button name="login" string="_Login" type="object" class="oe_highlight"/>
|
|
||||||
or
|
|
||||||
<button string="Cancel" class="oe_link" special="cancel" />
|
|
||||||
</footer>
|
|
||||||
</form>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Login Action
|
|
||||||
-->
|
|
||||||
<record model="ir.actions.act_window" id="act_google_login_form">
|
|
||||||
<field name="name">Google Login</field>
|
|
||||||
<field name="type">ir.actions.act_window</field>
|
|
||||||
<field name="res_model">google.login</field>
|
|
||||||
<field name="view_type">form</field>
|
|
||||||
<field name="view_mode">form</field>
|
|
||||||
<field name="target">new</field>
|
|
||||||
<field name="view_id" ref="view_google_login_form" />
|
|
||||||
</record>
|
|
||||||
</data>
|
|
||||||
</openerp>
|
|
|
@ -215,4 +215,8 @@ class base_config_settings(osv.osv):
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'google_docs_authorization_code': fields.char('Paste Generated "Authorization Code" from google to here', size=124),
|
'google_docs_authorization_code': fields.char('Paste Generated "Authorization Code" from google to here', size=124),
|
||||||
|
'google_docs_uri': fields.char('URI', readonly=True, help="The URL to generate the authorization code from Google"),
|
||||||
|
}
|
||||||
|
_defaults = {
|
||||||
|
'google_docs_uri': lambda s, cr, uid, c: s._get_google_token_uri(cr, uid, 'docs', context=c),
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,8 +76,9 @@
|
||||||
<xpath expr="//div[@name='google_docs']" position="after">
|
<xpath expr="//div[@name='google_docs']" position="after">
|
||||||
<div attrs="{'invisible': [('module_google_docs','=',False)]}">
|
<div attrs="{'invisible': [('module_google_docs','=',False)]}">
|
||||||
<p class="oe_gray" >
|
<p class="oe_gray" >
|
||||||
<!-- Need to generate client id, redirect url from Google Account (API console) and replace below link. Limitation on Number of request: 10 lacks per day. -->
|
<div class="oe_inline">
|
||||||
Click here to <a href="https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=39623646228-eg3ggo3mk6o40m7rguobi3rkl9frh4tb.apps.googleusercontent.com" target="_blank"><b>Generate Google Authorization Code</b></a><br/>
|
Click here to <field name="google_docs_uri" widget="url" text="Generate Google Authorization Code" class="oe_inline oe_bold"/>
|
||||||
|
</div>
|
||||||
<group>
|
<group>
|
||||||
<field name="google_docs_authorization_code" on_change="onchange_google_authorization_code('docs', google_docs_authorization_code)"/>''
|
<field name="google_docs_authorization_code" on_change="onchange_google_authorization_code('docs', google_docs_authorization_code)"/>''
|
||||||
</group>
|
</group>
|
||||||
|
|
Loading…
Reference in New Issue