* A couple of tweaks in response to Tom's feedback
[arvados.git] / apps / workbench / app / controllers / application_controller.rb
index 08a83e498634c6aa7d6ccd4a18e44e1ac897aa4b..6629454b17c8a71285ab5b42b0b4058c37688e67 100644 (file)
@@ -174,24 +174,25 @@ class ApplicationController < ActionController::Base
         logger.debug "No token received, session is #{session.inspect}"
       end
       if try_redirect_to_login
-        respond_to do |f|
-          f.html {
-            if request.method == 'GET'
-              if login_optional
-                Thread.current[:arvados_api_token] = nil
-                yield
-              else
+        unless login_optional
+          respond_to do |f|
+            f.html {
+              if request.method == 'GET'
                 redirect_to $arvados_api_client.arvados_login_url(return_to: request.url)
+              else
+                flash[:error] = "Either you are not logged in, or your session has timed out. I can't automatically log you in and re-attempt this request."
+                redirect_to :back
               end
-            else
-              flash[:error] = "Either you are not logged in, or your session has timed out. I can't automatically log you in and re-attempt this request."
-              redirect_to :back
-            end
-          }
-          f.json {
-            @errors = ['You do not seem to be logged in. You did not supply an API token with this request, and your session (if any) has timed out.']
-            self.render_error status: 422
-          }
+            }
+            f.json {
+              @errors = ['You do not seem to be logged in. You did not supply an API token with this request, and your session (if any) has timed out.']
+              self.render_error status: 422
+            }
+          end
+        else
+          # login is optional for this route so go on to the regular controller
+          Thread.current[:arvados_api_token] = nil
+          yield
         end
       end
     ensure