Merge branch 'master' into 10310-workbench-disable-apis
authorradhika <radhika@curoverse.com>
Wed, 2 Nov 2016 00:47:28 +0000 (20:47 -0400)
committerradhika <radhika@curoverse.com>
Wed, 2 Nov 2016 00:47:28 +0000 (20:47 -0400)
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/models/arvados_base.rb

index f68250ba15bbf77d9e25821632f3d37a0154e25c..46dad10f0321a6c33313c8dbcb623c0ef8fc7527 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,11 +214,34 @@ class ApplicationController < ActionController::Base
     end
   end
 
+  def ensure_arvados_api_exists
+    if params['action'] == 'show'
+      method = :get
+    else
+      method = params['action'].to_sym
+    end
+
+    exists = arvados_api_exists params['controller'].to_sym, method
+    if !exists
+      @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
   end
 
+  helper_method :arvados_api_exists
+  def arvados_api_exists ctrl, method
+    if [:jobs, :job_tasks, :pipeline_instances, :pipeline_templates].include?(ctrl)
+      arvados_api_client.discovery[:resources][ctrl].andand[:methods].andand[method]
+    else
+      true
+    end
+  end
+
   helper_method :next_page_offset
   def next_page_offset objects=nil
     if !objects
@@ -760,7 +784,11 @@ class ApplicationController < ActionController::Base
   }
 
   @@notification_tests.push lambda { |controller, current_user|
-    PipelineInstance.limit(1).where(created_by: current_user.uuid).each do
+    begin
+      PipelineInstance.limit(1).where(created_by: current_user.uuid).each do
+        return nil
+      end
+    rescue ArvadosApiClient::NotFoundException
       return nil
     end
     return lambda { |view|
@@ -856,12 +884,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"])
+    if arvados_api_exists :pipeline_instances, :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..ebcc392eb7eadc676a229b37784aaee1376a4f98 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 arvados_api_exists :jobs, :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..a0b48fda28884773880973dc743d08ea7859972e 100644 (file)
@@ -53,6 +53,17 @@ 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 arvados_api_exists(:pipeline_instances, :index)
+      procs << "arvados#pipelineInstance"
+    end
+
+    workflows = ["arvados#workflow"]
+    if arvados_api_exists(:pipeline_templates, :index)
+      workflows << "arvados#pipelineTemplate"
+    end
+
     if @object.uuid != current_user.andand.uuid
       pane_list << 'Description'
     end
@@ -64,12 +75,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)]]
+        :filters => [%w(uuid is_a) + [workflows]]
       }
     pane_list <<
       {
@@ -213,6 +224,8 @@ class ProjectsController < ApplicationController
       @name_link_for = {}
       kind_filters.each do |attr,op,val|
         (val.is_a?(Array) ? val : [val]).each do |type|
+          next if(!arvados_api_exists(type.split('#')[-1].underscore.pluralize.to_sym, :index))
+
           filters = @filters - kind_filters + [['uuid', 'is_a', type]]
           if type == 'arvados#containerRequest'
             filters = filters + [['container_requests.requesting_container_uuid', '=', nil]]
index 6b5f114a66fda426aa2353fda68c48daf87c7b3e..9926d5c552f1d93d40ffe5cabea128e0dcf77347 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 arvados_api_exists :pipeline_templates, :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..d94dcdaca42e9769e657b5c8927b96203fd2b8a6 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 arvados_api_exists :pipeline_instances, :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 arvados_api_exists :jobs, :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"]]]
index b02db7a6b63b5fad8c75ea5f107baa74a58d7151..6250daa06a3d0c65d2233f51c33588a9de3855a5 100644 (file)
@@ -334,7 +334,7 @@ class ArvadosBase < ActiveRecord::Base
   end
 
   def self.creatable?
-    current_user.andand.is_active
+    current_user.andand.is_active && api_exists?(:create)
   end
 
   def self.goes_in_projects?
@@ -361,6 +361,10 @@ class ArvadosBase < ActiveRecord::Base
     editable?
   end
 
+  def self.api_exists?(method)
+    arvados_api_client.discovery[:resources][self.to_s.underscore.pluralize.to_sym].andand[:methods].andand[method]
+  end
+
   # Array of strings that are the names of attributes that can be edited
   # with X-Editable.
   def editable_attributes