From 914b2be9678e747b585839449de04f86464941d4 Mon Sep 17 00:00:00 2001 From: Kinjal Mehta Date: Tue, 11 Aug 2015 16:27:27 +0530 Subject: [PATCH 1/2] [MOVE]auth_oauth: Moved files in related models and views directory. --- addons/auth_oauth/__init__.py | 7 +++---- addons/auth_oauth/__openerp__.py | 14 +++++++------- addons/auth_oauth/{ => data}/auth_oauth_data.xml | 0 addons/auth_oauth/{ => data}/auth_oauth_data.yml | 0 addons/auth_oauth/models/__init__.py | 6 ++++++ addons/auth_oauth/{ => models}/auth_oauth.py | 0 .../ir_config_parameter.py} | 0 addons/auth_oauth/{ => models}/res_config.py | 0 addons/auth_oauth/{ => models}/res_users.py | 0 ...th_oauth_login.xml => auth_oauth_templates.xml} | 0 .../auth_oauth_views.xml} | 0 .../{res_config.xml => views/res_config_views.xml} | 0 .../{res_users.xml => views/res_users_views.xml} | 0 13 files changed, 16 insertions(+), 11 deletions(-) rename addons/auth_oauth/{ => data}/auth_oauth_data.xml (100%) rename addons/auth_oauth/{ => data}/auth_oauth_data.yml (100%) create mode 100644 addons/auth_oauth/models/__init__.py rename addons/auth_oauth/{ => models}/auth_oauth.py (100%) rename addons/auth_oauth/{ir_configparameter.py => models/ir_config_parameter.py} (100%) rename addons/auth_oauth/{ => models}/res_config.py (100%) rename addons/auth_oauth/{ => models}/res_users.py (100%) rename addons/auth_oauth/views/{auth_oauth_login.xml => auth_oauth_templates.xml} (100%) rename addons/auth_oauth/{auth_oauth_view.xml => views/auth_oauth_views.xml} (100%) rename addons/auth_oauth/{res_config.xml => views/res_config_views.xml} (100%) rename addons/auth_oauth/{res_users.xml => views/res_users_views.xml} (100%) diff --git a/addons/auth_oauth/__init__.py b/addons/auth_oauth/__init__.py index 08c1dd3d6b5..bde83af3aea 100644 --- a/addons/auth_oauth/__init__.py +++ b/addons/auth_oauth/__init__.py @@ -1,5 +1,4 @@ +# -*- coding: utf-8 -*- + import controllers -import auth_oauth -import res_users -import res_config -import ir_configparameter +import models diff --git a/addons/auth_oauth/__openerp__.py b/addons/auth_oauth/__openerp__.py index 348f9228bf4..46935531d4d 100644 --- a/addons/auth_oauth/__openerp__.py +++ b/addons/auth_oauth/__openerp__.py @@ -10,16 +10,16 @@ Allow users to login through OAuth2 Provider. ============================================= """, - 'maintainer': 'OpenERP s.a.', + 'maintainer': 'Odoo s.a.', 'depends': ['base', 'web', 'base_setup', 'auth_signup'], 'data': [ - 'res_users.xml', - 'auth_oauth_data.xml', - 'auth_oauth_data.yml', - 'auth_oauth_view.xml', + 'data/auth_oauth_data.xml', + 'data/auth_oauth_data.yml', + 'views/auth_oauth_views.xml', + 'views/res_users_views.xml', + 'views/res_config_views.xml', + 'views/auth_oauth_templates.xml', 'security/ir.model.access.csv', - 'res_config.xml', - 'views/auth_oauth_login.xml', ], 'installable': True, 'auto_install': False, diff --git a/addons/auth_oauth/auth_oauth_data.xml b/addons/auth_oauth/data/auth_oauth_data.xml similarity index 100% rename from addons/auth_oauth/auth_oauth_data.xml rename to addons/auth_oauth/data/auth_oauth_data.xml diff --git a/addons/auth_oauth/auth_oauth_data.yml b/addons/auth_oauth/data/auth_oauth_data.yml similarity index 100% rename from addons/auth_oauth/auth_oauth_data.yml rename to addons/auth_oauth/data/auth_oauth_data.yml diff --git a/addons/auth_oauth/models/__init__.py b/addons/auth_oauth/models/__init__.py new file mode 100644 index 00000000000..86eac414dfa --- /dev/null +++ b/addons/auth_oauth/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + +import auth_oauth +import ir_config_parameter +import res_config +import res_users diff --git a/addons/auth_oauth/auth_oauth.py b/addons/auth_oauth/models/auth_oauth.py similarity index 100% rename from addons/auth_oauth/auth_oauth.py rename to addons/auth_oauth/models/auth_oauth.py diff --git a/addons/auth_oauth/ir_configparameter.py b/addons/auth_oauth/models/ir_config_parameter.py similarity index 100% rename from addons/auth_oauth/ir_configparameter.py rename to addons/auth_oauth/models/ir_config_parameter.py diff --git a/addons/auth_oauth/res_config.py b/addons/auth_oauth/models/res_config.py similarity index 100% rename from addons/auth_oauth/res_config.py rename to addons/auth_oauth/models/res_config.py diff --git a/addons/auth_oauth/res_users.py b/addons/auth_oauth/models/res_users.py similarity index 100% rename from addons/auth_oauth/res_users.py rename to addons/auth_oauth/models/res_users.py diff --git a/addons/auth_oauth/views/auth_oauth_login.xml b/addons/auth_oauth/views/auth_oauth_templates.xml similarity index 100% rename from addons/auth_oauth/views/auth_oauth_login.xml rename to addons/auth_oauth/views/auth_oauth_templates.xml diff --git a/addons/auth_oauth/auth_oauth_view.xml b/addons/auth_oauth/views/auth_oauth_views.xml similarity index 100% rename from addons/auth_oauth/auth_oauth_view.xml rename to addons/auth_oauth/views/auth_oauth_views.xml diff --git a/addons/auth_oauth/res_config.xml b/addons/auth_oauth/views/res_config_views.xml similarity index 100% rename from addons/auth_oauth/res_config.xml rename to addons/auth_oauth/views/res_config_views.xml diff --git a/addons/auth_oauth/res_users.xml b/addons/auth_oauth/views/res_users_views.xml similarity index 100% rename from addons/auth_oauth/res_users.xml rename to addons/auth_oauth/views/res_users_views.xml From 3f201066f0f360eaf84ee02b661ad9994758f304 Mon Sep 17 00:00:00 2001 From: Kinjal Mehta Date: Tue, 11 Aug 2015 19:08:28 +0530 Subject: [PATCH 2/2] [MIG]auth_oauth: Migrate to new api. --- addons/auth_oauth/__init__.py | 1 + addons/auth_oauth/__openerp__.py | 8 +- addons/auth_oauth/controllers/__init__.py | 3 + addons/auth_oauth/controllers/main.py | 45 +++++----- addons/auth_oauth/data/auth_oauth_data.xml | 6 +- addons/auth_oauth/models/__init__.py | 1 + addons/auth_oauth/models/auth_oauth.py | 34 ++++--- .../auth_oauth/models/ir_config_parameter.py | 17 ++-- addons/auth_oauth/models/res_config.py | 63 +++++++------ addons/auth_oauth/models/res_users.py | 90 +++++++++---------- .../auth_oauth/views/auth_oauth_templates.xml | 6 +- addons/auth_oauth/views/auth_oauth_views.xml | 14 ++- addons/auth_oauth/views/res_config_views.xml | 12 ++- addons/auth_oauth/views/res_users_views.xml | 9 +- 14 files changed, 153 insertions(+), 156 deletions(-) diff --git a/addons/auth_oauth/__init__.py b/addons/auth_oauth/__init__.py index bde83af3aea..ac0011716f6 100644 --- a/addons/auth_oauth/__init__.py +++ b/addons/auth_oauth/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. import controllers import models diff --git a/addons/auth_oauth/__openerp__.py b/addons/auth_oauth/__openerp__.py index 46935531d4d..b6f8805dedc 100644 --- a/addons/auth_oauth/__openerp__.py +++ b/addons/auth_oauth/__openerp__.py @@ -1,16 +1,14 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. - { 'name': 'OAuth2 Authentication', - 'version': '1.0', - 'category': 'Extra Tools', + 'category': 'Tools', 'description': """ Allow users to login through OAuth2 Provider. ============================================= """, - 'maintainer': 'Odoo s.a.', + 'maintainer': 'Odoo S.A.', 'depends': ['base', 'web', 'base_setup', 'auth_signup'], 'data': [ 'data/auth_oauth_data.xml', @@ -21,6 +19,4 @@ Allow users to login through OAuth2 Provider. 'views/auth_oauth_templates.xml', 'security/ir.model.access.csv', ], - 'installable': True, - 'auto_install': False, } diff --git a/addons/auth_oauth/controllers/__init__.py b/addons/auth_oauth/controllers/__init__.py index 8ee9bae18d9..f48716d3a69 100644 --- a/addons/auth_oauth/controllers/__init__.py +++ b/addons/auth_oauth/controllers/__init__.py @@ -1 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + import main diff --git a/addons/auth_oauth/controllers/main.py b/addons/auth_oauth/controllers/main.py index b7c1f13cf6b..6dd0643b4fb 100644 --- a/addons/auth_oauth/controllers/main.py +++ b/addons/auth_oauth/controllers/main.py @@ -1,19 +1,22 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + import functools import logging import json -import urlparse + import werkzeug.utils from werkzeug.exceptions import BadRequest -import openerp -from openerp import SUPERUSER_ID -from openerp import http -from openerp.http import request -from openerp.addons.web.controllers.main import db_monodb, ensure_db, set_cookie_and_redirect, login_and_redirect -from openerp.addons.auth_signup.controllers.main import AuthSignupHome as Home -from openerp.modules.registry import RegistryManager -from openerp.tools.translate import _ +from odoo import api, http, SUPERUSER_ID, _ +from odoo.exceptions import AccessDenied +from odoo.http import request +from odoo import registry as registry_get + +from odoo.addons.auth_signup.controllers.main import AuthSignupHome as Home +from odoo.addons.web.controllers.main import db_monodb, ensure_db, set_cookie_and_redirect, login_and_redirect + _logger = logging.getLogger(__name__) @@ -49,8 +52,7 @@ def fragment_to_query_string(func): class OAuthLogin(Home): def list_providers(self): try: - provider_obj = request.registry.get('auth.oauth.provider') - providers = provider_obj.search_read(request.cr, SUPERUSER_ID, [('enabled', '=', True)]) + providers = request.env['auth.oauth.provider'].sudo().search_read([('enabled', '=', True)]) except Exception: providers = [] for provider in providers: @@ -63,8 +65,7 @@ class OAuthLogin(Home): scope=provider['scope'], state=json.dumps(state), ) - provider['auth_link'] = provider['auth_endpoint'] + '?' + werkzeug.url_encode(params) - + provider['auth_link'] = "%s?%s" % (provider['auth_endpoint'], werkzeug.url_encode(params)) return providers def get_state(self, provider): @@ -135,11 +136,11 @@ class OAuthController(http.Controller): dbname = state['d'] provider = state['p'] context = state.get('c', {}) - registry = RegistryManager.get(dbname) + registry = registry_get(dbname) with registry.cursor() as cr: try: - u = registry.get('res.users') - credentials = u.auth_oauth(cr, SUPERUSER_ID, provider, kw, context=context) + env = api.Environment(cr, SUPERUSER_ID, context) + credentials = env['res.users'].sudo().auth_oauth(provider, kw) cr.commit() action = state.get('a') menu = state.get('m') @@ -156,7 +157,7 @@ class OAuthController(http.Controller): # auth_signup is not installed _logger.error("auth_signup not installed on database %s: oauth sign up cancelled." % (dbname,)) url = "/web/login?oauth_error=1" - except openerp.exceptions.AccessDenied: + except AccessDenied: # oauth credentials not valid, user could be on a temporary session _logger.info('OAuth2: access denied, redirect to main page in case a valid session exists, without setting cookies') url = "/web/login?oauth_error=3" @@ -179,18 +180,18 @@ class OAuthController(http.Controller): if not dbname: return BadRequest() - registry = RegistryManager.get(dbname) + registry = registry_get(dbname) with registry.cursor() as cr: - IMD = registry['ir.model.data'] try: - model, provider_id = IMD.get_object_reference(cr, SUPERUSER_ID, 'auth_oauth', 'provider_openerp') + env = api.Environment(cr, SUPERUSER_ID, {}) + provider = env.ref('auth_oauth.provider_openerp') except ValueError: return set_cookie_and_redirect('/web?db=%s' % dbname) - assert model == 'auth.oauth.provider' + assert provider._name == 'auth.oauth.provider' state = { 'd': dbname, - 'p': provider_id, + 'p': provider.id, 'c': {'no_user_creation': True}, } diff --git a/addons/auth_oauth/data/auth_oauth_data.xml b/addons/auth_oauth/data/auth_oauth_data.xml index 3b71b56be1f..1b1ff532ae4 100644 --- a/addons/auth_oauth/data/auth_oauth_data.xml +++ b/addons/auth_oauth/data/auth_oauth_data.xml @@ -1,5 +1,5 @@ - - + + Odoo.com Accounts @@ -30,4 +30,4 @@ Log in with Google - + diff --git a/addons/auth_oauth/models/__init__.py b/addons/auth_oauth/models/__init__.py index 86eac414dfa..7e9ec068f13 100644 --- a/addons/auth_oauth/models/__init__.py +++ b/addons/auth_oauth/models/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. import auth_oauth import ir_config_parameter diff --git a/addons/auth_oauth/models/auth_oauth.py b/addons/auth_oauth/models/auth_oauth.py index 52535fe8c14..de27556140c 100644 --- a/addons/auth_oauth/models/auth_oauth.py +++ b/addons/auth_oauth/models/auth_oauth.py @@ -1,25 +1,23 @@ -from openerp.osv import osv, fields +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. -class auth_oauth_provider(osv.osv): +from odoo import fields, models + + +class AuthOAuthProvider(models.Model): """Class defining the configuration values of an OAuth2 provider""" _name = 'auth.oauth.provider' _description = 'OAuth2 provider' _order = 'name' - _columns = { - 'name' : fields.char('Provider name', required=True), # Name of the OAuth2 entity, Google, etc - 'client_id' : fields.char('Client ID'), # Our identifier - 'auth_endpoint' : fields.char('Authentication URL', required=True), # OAuth provider URL to authenticate users - 'scope' : fields.char('Scope'), # OAUth user data desired to access - 'validation_endpoint' : fields.char('Validation URL', required=True),# 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', required=True), - 'sequence' : fields.integer(), - } - _defaults = { - 'enabled' : False, - 'css_class' : "zocial", - } + name = fields.Char(string='Provider name', required=True) # Name of the OAuth2 entity, Google, etc + client_id = fields.Char(string='Client ID') # Our identifier + auth_endpoint = fields.Char(string='Authentication URL', required=True) # OAuth provider URL to authenticate users + scope = fields.Char() # OAUth user data desired to access + validation_endpoint = fields.Char(string='Validation URL', required=True) # OAuth provider URL to validate tokens + data_endpoint = fields.Char(string='Data URL') + enabled = fields.Boolean(string='Allowed') + css_class = fields.Char(string='CSS class', default='zocial') + body = fields.Char(required=True) + sequence = fields.Integer() diff --git a/addons/auth_oauth/models/ir_config_parameter.py b/addons/auth_oauth/models/ir_config_parameter.py index b0fa17ffa5b..0bb07465286 100644 --- a/addons/auth_oauth/models/ir_config_parameter.py +++ b/addons/auth_oauth/models/ir_config_parameter.py @@ -1,14 +1,15 @@ # -*- coding: utf-8 -*- -from openerp import SUPERUSER_ID -from openerp.osv import osv +# Part of Odoo. See LICENSE file for full copyright and licensing details. -class ir_configparameter(osv.Model): +from odoo import models + + +class IrConfigParameter(models.Model): _inherit = 'ir.config_parameter' - def init(self, cr, force=False): - super(ir_configparameter, self).init(cr, force=force) + def init(self, force=False): + super(IrConfigParameter, self).init(force=force) if force: - IMD = self.pool['ir.model.data'] - oauth_oe = IMD.xmlid_to_object(cr, SUPERUSER_ID, 'auth_oauth.provider_openerp') - dbuuid = self.get_param(cr, SUPERUSER_ID, 'database.uuid') + oauth_oe = self.env.ref('auth_oauth.provider_openerp') + dbuuid = self.sudo().get_param('database.uuid') oauth_oe.write({'client_id': dbuuid}) diff --git a/addons/auth_oauth/models/res_config.py b/addons/auth_oauth/models/res_config.py index c7f14ba6199..2fb55d5ab09 100644 --- a/addons/auth_oauth/models/res_config.py +++ b/addons/auth_oauth/models/res_config.py @@ -1,46 +1,51 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from openerp.osv import osv, fields - import logging + +from odoo import api, fields, models + _logger = logging.getLogger(__name__) -class base_config_settings(osv.TransientModel): + +class BaseConfigSettings(models.TransientModel): _inherit = 'base.config.settings' - def get_uri(self, cr, uid, context=None): - return "%s/auth_oauth/signin" % (self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url', context=context)) + @api.model + def get_uri(self): + return "%s/auth_oauth/signin" % (self.env['ir.config_parameter'].get_param('web.base.url')) - def _get_server_uri(self, cr, uid, ids, name, arg, context=None): - return dict.fromkeys(ids, self.get_uri(cr, uid, context)) + def _compute_server_uri(self): + uri = self.get_uri() + for setting in self: + setting.server_uri_google = uri - _columns = { - 'auth_oauth_google_enabled' : fields.boolean('Allow users to sign in with Google'), - 'auth_oauth_google_client_id' : fields.char('Client ID'), - 'server_uri_google': fields.function(_get_server_uri, type='char', string='Server uri'), - 'auth_oauth_tutorial_enabled': fields.boolean('Show tutorial'), - } + auth_oauth_google_enabled = fields.Boolean(string='Allow users to sign in with Google') + auth_oauth_google_client_id = fields.Char(string='Client ID') + server_uri_google = fields.Char(compute='_compute_server_uri', string='Server uri') + auth_oauth_tutorial_enabled = fields.Boolean(string='Show tutorial') - def default_get(self, cr, uid, fields, context=None): - res = super(base_config_settings, self).default_get(cr, uid, fields, context=context) - res.update(self.get_oauth_providers(cr, uid, fields, context=context)) - return res + @api.model + def default_get(self, fields): + settings = super(BaseConfigSettings, self).default_get(fields) + settings.update(self.get_oauth_providers(fields)) + return settings - def get_oauth_providers(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','client_id'], context=context) + @api.model + def get_oauth_providers(self, fields): + google_provider = self.env.ref('auth_oauth.provider_google') return { - 'auth_oauth_google_enabled': rg[0]['enabled'], - 'auth_oauth_google_client_id': rg[0]['client_id'], - 'server_uri_google': self.get_uri(cr, uid, context) + 'auth_oauth_google_enabled': google_provider.enabled, + 'auth_oauth_google_client_id': google_provider.client_id, + 'server_uri_google': self.get_uri() } - def set_oauth_providers(self, cr, uid, ids, context=None): - google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1] - config = self.browse(cr, uid, ids[0], context=context) + @api.multi + def set_oauth_providers(self): + self.ensure_one() + google_provider = self.env.ref('auth_oauth.provider_google') rg = { - 'enabled':config.auth_oauth_google_enabled, - 'client_id':config.auth_oauth_google_client_id, + 'enabled': self.auth_oauth_google_enabled, + 'client_id': self.auth_oauth_google_client_id, } - self.pool.get('auth.oauth.provider').write(cr, uid, [google_id], rg) + google_provider.write(rg) diff --git a/addons/auth_oauth/models/res_users.py b/addons/auth_oauth/models/res_users.py index f277a6c5fc0..f48802c2310 100644 --- a/addons/auth_oauth/models/res_users.py +++ b/addons/auth_oauth/models/res_users.py @@ -1,31 +1,29 @@ -import logging +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. import werkzeug.urls import urlparse import urllib2 import json -import openerp -from openerp.addons.auth_signup.models.res_partner import SignupError -from openerp.osv import osv, fields -from openerp import SUPERUSER_ID +from odoo import api, fields, models +from odoo.exceptions import AccessDenied +from odoo.addons.auth_signup.models.res_users import SignupError -_logger = logging.getLogger(__name__) -class res_users(osv.Model): +class ResUsers(models.Model): _inherit = 'res.users' - _columns = { - 'oauth_provider_id': fields.many2one('auth.oauth.provider', 'OAuth Provider'), - 'oauth_uid': fields.char('OAuth User ID', help="Oauth Provider user_id", copy=False), - 'oauth_access_token': fields.char('OAuth Access Token', readonly=True, copy=False), - } + oauth_provider_id = fields.Many2one('auth.oauth.provider', string='OAuth Provider') + oauth_uid = fields.Char(string='OAuth User ID', help="Oauth Provider user_id", copy=False) + oauth_access_token = fields.Char(string='OAuth Access Token', readonly=True, copy=False) _sql_constraints = [ ('uniq_users_oauth_provider_oauth_uid', 'unique(oauth_provider_id, oauth_uid)', 'OAuth UID must be unique per provider'), ] - def _auth_oauth_rpc(self, cr, uid, endpoint, access_token, context=None): + @api.model + def _auth_oauth_rpc(self, endpoint, access_token): params = werkzeug.url_encode({'access_token': access_token}) if urlparse.urlparse(endpoint)[4]: url = endpoint + '&' + params @@ -35,18 +33,20 @@ class res_users(osv.Model): response = f.read() return json.loads(response) - def _auth_oauth_validate(self, cr, uid, provider, access_token, context=None): + @api.model + def _auth_oauth_validate(self, provider, access_token): """ return the validation data corresponding to the access token """ - p = self.pool.get('auth.oauth.provider').browse(cr, uid, provider, context=context) - validation = self._auth_oauth_rpc(cr, uid, p.validation_endpoint, access_token, context=context) + oauth_provider = self.env['auth.oauth.provider'].browse(provider) + validation = self._auth_oauth_rpc(oauth_provider.validation_endpoint, access_token) if validation.get("error"): raise Exception(validation['error']) - if p.data_endpoint: - data = self._auth_oauth_rpc(cr, uid, p.data_endpoint, access_token, context=context) + if oauth_provider.data_endpoint: + data = self._auth_oauth_rpc(oauth_provider.data_endpoint, access_token) validation.update(data) return validation - def _generate_signup_values(self, cr, uid, provider, validation, params, context=None): + @api.model + def _generate_signup_values(self, provider, validation, params): oauth_uid = validation['user_id'] email = validation.get('email', 'provider_%s_user_%s' % (provider, oauth_uid)) name = validation.get('name', email) @@ -60,66 +60,66 @@ class res_users(osv.Model): 'active': True, } - def _auth_oauth_signin(self, cr, uid, provider, validation, params, context=None): + @api.model + def _auth_oauth_signin(self, provider, validation, params): """ retrieve and sign in the user corresponding to provider and validated access token :param provider: oauth provider id (int) :param validation: result of validation of access token (dict) :param params: oauth parameters (dict) :return: user login (str) - :raise: openerp.exceptions.AccessDenied if signin failed + :raise: AccessDenied if signin failed This method can be overridden to add alternative signin methods. """ + oauth_uid = validation['user_id'] try: - oauth_uid = validation['user_id'] - user_ids = self.search(cr, uid, [("oauth_uid", "=", oauth_uid), ('oauth_provider_id', '=', provider)]) - if not user_ids: - raise openerp.exceptions.AccessDenied() - assert len(user_ids) == 1 - user = self.browse(cr, uid, user_ids[0], context=context) - user.write({'oauth_access_token': params['access_token']}) - return user.login - except openerp.exceptions.AccessDenied, access_denied_exception: - if context and context.get('no_user_creation'): + oauth_user = self.search([("oauth_uid", "=", oauth_uid), ('oauth_provider_id', '=', provider)]) + if not oauth_user: + raise AccessDenied() + assert len(oauth_user) == 1 + oauth_user.write({'oauth_access_token': params['access_token']}) + return oauth_user.login + except AccessDenied, access_denied_exception: + if self.env.context.get('no_user_creation'): return None state = json.loads(params['state']) token = state.get('t') - values = self._generate_signup_values(cr, uid, provider, validation, params, context=context) + values = self._generate_signup_values(provider, validation, params) try: - _, login, _ = self.signup(cr, uid, values, token, context=context) + _, login, _ = self.signup(values, token) return login except SignupError: raise access_denied_exception - def auth_oauth(self, cr, uid, provider, params, context=None): + @api.model + def auth_oauth(self, provider, params): # Advice by Google (to avoid Confused Deputy Problem) # if validation.audience != OUR_CLIENT_ID: # abort() # else: # continue with the process access_token = params.get('access_token') - validation = self._auth_oauth_validate(cr, uid, provider, access_token, context=context) + validation = self._auth_oauth_validate(provider, access_token) # required check if not validation.get('user_id'): # Workaround: facebook does not send 'user_id' in Open Graph Api if validation.get('id'): validation['user_id'] = validation['id'] else: - raise openerp.exceptions.AccessDenied() + raise AccessDenied() # retrieve and sign in user - login = self._auth_oauth_signin(cr, uid, provider, validation, params, context=context) + login = self._auth_oauth_signin(provider, validation, params) if not login: - raise openerp.exceptions.AccessDenied() + raise AccessDenied() # return user credentials - return (cr.dbname, login, access_token) + return (self.env.cr.dbname, login, access_token) - def check_credentials(self, cr, uid, password): + @api.model + def check_credentials(self, password): try: - return super(res_users, self).check_credentials(cr, uid, password) - except openerp.exceptions.AccessDenied: - res = self.search(cr, SUPERUSER_ID, [('id', '=', uid), ('oauth_access_token', '=', password)]) + return super(ResUsers, self).check_credentials(password) + except AccessDenied: + res = self.sudo().search([('id', '=', self.env.uid), ('oauth_access_token', '=', password)]) if not res: raise - -# diff --git a/addons/auth_oauth/views/auth_oauth_templates.xml b/addons/auth_oauth/views/auth_oauth_templates.xml index a8fe99d30f8..7e483dd842e 100644 --- a/addons/auth_oauth/views/auth_oauth_templates.xml +++ b/addons/auth_oauth/views/auth_oauth_templates.xml @@ -1,6 +1,5 @@ - - + - - + diff --git a/addons/auth_oauth/views/auth_oauth_views.xml b/addons/auth_oauth/views/auth_oauth_views.xml index 58359ee9bfe..0419c1c9f31 100644 --- a/addons/auth_oauth/views/auth_oauth_views.xml +++ b/addons/auth_oauth/views/auth_oauth_views.xml @@ -1,7 +1,6 @@ - - - + + auth.oauth.provider.form auth.oauth.provider @@ -23,8 +22,8 @@ - - auth.oauth.provider.list + + auth.oauth.provider.tree auth.oauth.provider @@ -34,7 +33,7 @@ - + Providers auth.oauth.provider form @@ -43,5 +42,4 @@ - - + diff --git a/addons/auth_oauth/views/res_config_views.xml b/addons/auth_oauth/views/res_config_views.xml index 63f83d3ef4f..6b48bcb21ae 100644 --- a/addons/auth_oauth/views/res_config_views.xml +++ b/addons/auth_oauth/views/res_config_views.xml @@ -1,8 +1,7 @@ - - - - - base.config.settings.oauth + + + + base.config.settings.form.inherit base.config.settings @@ -107,5 +106,4 @@ - - + diff --git a/addons/auth_oauth/views/res_users_views.xml b/addons/auth_oauth/views/res_users_views.xml index f9132d1eede..13e7bdb7ac5 100644 --- a/addons/auth_oauth/views/res_users_views.xml +++ b/addons/auth_oauth/views/res_users_views.xml @@ -1,8 +1,7 @@ - - + - res.users.form + res.users.form.inherit res.users form @@ -18,6 +17,4 @@ - - - +