5261: Redirect to destination project's Collections tab when copying/moving collections.
[arvados.git] / apps / workbench / app / controllers / application_controller.rb
index 5d097c1a0886fad3dead9e811fa2f6420a472c4a..0a13fa6b601d2d45a8eac3d0a18d0b2c951584e6 100644 (file)
@@ -8,7 +8,6 @@ class ApplicationController < ActionController::Base
   ERROR_ACTIONS = [:render_error, :render_not_found]
 
   around_filter :thread_clear
-  before_filter :permit_anonymous_browsing_for_public_data
   around_filter :set_thread_api_token
   # Methods that don't require login should
   #   skip_around_filter :require_thread_api_token
@@ -268,6 +267,14 @@ class ApplicationController < ActionController::Base
     end
   end
 
+  def redirect_to uri, *args
+    if request.xhr?
+      render json: {href: uri}
+    else
+      super
+    end
+  end
+
   def choose
     params[:limit] ||= 40
     respond_to do |f|
@@ -391,7 +398,7 @@ class ApplicationController < ActionController::Base
     @user_is_manager = false
     @share_links = []
 
-    if @object.uuid != current_user.uuid
+    if @object.uuid != current_user.andand.uuid
       begin
         @share_links = Link.permissions_for(@object)
         @user_is_manager = true
@@ -436,6 +443,7 @@ class ApplicationController < ActionController::Base
 
   protected
 
+  helper_method :strip_token_from_path
   def strip_token_from_path(path)
     path.sub(/([\?&;])api_token=[^&;]*[&;]?/, '\1')
   end
@@ -498,7 +506,7 @@ class ApplicationController < ActionController::Base
       else
         @object = model_class.find(params[:uuid])
       end
-    rescue ArvadosApiClient::NotFoundException, RuntimeError => error
+    rescue ArvadosApiClient::NotFoundException, ArvadosApiClient::NotLoggedInException, RuntimeError => error
       if error.is_a?(RuntimeError) and (error.message !~ /^argument to find\(/)
         raise
       end
@@ -565,17 +573,6 @@ class ApplicationController < ActionController::Base
     end
   end
 
-  # Anonymous allowed paths:
-  #   /projects/#{uuid}?public_data=true
-  def permit_anonymous_browsing_for_public_data
-    if !Thread.current[:arvados_api_token] && !params[:api_token] && !session[:arvados_api_token]
-      public_project_accessed = /\/projects\/([0-9a-z]{5}-j7d0g-[0-9a-z]{15})(.*)public_data\=true/.match(request.fullpath)
-      if public_project_accessed
-        params[:api_token] = Rails.configuration.anonymous_user_token
-      end
-    end
-  end
-
   # Save the session API token in thread-local storage, and yield.
   # This method also takes care of session setup if the request
   # provides a valid api_token parameter.
@@ -639,8 +636,6 @@ class ApplicationController < ActionController::Base
 
   def check_user_agreements
     if current_user && !current_user.is_active
-      return true if is_anonymous
-
       if not current_user.is_invited
         return redirect_to inactive_users_path(return_to: request.fullpath)
       end
@@ -660,9 +655,10 @@ class ApplicationController < ActionController::Base
   end
 
   def check_user_profile
+    return true if !current_user
     if request.method.downcase != 'get' || params[:partial] ||
        params[:tab_pane] || params[:action_method] ||
-       params[:action] == 'setup_popup' || is_anonymous
+       params[:action] == 'setup_popup'
       return true
     end
 
@@ -1094,10 +1090,4 @@ class ApplicationController < ActionController::Base
   def wiselinks_layout
     'body'
   end
-
-  helper_method :is_anonymous
-  def is_anonymous
-    return Rails.configuration.anonymous_user_token &&
-          (Thread.current[:arvados_api_token] == Rails.configuration.anonymous_user_token)
-  end
 end