[FIX] Fixed oauth in order to reload provider on database selection. Also avoid to...
authorFabien Meghazi <fme@openerp.com>
Thu, 27 Sep 2012 12:34:29 +0000 (14:34 +0200)
committerFabien Meghazi <fme@openerp.com>
Thu, 27 Sep 2012 12:34:29 +0000 (14:34 +0200)
bzr revid: fme@openerp.com-20120927123429-nzau63yeo2zyn7ck

addons/auth_oauth/controllers/main.py
addons/auth_oauth/static/src/css/auth_oauth.css
addons/auth_oauth/static/src/js/auth_oauth.js
addons/auth_oauth/static/src/xml/auth_oauth.xml

index 5d939f1..ae01df5 100644 (file)
@@ -16,10 +16,13 @@ class OAuthController(openerpweb.Controller):
 
     @openerpweb.jsonrequest
     def list_providers(self, req, dbname):
-        registry = openerp.modules.registry.RegistryManager.get(dbname)
-        with registry.cursor() as cr:
-            providers = registry.get('auth.oauth.provider')
-            l = providers.read(cr, SUPERUSER_ID, providers.search(cr, SUPERUSER_ID, [('enabled','=',True)]))
+        try:
+            registry = openerp.modules.registry.RegistryManager.get(dbname)
+            with registry.cursor() as cr:
+                providers = registry.get('auth.oauth.provider')
+                l = providers.read(cr, SUPERUSER_ID, providers.search(cr, SUPERUSER_ID, [('enabled','=',True)]))
+        except Exception:
+            l = []
         return l
 
     @openerpweb.httprequest
index 8e267e1..ed6130e 100644 (file)
@@ -2,13 +2,13 @@
     font: white;
 }
 
-.zocial.openerp:before {
+.openerp .zocial.openerp:before {
     content: "\E02E";
     font-style: italic;
     text-shadow: 0 1px 1px black;
 }
 
-a.zocial.openerp {
+.openerp a.zocial.openerp {
     float: right;
     border: 1px solid #222222;
     color: white;
@@ -29,3 +29,7 @@ a.zocial.openerp {
     text-shadow: none;
     font-weight: normal;
 }
+
+.openerp .oe_login .oe_oauth_provider_login_button {
+    margin-top: 4px;
+}
index 4a41e72..5c80d29 100644 (file)
@@ -1,8 +1,9 @@
 openerp.auth_oauth = function(instance) {
     var QWeb = instance.web.qweb;
 
-    instance.web.Login = instance.web.Login.extend({
+    instance.web.Login.include({
         start: function(parent, params) {
+            var self = this;
             var d = this._super.apply(this, arguments);
             this.$el.on('click', 'a.zocial', this.on_oauth_sign_in);
             this.oauth_providers = [];
@@ -11,7 +12,13 @@ openerp.auth_oauth = function(instance) {
             } else if(this.params.oauth_error === 2) {
                 this.do_warn("Authentication error","");
             }
-            return d.then(this.do_oauth_load);
+            return d.then(this.do_oauth_load).fail(function() {
+                self.do_oauth_load([]);
+            });
+        },
+        on_db_loaded: function(result) {
+            this._super.apply(this, arguments);
+            this.$("form [name=db]").change(this.do_oauth_load);
         },
         do_oauth_load: function() {
             var db = this.$("form [name=db]").val();
@@ -21,6 +28,7 @@ openerp.auth_oauth = function(instance) {
         },
         on_oauth_loaded: function(result) {
             this.oauth_providers = result;
+            this.$('.oe_oauth_provider_login_button').remove();
             var buttons = QWeb.render("auth_oauth.Login.button",{"widget":this});
             this.$(".oe_login_pane form ul").after(buttons);
         },
@@ -33,7 +41,7 @@ openerp.auth_oauth = function(instance) {
             var state_object = {
                 d: dbname,
                 p: p.id
-            }
+            };
             var state = JSON.stringify(state_object);
             var params = {
                 response_type: 'token',
index c269380..76c71b8 100644 (file)
@@ -2,8 +2,7 @@
 <templates id="template" xml:space="preserve">
 <t t-name="auth_oauth.Login.button">
     <t t-foreach="widget.oauth_providers" t-as="p">
-        <a href="#" t-att-class="p.css_class" t-att-data-index="p_index"><t t-esc="p.body"/></a>
-        <br/>
+        <a href="#" t-attf-class="oe_oauth_provider_login_button #{p.css_class}" t-att-data-index="p_index"><t t-esc="p.body"/></a>
     </t>
 </t>
 </templates>