10310: invoke index and show actions only when they are not blacklisted by the api...
authorradhika <radhika@curoverse.com>
Wed, 2 Nov 2016 00:46:31 +0000 (20:46 -0400)
committerradhika <radhika@curoverse.com>
Thu, 10 Nov 2016 15:34:13 +0000 (10:34 -0500)
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/collections_controller.rb
apps/workbench/app/controllers/projects_controller.rb
apps/workbench/app/controllers/work_unit_templates_controller.rb
apps/workbench/app/controllers/work_units_controller.rb
apps/workbench/app/views/projects/_show_workflows.html.erb [new file with mode: 0644]
apps/workbench/test/controllers/disabled_api_test.rb [new file with mode: 0644]
apps/workbench/test/unit/disabled_api_test.rb [new file with mode: 0644]

index f68250ba15bbf77d9e25821632f3d37a0154e25c..c9ce8ce0b748a9473d2cd5f80739d070f1f8aef5 100644 (file)
@@ -13,6 +13,7 @@ class ApplicationController < ActionController::Base
   # Methods that don't require login should
   #   skip_around_filter :require_thread_api_token
   around_filter :require_thread_api_token, except: ERROR_ACTIONS
+  before_filter :ensure_arvados_api_exists, only: [:index, :show]
   before_filter :set_cache_buster
   before_filter :accept_uuid_as_id_param, except: ERROR_ACTIONS
   before_filter :check_user_agreements, except: ERROR_ACTIONS
@@ -213,6 +214,13 @@ class ApplicationController < ActionController::Base
     end
   end
 
+  def ensure_arvados_api_exists
+    if model_class.is_a?(Class) && model_class < ArvadosBase && !model_class.api_exists?(params['action'].to_sym)
+      @errors = ["#{params['action']} method is not supported for #{params['controller']}"]
+      return render_error(status: 404)
+    end
+  end
+
   def index
     find_objects_for_index if !@objects
     render_index
@@ -760,7 +768,11 @@ class ApplicationController < ActionController::Base
   }
 
   @@notification_tests.push lambda { |controller, current_user|
-    PipelineInstance.limit(1).where(created_by: current_user.uuid).each do
+    if PipelineInstance.api_exists?(:index)
+      PipelineInstance.limit(1).where(created_by: current_user.uuid).each do
+        return nil
+      end
+    else
       return nil
     end
     return lambda { |view|
@@ -856,12 +868,14 @@ class ApplicationController < ActionController::Base
   def recent_processes lim
     lim = 12 if lim.nil?
 
-    cols = %w(uuid owner_uuid created_at modified_at pipeline_template_uuid name state started_at finished_at)
-    pipelines = PipelineInstance.select(cols).limit(lim).order(["created_at desc"])
+    procs = {}
+    if PipelineInstance.api_exists?(:index)
+      cols = %w(uuid owner_uuid created_at modified_at pipeline_template_uuid name state started_at finished_at)
+      pipelines = PipelineInstance.select(cols).limit(lim).order(["created_at desc"])
+      pipelines.results.each { |pi| procs[pi] = pi.created_at }
+    end
 
     crs = ContainerRequest.limit(lim).order(["created_at desc"]).filter([["requesting_container_uuid", "=", nil]])
-    procs = {}
-    pipelines.results.each { |pi| procs[pi] = pi.created_at }
     crs.results.each { |c| procs[c] = c.created_at }
 
     Hash[procs.sort_by {|key, value| value}].keys.reverse.first(lim)
index 20b227c3c7277d491c74b96c0f5de7bc415c0f4c..46dcab6dce38487a7bb938472e91f209f4e926e2 100644 (file)
@@ -239,12 +239,15 @@ class CollectionsController < ApplicationController
         render 'hash_matches'
         return
       else
-        jobs_with = lambda do |conds|
-          Job.limit(RELATION_LIMIT).where(conds)
-            .results.sort_by { |j| j.finished_at || j.created_at }
+        if Job.api_exists?(:index)
+          jobs_with = lambda do |conds|
+            Job.limit(RELATION_LIMIT).where(conds)
+              .results.sort_by { |j| j.finished_at || j.created_at }
+          end
+          @output_of = jobs_with.call(output: @object.portable_data_hash)
+          @log_of = jobs_with.call(log: @object.portable_data_hash)
         end
-        @output_of = jobs_with.call(output: @object.portable_data_hash)
-        @log_of = jobs_with.call(log: @object.portable_data_hash)
+
         @project_links = Link.limit(RELATION_LIMIT).order("modified_at DESC")
           .where(head_uuid: @object.uuid, link_class: 'name').results
         project_hash = Group.where(uuid: @project_links.map(&:tail_uuid)).to_hash
index 16212a8d0ad489b381aa3619d69d72443905cfcb..0a2044a0e23e96b741d77658dfa91057fe57bdfa 100644 (file)
@@ -53,6 +53,19 @@ class ProjectsController < ApplicationController
   # It also seems to me that something like these could be used to configure the contents of the panes.
   def show_pane_list
     pane_list = []
+
+    procs = ["arvados#containerRequest"]
+    if PipelineInstance.api_exists?(:index)
+      procs << "arvados#pipelineInstance"
+    end
+
+    workflows = ["arvados#workflow"]
+    workflows_pane_name = 'Workflows'
+    if PipelineTemplate.api_exists?(:index)
+      workflows << "arvados#pipelineTemplate"
+      workflows_pane_name = 'Pipeline_templates'
+    end
+
     if @object.uuid != current_user.andand.uuid
       pane_list << 'Description'
     end
@@ -64,12 +77,12 @@ class ProjectsController < ApplicationController
     pane_list <<
       {
         :name => 'Pipelines_and_processes',
-        :filters => [%w(uuid is_a) + [%w(arvados#containerRequest arvados#pipelineInstance)]]
+        :filters => [%w(uuid is_a) + [procs]]
       }
     pane_list <<
       {
-        :name => 'Pipeline_templates',
-        :filters => [%w(uuid is_a) + [%w(arvados#pipelineTemplate arvados#workflow)]]
+        :name => workflows_pane_name,
+        :filters => [%w(uuid is_a) + [workflows]]
       }
     pane_list <<
       {
@@ -213,6 +226,10 @@ class ProjectsController < ApplicationController
       @name_link_for = {}
       kind_filters.each do |attr,op,val|
         (val.is_a?(Array) ? val : [val]).each do |type|
+          klass = type.split('#')[-1]
+          klass[0] = klass[0].capitalize
+          next if(!Object.const_get(klass).api_exists?(:index))
+
           filters = @filters - kind_filters + [['uuid', 'is_a', type]]
           if type == 'arvados#containerRequest'
             filters = filters + [['container_requests.requesting_container_uuid', '=', nil]]
index 6b5f114a66fda426aa2353fda68c48daf87c7b3e..fe53ac403c3faccf50cc17e2159be32a120e585e 100644 (file)
@@ -6,8 +6,10 @@ class WorkUnitTemplatesController < ApplicationController
     @filters = @filters || []
 
     # get next page of pipeline_templates
-    filters = @filters + [["uuid", "is_a", ["arvados#pipelineTemplate"]]]
-    pipelines = PipelineTemplate.limit(@limit).order(["created_at desc"]).filter(filters)
+    if PipelineTemplate.api_exists?(:index)
+      filters = @filters + [["uuid", "is_a", ["arvados#pipelineTemplate"]]]
+      pipelines = PipelineTemplate.limit(@limit).order(["created_at desc"]).filter(filters)
+    end
 
     # get next page of workflows
     filters = @filters + [["uuid", "is_a", ["arvados#workflow"]]]
index fe6bff1cee4dfd7fa42a8b487376713808cbbd29..3b611aa25b74e28663d9b7ecc2b0647670f066c8 100644 (file)
@@ -14,12 +14,16 @@ class WorkUnitsController < ApplicationController
     @filters = @filters || []
 
     # get next page of pipeline_instances
-    filters = @filters + [["uuid", "is_a", ["arvados#pipelineInstance"]]]
-    pipelines = PipelineInstance.limit(@limit).order(["created_at desc"]).filter(filters)
+    if PipelineInstance.api_exists?(:index)
+      filters = @filters + [["uuid", "is_a", ["arvados#pipelineInstance"]]]
+      pipelines = PipelineInstance.limit(@limit).order(["created_at desc"]).filter(filters)
+    end
 
     # get next page of jobs
-    filters = @filters + [["uuid", "is_a", ["arvados#job"]]]
-    jobs = Job.limit(@limit).order(["created_at desc"]).filter(filters)
+    if Job.api_exists?(:index)
+      filters = @filters + [["uuid", "is_a", ["arvados#job"]]]
+      jobs = Job.limit(@limit).order(["created_at desc"]).filter(filters)
+    end
 
     # get next page of container_requests
     filters = @filters + [["uuid", "is_a", ["arvados#containerRequest"]]]
diff --git a/apps/workbench/app/views/projects/_show_workflows.html.erb b/apps/workbench/app/views/projects/_show_workflows.html.erb
new file mode 100644 (file)
index 0000000..133fddc
--- /dev/null
@@ -0,0 +1,5 @@
+<%= render_pane 'tab_contents', to_string: true, locals: {
+    limit: 50,
+    filters: [['uuid', 'is_a', ["arvados#workflow"]]],
+       sortable_columns: { 'name' => 'workflows.name', 'description' => 'workflows.description' }
+    }.merge(local_assigns) %>
diff --git a/apps/workbench/test/controllers/disabled_api_test.rb b/apps/workbench/test/controllers/disabled_api_test.rb
new file mode 100644 (file)
index 0000000..a41d87f
--- /dev/null
@@ -0,0 +1,63 @@
+require 'test_helper'
+require 'helpers/share_object_helper'
+
+class DisabledApiTest < ActionController::TestCase
+  test "dashboard recent processes when pipeline_instance index API is disabled" do
+    @controller = ProjectsController.new
+
+    dd = ArvadosApiClient.new_or_current.discovery.deep_dup
+    dd[:resources][:pipeline_instances][:methods].delete(:index)
+    ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
+
+    get :index, {}, session_for(:active)
+    assert_includes @response.body, "zzzzz-xvhdp-cr4runningcntnr" # expect crs
+    assert_not_includes @response.body, "zzzzz-d1hrv-"   # expect no pipelines
+  end
+
+  [
+    [:jobs, JobsController.new],
+    [:job_tasks, JobTasksController.new],
+    [:pipeline_instances, PipelineInstancesController.new],
+    [:pipeline_templates, PipelineTemplatesController.new],
+  ].each do |ctrl_name, ctrl|
+    test "#{ctrl_name} index page when API is disabled" do
+      @controller = ctrl
+
+      dd = ArvadosApiClient.new_or_current.discovery.deep_dup
+      dd[:resources][ctrl_name][:methods].delete(:index)
+      ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
+
+      get :index, {}, session_for(:active)
+      assert_response 404
+    end
+  end
+
+  [
+    :active,
+    nil,
+  ].each do |user|
+    test "project tabs as user #{user} when pipeline related index APIs are disabled" do
+      @controller = ProjectsController.new
+
+      Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
+
+      dd = ArvadosApiClient.new_or_current.discovery.deep_dup
+      dd[:resources][:pipeline_templates][:methods].delete(:index)
+      ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
+
+      proj_uuid = api_fixture('groups')['anonymously_accessible_project']['uuid']
+
+      if user
+        get(:show, {id: proj_uuid}, session_for(user))
+      else
+        get(:show, {id: proj_uuid})
+      end
+
+      resp = @response.body
+      assert_includes resp, "href=\"#Data_collections\""
+      assert_includes resp, "href=\"#Pipelines_and_processes\""
+      assert_includes resp, "href=\"#Workflows\""
+      assert_not_includes resp, "href=\"#Pipeline_templates\""
+    end
+  end
+end
diff --git a/apps/workbench/test/unit/disabled_api_test.rb b/apps/workbench/test/unit/disabled_api_test.rb
new file mode 100644 (file)
index 0000000..52e3bd1
--- /dev/null
@@ -0,0 +1,15 @@
+require 'test_helper'
+
+class DisabledApiTest < ActiveSupport::TestCase
+  test 'Job.creatable? reflects whether jobs.create API is enabled' do
+    use_token(:active) do
+      assert(Job.creatable?)
+    end
+    dd = ArvadosApiClient.new_or_current.discovery.deep_dup
+    dd[:resources][:jobs][:methods].delete(:create)
+    ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
+    use_token(:active) do
+      refute(Job.creatable?)
+    end
+  end
+end