From 200a0fd5dd8dc03d17aaedb8ba61def2c629bd06 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Fri, 17 Aug 2012 15:28:35 +0200 Subject: [PATCH] [FIX] Fixed settings view, and added some functionality to oauth related fields. bzr revid: vta@openerp.com-20120817132835-l5ne76q7t8lj73yc --- addons/auth_oauth/__openerp__.py | 2 +- addons/auth_oauth/auth_oauth.py | 13 +++--- addons/auth_oauth/auth_oauth_data.xml | 16 +++----- addons/auth_oauth/auth_oauth_view.xml | 7 ++-- addons/auth_oauth/controllers/main.py | 2 +- addons/auth_oauth/res_config.py | 59 ++++++++++++++++++++++----- addons/auth_oauth/res_config.xml | 52 +++++++++++++++++++++++ addons/auth_oauth/res_config_view.xml | 30 -------------- 8 files changed, 120 insertions(+), 61 deletions(-) create mode 100644 addons/auth_oauth/res_config.xml delete mode 100644 addons/auth_oauth/res_config_view.xml diff --git a/addons/auth_oauth/__openerp__.py b/addons/auth_oauth/__openerp__.py index c8d9c85c265..585dc48e11e 100644 --- a/addons/auth_oauth/__openerp__.py +++ b/addons/auth_oauth/__openerp__.py @@ -34,7 +34,7 @@ ], 'update_xml': [ 'auth_oauth_view.xml', - 'res_config_view.xml', + 'res_config.xml', ], 'js': [ 'static/src/js/auth_oauth.js', diff --git a/addons/auth_oauth/auth_oauth.py b/addons/auth_oauth/auth_oauth.py index e258505868d..8a7ba4e6e4d 100644 --- a/addons/auth_oauth/auth_oauth.py +++ b/addons/auth_oauth/auth_oauth.py @@ -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, + } diff --git a/addons/auth_oauth/auth_oauth_data.xml b/addons/auth_oauth/auth_oauth_data.xml index 021a03b2742..7bb95192e5d 100644 --- a/addons/auth_oauth/auth_oauth_data.xml +++ b/addons/auth_oauth/auth_oauth_data.xml @@ -1,38 +1,34 @@ - + + Facebook Graph - facebook_client_id https://www.facebook.com/dialog/oauth https://graph.facebook.com/me/permissions zocial facebook Sign in with facebook - True Google OAuth2 - 108010644258-duuhmp6pu7li4tsmnqg7j9rvdeklg0ki.apps.googleusercontent.com https://accounts.google.com/o/oauth2/auth https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/oauth2/v1/tokeninfo https://www.googleapis.com/oauth2/v1/userinfo zocial google Sign in with google - True - - Twitter OAuth2 - 108010644258-duuhmp6pu7li4tsmnqg7j9rvdeklg0ki.apps.twitterusercontent.com + + diff --git a/addons/auth_oauth/auth_oauth_view.xml b/addons/auth_oauth/auth_oauth_view.xml index 23e05e7a31f..475720af9fd 100644 --- a/addons/auth_oauth/auth_oauth_view.xml +++ b/addons/auth_oauth/auth_oauth_view.xml @@ -11,7 +11,7 @@ - + @@ -22,8 +22,7 @@ - - + auth.oauth.provider.list auth.oauth.provider @@ -32,7 +31,7 @@ - + diff --git a/addons/auth_oauth/controllers/main.py b/addons/auth_oauth/controllers/main.py index 28f550b4bda..2959fa45db1 100644 --- a/addons/auth_oauth/controllers/main.py +++ b/addons/auth_oauth/controllers/main.py @@ -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 diff --git a/addons/auth_oauth/res_config.py b/addons/auth_oauth/res_config.py index 4a218d98165..52d82b71895 100644 --- a/addons/auth_oauth/res_config.py +++ b/addons/auth_oauth/res_config.py @@ -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) \ No newline at end of file diff --git a/addons/auth_oauth/res_config.xml b/addons/auth_oauth/res_config.xml new file mode 100644 index 00000000000..78c5e26d983 --- /dev/null +++ b/addons/auth_oauth/res_config.xml @@ -0,0 +1,52 @@ + + + + + + base.config.settings.oauth + base.config.settings + + + +
+
+
+ +
+
+
+

To setup the signin process with Google, first you have to perform the following steps:

+
+ 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'. +
+ 2. Fill the following field with the values assigned by Google. +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
\ No newline at end of file diff --git a/addons/auth_oauth/res_config_view.xml b/addons/auth_oauth/res_config_view.xml deleted file mode 100644 index 5744dfaa8a2..00000000000 --- a/addons/auth_oauth/res_config_view.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - base.config.auth.oauth - base.config.settings - - - -
- -
-
-

- 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. -

-
-
-
-
-
-