summaryrefslogtreecommitdiff
path: root/addons/auth_oauth/controllers
diff options
context:
space:
mode:
authorKinjal Mehta <kme@odoo.com>2015-08-11 19:08:28 +0530
committerYannick Tivisse <yti@odoo.com>2016-08-02 16:02:29 +0200
commit3f201066f0f360eaf84ee02b661ad9994758f304 (patch)
tree232c5547561b607876d0f6f005f10cbb7e57bcdb /addons/auth_oauth/controllers
parent914b2be9678e747b585839449de04f86464941d4 (diff)
[MIG]auth_oauth: Migrate to new api.
Diffstat (limited to 'addons/auth_oauth/controllers')
-rw-r--r--addons/auth_oauth/controllers/__init__.py3
-rw-r--r--addons/auth_oauth/controllers/main.py45
2 files changed, 26 insertions, 22 deletions
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},
}