13647: Move ...Controller.from_config_or_db to KeepService.all.
authorTom Clegg <tclegg@veritasgenetics.com>
Mon, 16 Sep 2019 00:07:23 +0000 (20:07 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Mon, 16 Sep 2019 00:07:23 +0000 (20:07 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

services/api/app/controllers/arvados/v1/keep_services_controller.rb
services/api/app/models/keep_service.rb
services/api/test/functional/arvados/v1/keep_services_controller_test.rb

index 865f9c942f4aa63311a0da88e2dd203e9362a5bb..c6e8894352f4f5f147c1d8e7f7d4c6d7db331aab 100644 (file)
@@ -10,29 +10,16 @@ class Arvados::V1::KeepServicesController < ApplicationController
 
   def find_objects_for_index
     # all users can list all keep services
-    @objects = from_config_or_db
+    @objects = KeepService.all
     super
   end
 
   def accessible
     if request.headers['X-External-Client'] == '1'
-      @objects = from_config_or_db.where('service_type=?', 'proxy')
+      @objects = KeepService.where('service_type=?', 'proxy')
     else
-      @objects = from_config_or_db.where('service_type<>?', 'proxy')
+      @objects = KeepService.where('service_type<>?', 'proxy')
     end
     render_list
   end
-
-  private
-
-  # return the set of keep services from the database (if this is an
-  # older installation or test system where entries have been added
-  # manually) or, preferably, the cluster config file.
-  def from_config_or_db
-    if KeepService.all.count == 0
-      KeepService.from_config
-    else
-      KeepService.all
-    end
-  end
 end
index f9dd01837c988c35e8597cf3a96d45c255297cfe..777f6bfb223d5156dfd07864dbf77fa37dec97fc 100644 (file)
@@ -20,6 +20,21 @@ class KeepService < ArvadosModel
   api_accessible :superuser, :extend => :user do |t|
   end
 
+  # return the set of keep services from the database (if this is an
+  # older installation or test system where entries have been added
+  # manually) or, preferably, the cluster config file.
+  def self.all *args
+    if super.count == 0
+      from_config
+    else
+      super
+    end
+  end
+
+  def self.where *args
+    all.where *args
+  end
+
   protected
 
   def permission_to_create
@@ -45,10 +60,10 @@ class KeepService < ArvadosModel
     end
     if values.length == 0
       # return empty set as AR relation
-      return where('1=0')
+      return unscoped.where('1=0')
     else
       sql = "(values #{values.join(", ")}) as keep_services (id, uuid, service_host, service_port, service_ssl_flag, service_type, read_only, created_at, modified_at, owner_uuid, modified_by_user_uuid, modified_by_client_uuid)"
-      return KeepService.from(sql)
+      return unscoped.from(sql)
     end
   end
 
index 33c8aad3ea13dedebe1da34dce677dba45eaef9c..f41a1d679c33bd5611936d86489bb945674c9409 100644 (file)
@@ -37,7 +37,7 @@ class Arvados::V1::KeepServicesControllerTest < ActionController::TestCase
   end
 
   test "report configured servers if db is empty" do
-    KeepService.all.delete_all
+    KeepService.unscoped.all.delete_all
     expect_rvz = {}
     n = 0
     Rails.configuration.Services.Keepstore.InternalURLs.each do |k,v|
@@ -57,6 +57,7 @@ class Arvados::V1::KeepServicesControllerTest < ActionController::TestCase
     get :index,
       params: {:format => :json},
       headers: auth(:active)
+    assert_response :success
     json_response['items'].each do |svc|
       url = "#{svc['service_ssl_flag'] ? 'https' : 'http'}://#{svc['service_host']}:#{svc['service_port']}"
       assert_equal true, expect_rvz.has_key?(url), "#{url} does not match any configured service: expecting #{expect_rvz}"