[ARVADOS] created: 01e105fdeeaec55b18e3ec77612378a554f3f659
git at public.curoverse.com
git at public.curoverse.com
Tue Apr 1 22:17:59 EDT 2014
at 01e105fdeeaec55b18e3ec77612378a554f3f659 (commit)
commit 01e105fdeeaec55b18e3ec77612378a554f3f659
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Apr 1 22:16:43 2014 -0400
Fix searching on tables with no "name" column. Take care not to use
string operators on incompatible column types when applying
where/filters.
diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index fa189aa..ab6ec9c 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -146,7 +146,7 @@ class ApplicationController < ActionController::Base
cond_out = []
param_out = []
@filters.each do |attr, operator, operand|
- if !model_class.searchable_columns.index attr.to_s
+ if !model_class.searchable_columns(operator).index attr.to_s
raise ArgumentError.new("Invalid attribute '#{attr}' in condition")
end
case operator.downcase
@@ -175,13 +175,12 @@ class ApplicationController < ActionController::Base
if @where.is_a? Hash and @where.any?
conditions = ['1=1']
@where.each do |attr,value|
- if attr == :any
+ if attr.to_s == 'any'
if value.is_a?(Array) and
value.length == 2 and
- value[0] == 'contains' and
- model_class.columns.collect(&:name).index('name') then
+ value[0] == 'contains' then
ilikes = []
- model_class.searchable_columns.each do |column|
+ model_class.searchable_columns('ilike').each do |column|
ilikes << "#{table_name}.#{column} ilike ?"
conditions << "%#{value[1]}%"
end
diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 8e37898..38c7a79 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -38,9 +38,14 @@ class ArvadosModel < ActiveRecord::Base
"#{current_api_base}/#{self.class.to_s.pluralize.underscore}/#{self.uuid}"
end
- def self.searchable_columns
+ def self.searchable_columns operator
+ textonly_operator = !operator.match(/[<=>]/)
self.columns.collect do |col|
- if [:string, :text, :datetime, :integer].index(col.type) && col.name != 'owner_uuid'
+ if col.name == 'owner_uuid'
+ nil
+ elsif [:string, :text].index(col.type)
+ col.name
+ elsif !textonly_operator and [:datetime, :integer].index(col.type)
col.name
end
end.compact
diff --git a/services/api/test/functional/arvados/v1/collections_controller_test.rb b/services/api/test/functional/arvados/v1/collections_controller_test.rb
index 575eda3..e5235c4 100644
--- a/services/api/test/functional/arvados/v1/collections_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb
@@ -198,4 +198,15 @@ EOS
assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
end
+ test "search collections with 'any' operator" do
+ authorize_with :active
+ get :index, {
+ where: { any: ['contains', '7f9102c395f4ffc5e3'] }
+ }
+ assert_response :success
+ found = assigns(:objects).collect(&:uuid)
+ assert_equal 1, assigns(:objects).count
+ assert_equal true, !!found.index('1f4b0bc7583c2a7f9102c395f4ffc5e3+45')
+ end
+
end
diff --git a/services/api/test/functional/arvados/v1/jobs_controller_test.rb b/services/api/test/functional/arvados/v1/jobs_controller_test.rb
index a8a4f85..9904c83 100644
--- a/services/api/test/functional/arvados/v1/jobs_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/jobs_controller_test.rb
@@ -223,7 +223,8 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
}
assert_response :success
found = assigns(:objects).collect(&:uuid)
- assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
+ assert_equal 0, found.index('zzzzz-8i9sb-pshmckwoma9plh7')
+ assert_equal 1, found.count
end
test "search jobs by nonexistent column with < query" do
commit b0542ec0dd2bb6fbf040d1c7d719e7fa4d82d58a
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Apr 1 21:53:13 2014 -0400
Load ArvadosApiClient after configuration.
diff --git a/apps/workbench/app/models/arvados_api_client.rb b/apps/workbench/app/models/arvados_api_client.rb
index 2f83a41..367a33e 100644
--- a/apps/workbench/app/models/arvados_api_client.rb
+++ b/apps/workbench/app/models/arvados_api_client.rb
@@ -9,7 +9,7 @@ class ArvadosApiClient
@@client_mtx = Mutex.new
@@api_client = nil
- @@profiling_enabled = Rails.configuration.profiling_enabled rescue false
+ @@profiling_enabled = Rails.configuration.profiling_enabled
def api(resources_kind, action, data=nil)
profile_checkpoint
diff --git a/apps/workbench/config/initializers/arvados_api_client.rb b/apps/workbench/config/initializers/arvados_api_client.rb
deleted file mode 100644
index 6222ab5..0000000
--- a/apps/workbench/config/initializers/arvados_api_client.rb
+++ /dev/null
@@ -1 +0,0 @@
-$arvados_api_client = ArvadosApiClient.new
diff --git a/apps/workbench/config/initializers/zz_load_config.rb b/apps/workbench/config/initializers/zza_load_config.rb
similarity index 90%
rename from apps/workbench/config/initializers/zz_load_config.rb
rename to apps/workbench/config/initializers/zza_load_config.rb
index 43711fc..51fc81a 100644
--- a/apps/workbench/config/initializers/zz_load_config.rb
+++ b/apps/workbench/config/initializers/zza_load_config.rb
@@ -1,3 +1,6 @@
+# This file must be loaded _after_ secret_token.rb if secret_token is
+# defined there instead of in config/application.yml.
+
$application_config = {}
%w(application.default application).each do |cfgfile|
diff --git a/apps/workbench/config/initializers/zzz_arvados_api_client.rb b/apps/workbench/config/initializers/zzz_arvados_api_client.rb
new file mode 100644
index 0000000..20ddd8c
--- /dev/null
+++ b/apps/workbench/config/initializers/zzz_arvados_api_client.rb
@@ -0,0 +1,8 @@
+# The client object must be instantiated _after_ zza_load_config.rb
+# runs, because it relies on configuration settings.
+#
+if not $application_config
+ raise "Fatal: Config must be loaded before instantiating ArvadosApiClient."
+end
+
+$arvados_api_client = ArvadosApiClient.new
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list