[FIX] Fixed settings view, and added some functionality to oauth related fields.

bzr revid: vta@openerp.com-20120817132835-l5ne76q7t8lj73yc
This commit is contained in:
vta vta@openerp.com 2012-08-17 15:28:35 +02:00
parent b441abb3a9
commit 200a0fd5dd
8 changed files with 120 additions and 61 deletions

View File

@ -34,7 +34,7 @@
],
'update_xml': [
'auth_oauth_view.xml',
'res_config_view.xml',
'res_config.xml',
],
'js': [
'static/src/js/auth_oauth.js',

View File

@ -1,6 +1,6 @@
from openerp.osv import osv, fields
class auth_oauth_providers(osv.osv):
class auth_oauth_provider(osv.osv):
"""Class defining the configuration values of an OAuth2 provider"""
_name = 'auth.oauth.provider'
@ -8,15 +8,18 @@ class auth_oauth_providers(osv.osv):
_order = 'name'
_columns = {
'name' : fields.char('Provider name', required=True), # Name of the OAuth2 entity, Google, LinkedIn, etc
'client_id' : fields.char('Client ID', required=True), # Our identifier
'auth_endpoint' : fields.char('Authentication URL', required=True), # OAuth provider URL to authenticate users
'name' : fields.char('Provider name'), # Name of the OAuth2 entity, Google, LinkedIn, etc
'client_id' : fields.char('Client ID'), # Our identifier
'auth_endpoint' : fields.char('Authentication URL'), # OAuth provider URL to authenticate users
'scope' : fields.char('Scope'), # OAUth user data desired to access
'validation_endpoint' : fields.char('Validation URL'), # OAuth provider URL to validate tokens
'data_endpoint' : fields.char('Data URL'),
'enabled' : fields.boolean('Allowed'),
'css_class' : fields.char('CSS class'),
'body' : fields.char('Body'),
'active' : fields.boolean('Active'),
'sequence' : fields.integer(),
}
_defaults = {
'enabled' : False,
}

View File

@ -1,38 +1,34 @@
<?xml version="1.0"?>
<openerp>
<data noupdate="1">
<data>
<record id="provider_facebook" model="auth.oauth.provider">
<field name="name">Facebook Graph</field>
<field name="client_id">facebook_client_id</field>
<field name="auth_endpoint">https://www.facebook.com/dialog/oauth</field>
<field name="scope"></field>
<field name="validation_endpoint">https://graph.facebook.com/me/permissions</field>
<field name="data_endpoint"></field>
<field name="css_class">zocial facebook</field>
<field name="body">Sign in with facebook</field>
<field name="active">True</field>
</record>
<record id="provider_google" model="auth.oauth.provider">
<field name="name">Google OAuth2</field>
<field name="client_id">108010644258-duuhmp6pu7li4tsmnqg7j9rvdeklg0ki.apps.googleusercontent.com</field>
<field name="auth_endpoint">https://accounts.google.com/o/oauth2/auth</field>
<field name="scope">https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile</field>
<field name="validation_endpoint">https://www.googleapis.com/oauth2/v1/tokeninfo</field>
<field name="data_endpoint">https://www.googleapis.com/oauth2/v1/userinfo</field>
<field name="css_class">zocial google</field>
<field name="body">Sign in with google</field>
<field name="active">True</field>
</record>
<record id="provider_twitter" model="auth.oauth.provider">
<field name="name">Twitter OAuth2</field>
<field name="client_id">108010644258-duuhmp6pu7li4tsmnqg7j9rvdeklg0ki.apps.twitterusercontent.com</field>
<!-- <record id="provider_twitter" model="auth.oauth.provider">
<field name="name">Twitter OAuth</field>
<field name="auth_endpoint">https://api.twitter.com/oauth/request_token</field>
<field name="scope"></field>
<field name="validation_endpoint">https://api.twitter.com/oauth/authorize</field>
<field name="data_endpoint"></field>
<field name="css_class">zocial twitter</field>
<field name="body">Sign in with twitter</field>
<field name="active">True</field>
</record>
</record> -->
</data>
</openerp>

View File

@ -11,7 +11,7 @@
<group>
<field name="name" />
<field name="client_id" />
<field name="active" />
<field name="enabled" />
</group>
<group>
<field name="auth_endpoint" />
@ -22,8 +22,7 @@
</sheet>
</form>
</field>
</record>
</record>
<record model="ir.ui.view" id="view_oauth_provider_list">
<field name="name">auth.oauth.provider.list</field>
<field name="model">auth.oauth.provider</field>
@ -32,7 +31,7 @@
<tree string="arch" version="7.0">
<field name="name" />
<field name="client_id" />
<field name="active" />
<field name="enabled" />
</tree>
</field>
</record>

View File

@ -18,7 +18,7 @@ class OAuthController(openerpweb.Controller):
registry = openerp.modules.registry.RegistryManager.get(dbname)
with registry.cursor() as cr:
providers = registry.get('auth.oauth.provider')
l = providers.read(cr, 1, providers.search(cr, 1, []))
l = providers.read(cr, 1, providers.search(cr, 1, [('enabled','=',True)]))
return l
@openerpweb.httprequest

View File

@ -21,19 +21,58 @@
from openerp.osv import osv, fields
class project_configuration(osv.TransientModel):
import logging
_logger = logging.getLogger(__name__)
class base_config_settings(osv.TransientModel):
_inherit = 'base.config.settings'
_columns = {
'auth_oauth_google_active' : fields.boolean('enable sign in with google'),
'auth_oauth_google_client_id' : fields.char('Google client_id'),
'auth_oauth_facebook_client_id' : fields.char('Facebook client_id'),
'auth_oauth_google_enabled' : fields.boolean('Allow users to login with Google'),
'auth_oauth_google_client_id' : fields.char('Client ID'),
'auth_oauth_facebook_enabled' : fields.boolean('Allow users to login with Facebook'),
'auth_oauth_facebook_client_id' : fields.char('Client ID'),
}
# def get_default_alias_domain(self, cr, uid, ids, context=None):
# return {'alias_domain': self.pool.get("ir.config_parameter").get_param(cr, uid, "mail.catchall.domain", context=context)}
def get_default_allow(self, cr, uid, fields, context=None):
google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1]
rg = self.pool.get('auth.oauth.provider').read(cr, uid, [google_id], ['enabled'], context=context)
facebook_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_facebook')[1]
rf = self.pool.get('auth.oauth.provider').read(cr, uid, [facebook_id], ['enabled'], context=context)
return {
'auth_oauth_google_enabled': rg[0]['enabled'],
'auth_oauth_facebook_enabled': rf[0]['enabled']
}
# def set_alias_domain(self, cr, uid, ids, context=None):
# config_parameters = self.pool.get("ir.config_parameter")
# for record in self.browse(cr, uid, ids, context=context):
# config_parameters.set_param(cr, uid, "mail.catchall.domain", record.alias_domain or '', context=context)
def set_allow(self, cr, uid, ids, context=None):
google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1]
facebook_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_facebook')[1]
config = self.browse(cr, uid, ids[0], context=context)
self.pool.get('auth.oauth.provider').write(cr, uid, [google_id], {'enabled':config.auth_oauth_google_enabled})
self.pool.get('auth.oauth.provider').write(cr, uid, [facebook_id], {'enabled':config.auth_oauth_facebook_enabled})
# def get_default_client_ids(self, cr, uid, fields, context=None):
# google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1]
# facebook_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_facebook')[1]
# return {
# 'auth_oauth_google_client_id': icp.get_param(cr, uid, 'auth.auth_oauth_google_client_id', "Set by the user") or False
# }
# def set_client_ids(self, cr, uid, ids, context=None):
# provider_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_goole')
# config = self.browse(cr, uid, ids[0], context=context)
# icp = self.pool.get('ir.config_parameter')
# icp.set_param(cr, uid, 'auth.google_client_id', config.google_client_id)
# def get_default_facebook_client_id(self, cr, uid, fields, context=None):
# icp = self.pool.get('ir.config_parameter')
# return {
# 'facebook_client_id': icp.get_param(cr, uid, 'auth.facebook_client_id', "Set by the user") or False
# }
# def set_facebook_client_id(self, cr, uid, ids, context=None):
# config = self.browse(cr, uid, ids[0], context=context)
# icp = self.pool.get('ir.config_parameter')
# icp.set_param(cr, uid, 'auth.facebook_client_id', config.facebook_client_id)

View File

@ -0,0 +1,52 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_general_configuration">
<field name="name">base.config.settings.oauth</field>
<field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='module_auth_oauth']/.." position="after">
<div attrs="{'invisible':[('module_auth_oauth','=',False)]}">
<div name="google">
<div>
<field name="auth_oauth_google_enabled" class="oe_inline"/>
<label for="auth_oauth_google_enabled"/>
</div>
<div attrs="{'invisible':[('auth_oauth_google_enabled','=',False)]}">
<div>
<p>To setup the signin process with Google, first you have to perform the following steps:</p>
<br/>
1. Register your application through the Google's APIs console. The result of this registration is a set of values that are known to both Google and you application: 'client_id' and 'redirect_uri'.
<br/>
2. Fill the following field with the values assigned by Google.
</div>
<div>
<label for="auth_oauth_google_client_id" placeholder="Your CLIENT_ID"/>
<field name="auth_oauth_google_client_id" class="oe_inline"/>
</div>
</div>
</div>
<div name="facebook">
<div>
<field name="auth_oauth_facebook_enabled" class="oe_inline"/>
<label for="auth_oauth_facebook_enabled"/>
</div>
<div attrs="{'invisible':[('auth_oauth_facebook_enabled','=',False)]}">
<div>
<label string="Here goes the explanation"/>
</div>
<div>
<label for="auth_oauth_facebook_client_id" placeholder="Your CLIENT_ID"/>
<field name="auth_oauth_facebook_client_id" class="oe_inline"/>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@ -1,30 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_general_configuration_auth_oauth" model="ir.ui.view">
<field name="name">base.config.auth.oauth</field>
<field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
<field name="arch" type="xml">
<xpath expr="//label[@for='module_auth_oauth']" position="after">
<div>
<field name="auth_oauth_google_active" class="oe_inline"/>
<label for="auth_oauth_google_active"/>
</div>
<div>
<p attrs="{'invisible': [('auth_oauth_google_active','=',False)]}">
Explanation goes here OpenERP allows to
automatically create leads (or others documents)
from incoming emails. You can automatically
synchronize emails with OpenERP using regular
POP/IMAP accounts, using a direct email integration
script for your email server, or by manually
pushing emails to OpenERP using specific
plugins for your preferred email application.
</p>
</div>
</xpath>
</field>
</record>
</data>
</openerp>