Fix get_n_objects_of only accepts ArvadosBase classes, not any class. no issue #
[arvados.git] / apps / workbench / app / controllers / application_controller.rb
index ebd8661f55800674b1bfb653b84e39f342bf16e3..ec2e95afd2ed065530459d25baf00a0f87d2ba6d 100644 (file)
@@ -12,20 +12,18 @@ class ApplicationController < ActionController::Base
   around_filter :thread_with_optional_api_token
   before_filter :check_user_agreements, except: ERROR_ACTIONS
   before_filter :check_user_notifications, except: ERROR_ACTIONS
-  before_filter :find_object_by_uuid, except: [:index] + ERROR_ACTIONS
+  before_filter :find_object_by_uuid, except: [:index, :choose] + ERROR_ACTIONS
   theme :select_theme
 
   begin
-    rescue_from Exception,
-    :with => :render_exception
-    rescue_from ActiveRecord::RecordNotFound,
-    :with => :render_not_found
-    rescue_from ActionController::RoutingError,
-    :with => :render_not_found
-    rescue_from ActionController::UnknownController,
-    :with => :render_not_found
-    rescue_from ::AbstractController::ActionNotFound,
-    :with => :render_not_found
+    rescue_from(ActiveRecord::RecordNotFound,
+                ActionController::RoutingError,
+                ActionController::UnknownController,
+                AbstractController::ActionNotFound,
+                with: :render_not_found)
+    rescue_from(Exception,
+                ActionController::UrlGenerationError,
+                with: :render_exception)
   end
 
   def unprocessable(message=nil)
@@ -145,8 +143,17 @@ class ApplicationController < ActionController::Base
   end
 
   def choose
-    params[:limit] ||= 20
-    find_objects_for_index if !@objects
+    params[:limit] ||= 40
+    if !@objects
+      if params[:project_uuid] and !params[:project_uuid].empty?
+        # We want the chooser to show objects of the controllers's model_class
+        # type within a specific project specified by project_uuid, so fetch the
+        # project and request the contents of the project filtered on the
+        # controllers's model_class kind.
+        @objects = Group.find(params[:project_uuid]).contents({:filters => [['uuid', 'is_a', "arvados\##{ArvadosApiClient.class_kind(model_class)}"]]})
+      end
+      find_objects_for_index if !@objects
+    end
     respond_to do |f|
       if params[:partial]
         f.json {
@@ -728,7 +735,7 @@ class ApplicationController < ActionController::Base
   def get_n_objects_of_class dataclass, size
     @objects_map_for ||= {}
 
-    raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? Class
+    raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? ArvadosBase
     raise ArgumentError, 'Argument is not a valid limit size' unless (size && size>0)
 
     # if the objects_map_for has a value for this dataclass, and the