[PATCH conductor] BZ 858997 - Fix AJAX error handling

Matt Wagner matt.wagner at redhat.com
Fri Sep 21 13:55:32 UTC 2012


On Fri, Sep 21, 2012 at 02:09:19PM +0200, Jirka Tomasek wrote:
> On 09/21/2012 12:31 AM, Matt Wagner wrote:
> >A recent patch for the login page broke our handling of 401s
> >on AJAX responses. That has an easy fix, but broke the login
> >page's error-handling.
> >
> >This fix modifies the login page to handle 401s. It's the most
> >elegant fix I could find at this time -- ideally we should pull
> >some part of this 401 handling up to converge-ui but that is
> >out of scope for today.
> >
> >https://bugzilla.redhat.com/show_bug.cgi?id=858997
> >---
> >  src/app/controllers/user_sessions_controller.rb |    2 +-
> >  src/app/views/user_sessions/new.html.haml       |   15 ++++++++++++++-
> >  2 files changed, 15 insertions(+), 2 deletions(-)
> >
> >diff --git a/src/app/controllers/user_sessions_controller.rb b/src/app/controllers/user_sessions_controller.rb
> >index 8f3385d..ac0607f 100644
> >--- a/src/app/controllers/user_sessions_controller.rb
> >+++ b/src/app/controllers/user_sessions_controller.rb
> >@@ -48,7 +48,7 @@ class UserSessionsController < ApplicationController
> >        format.xml { head :unauthorized }
> >        flash.now[:warning] = t "user_sessions.flash.warning.login_failed"

What if we move this to format.html only, and ....

> >        format.html { render :action => :new }
> >-      format.js { render :layout => false }
> >+      format.js { head :unauthorized }
> >      end
> >    end
> >diff --git a/src/app/views/user_sessions/new.html.haml b/src/app/views/user_sessions/new.html.haml
> >index ec04542..b195b1b 100644
> >--- a/src/app/views/user_sessions/new.html.haml
> >+++ b/src/app/views/user_sessions/new.html.haml
> >@@ -17,10 +17,23 @@
> >    = "| #{@title}" unless @title.blank?
> >  = content_for :notifications do
> >-  = render :partial => 'notifications' if flash[:warning].present?

... leave this in?

> >+  %div.error.hidden
> >+    %p.text= t("user_sessions.flash.warning.login_failed")

Then just leave this part in.

> error message is not displayed when JS is turned off.
> 
> >  = content_for :login_logo do
> >    = image_tag 'login-card-logo-upstream.png'
> >  = content_for :footer do
> >    = render :partial => 'layouts/footer'
> >+
> >+= content_for :extra do
> >+  %script
> >+    :plain
> >+      $(document).bind("ajax:complete",
> >+              function(evt, data, status, xhr){
> >+                if(status == "error") {
> >+                  $('.error').show();

(And use a name other than '.error' here so it matches only the JS
version.)

> >+                  $('form .spinner').fadeOut('fast');
> >+                }
> >+              }
> >+      );
> 
> With this approach, the error message is not displayed when JS is
> turned off because it is not using flash functionality. I have tried
> to play with this, the best solution would probably be to
> use
> 
> format.js { render :layout => false, :status => :unauthorized }
> 
> in controller. But the problem is that the js.erb is not executed then :/

Oh, good catch. Does what I described inline above sound better?

-- Matt



More information about the aeolus-devel mailing list