X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/443f3228eb4c56849f77ae9c421dd1cc6fdbc5f1..7ee36999363fdad6b957747bb96ae3ded5973bc8:/services/api/app/models/arvados_model.rb diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb index 6cd40a4458..16f03430f7 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -50,6 +50,12 @@ class ArvadosModel < ActiveRecord::Base end end + class UnresolvableContainerError < StandardError + def http_status + 422 + end + end + def self.kind_class(kind) kind.match(/^arvados\#(.+)$/)[1].classify.safe_constantize rescue nil end @@ -104,10 +110,27 @@ class ArvadosModel < ActiveRecord::Base api_column_map end + def self.ignored_select_attributes + ["href", "kind", "etag"] + end + def self.columns_for_attributes(select_attributes) + if select_attributes.empty? + raise ArgumentError.new("Attribute selection list cannot be empty") + end + api_column_map = attributes_required_columns + invalid_attrs = [] + select_attributes.each do |s| + next if ignored_select_attributes.include? s + if not s.is_a? String or not api_column_map.include? s + invalid_attrs << s + end + end + if not invalid_attrs.empty? + raise ArgumentError.new("Invalid attribute(s): #{invalid_attrs.inspect}") + end # Given an array of attribute names to select, return an array of column # names that must be fetched from the database to satisfy the request. - api_column_map = attributes_required_columns select_attributes.flat_map { |attr| api_column_map[attr] }.uniq end @@ -226,7 +249,7 @@ class ArvadosModel < ActiveRecord::Base end def logged_attributes - attributes + attributes.except *Rails.configuration.unlogged_attributes end def self.full_text_searchable_columns @@ -391,15 +414,16 @@ class ArvadosModel < ActiveRecord::Base x.each do |k,v| return true if has_symbols?(k) or has_symbols?(v) end - false elsif x.is_a? Array x.each do |k| return true if has_symbols?(k) end - false - else - (x.class == Symbol) + elsif x.is_a? Symbol + return true + elsif x.is_a? String + return true if x.start_with?(':') && !x.start_with?('::') end + false end def self.recursive_stringify x @@ -413,6 +437,8 @@ class ArvadosModel < ActiveRecord::Base end elsif x.is_a? Symbol x.to_s + elsif x.is_a? String and x.start_with?(':') and !x.start_with?('::') + x[1..-1] else x end