* Removed 'rescue' clause. I think I left that in from debugging.
* Fixed :log -> :logs
* filters: ['tail_kind','=','arvados#user'] works
* Added more tests.
* Added equivalent logic and tests for logs controller for object_kind
end
def load_filters_param
+ @filters ||= []
if params[:filters].is_a? Array
- @filters = params[:filters]
+ @filters += params[:filters]
elsif params[:filters].is_a? String and !params[:filters].empty?
begin
- @filters = Oj.load params[:filters]
+ @filters += Oj.load params[:filters]
raise unless @filters.is_a? Array
rescue
raise ArgumentError.new("Could not parse \"filters\" param as an array")
class Arvados::V1::LinksController < ApplicationController
- prepend_before_filter :load_kind_params, :only => :index
-
def create
resource_attrs.delete :head_kind
resource_attrs.delete :tail_kind
super
end
- def load_kind_params
- if params[:tail_uuid]
- params[:where] = Oj.load(params[:where]) if params[:where].is_a?(String)
- @where ||= {}
- @where[:tail_uuid] = params[:tail_uuid]
- end
+ protected
- if params[:where] and params[:where].is_a? Hash
- if params[:where][:head_kind]
- params[:filters] ||= []
- params[:filters] << ['head_uuid', 'is_a', params[:where][:head_kind]]
- params[:where].delete :head_kind
+ # Overrides ApplicationController load_where_param
+ def load_where_param
+ super
+
+ # head_kind and tail_kind columns are now virtual,
+ # equivilent functionality is now provided by
+ # 'is_a', so fix up any old-style 'where' clauses.
+ if @where
+ @filters ||= []
+ if @where[:head_kind]
+ @filters << ['head_uuid', 'is_a', @where[:head_kind]]
+ @where.delete :head_kind
end
- if params[:where][:tail_kind]
- params[:filters] ||= []
- params[:filters] << ['tail_uuid', 'is_a', params[:where][:tail_kind]]
- params[:where].delete :tail_kind
+ if @where[:tail_kind]
+ @filters << ['tail_uuid', 'is_a', @where[:tail_kind]]
+ @where.delete :tail_kind
end
end
+ end
+ # Overrides ApplicationController load_filters_param
+ def load_filters_param
+ super
+
+ # head_kind and tail_kind columns are now virtual,
+ # equivilent functionality is now provided by
+ # 'is_a', so fix up any old-style 'filter' clauses.
+ @filters = @filters.map do |k|
+ if k[0] == 'head_kind' and k[1] == '='
+ ['head_uuid', 'is_a', k[2]]
+ elsif k[0] == 'tail_kind' and k[1] == '='
+ ['tail_uuid', 'is_a', k[2]]
+ else
+ k
+ end
+ end
end
end
class Arvados::V1::LogsController < ApplicationController
+ # Overrides ApplicationController load_where_param
+ def load_where_param
+ super
+
+ # object_kind and column is now virtual,
+ # equivilent functionality is now provided by
+ # 'is_a', so fix up any old-style 'where' clauses.
+ if @where
+ @filters ||= []
+ if @where[:object_kind]
+ @filters << ['object_uuid', 'is_a', @where[:object_kind]]
+ @where.delete :object_kind
+ end
+ end
+ end
+
+ # Overrides ApplicationController load_filters_param
+ def load_filters_param
+ super
+
+ # object_kind and column is now virtual,
+ # equivilent functionality is now provided by
+ # 'is_a', so fix up any old-style 'filter' clauses.
+ @filters = @filters.map do |k|
+ if k[0] == 'object_kind' and k[1] == '='
+ ['object_uuid', 'is_a', k[2]]
+ else
+ k
+ end
+ end
+ end
+
end
specials = [system_user_uuid, 'd41d8cd98f00b204e9800998ecf8427e+0']
foreign_key_attributes.each do |attr|
- begin
- if new_record? or send (attr + "_changed?")
- attr_value = send attr
- r = ArvadosModel::resource_class_for_uuid attr_value if attr_value
- r = r.readable_by(current_user) if r and not skip_uuid_read_permission_check.include? attr
- if r and r.where(uuid: attr_value).count == 0 and not specials.include? attr_value
- errors.add(attr, "'#{attr_value}' not found")
- end
+ if new_record? or send (attr + "_changed?")
+ attr_value = send attr
+ r = ArvadosModel::resource_class_for_uuid attr_value if attr_value
+ r = r.readable_by(current_user) if r and not skip_uuid_read_permission_check.include? attr
+ if r and r.where(uuid: attr_value).count == 0 and not specials.include? attr_value
+ errors.add(attr, "'#{attr_value}' not found")
end
- rescue Exception => e
- bt = e.backtrace.join("\n")
- errors.add(attr, "'#{attr_value}' error '#{e}'\n#{bt}\n")
end
end
end
after_update :maybe_invalidate_permissions_cache
after_create :maybe_invalidate_permissions_cache
after_destroy :maybe_invalidate_permissions_cache
+ attr_accessor :head_kind, :tail_kind
api_accessible :user, extend: :common do |t|
t.add :tail_uuid
include CommonApiTemplate
serialize :properties, Hash
before_validation :set_default_event_at
- attr_accessor :object
+ attr_accessor :object, :object_kind
api_accessible :user, extend: :common do |t|
t.add :object_uuid
t.add :object, :if => :object
+ t.add :object_kind
t.add :event_at
t.add :event_type
t.add :summary
t.add :properties
end
+ def object_kind
+ if k = ArvadosModel::resource_class_for_uuid(object_uuid)
+ k.kind
+ end
+ end
+
def fill_object(thing)
self.object_uuid ||= thing.uuid
self.summary ||= "#{self.event_type} of #{thing.uuid}"
def up
remove_column :links, :head_kind
remove_column :links, :tail_kind
- remove_column :log, :object_kind
+ remove_column :logs, :object_kind
end
def down
add_column :links, :head_kind, :string
add_column :links, :tail_kind, :string
- add_column :log, :object_kind, :string
+ add_column :logs, :object_kind, :string
act_as_system_user do
Link.all.each do |l|
--- /dev/null
+log1:
+ uuid: zzzzz-xxxxx-pshmckwoma9plh7
+ object_uuid: zzzzz-tpzed-l1s2piq4t4mps8r
\ No newline at end of file
assert_response 422
end
- test "head and tail exist" do
+ test "head and tail exist, head_kind and tail_kind are returned" do
link = {
link_class: 'test',
name: 'stuff',
assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
end
+ test "test can still use filter tail_kind" do
+ authorize_with :admin
+ get :index, {
+ filters: [ ['tail_kind', '=', 'arvados#user'] ]
+ }
+ assert_response :success
+ found = assigns(:objects)
+ assert_not_equal 0, found.count
+ assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
+ end
+
+ test "test can still use filter head_kind" do
+ authorize_with :admin
+ get :index, {
+ filters: [ ['head_kind', '=', 'arvados#user'] ]
+ }
+ assert_response :success
+ found = assigns(:objects)
+ assert_not_equal 0, found.count
+ assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
+ end
+
end
require 'test_helper'
class Arvados::V1::LogsControllerTest < ActionController::TestCase
+ fixtures :logs
+
test "non-admins can read their own logs" do
authorize_with :active
post :create, log: {summary: "test log"}
assert_equal("test log", assigns(:object).summary,
"loaded wrong log after creation")
end
+
+ test "test can still use where object_kind" do
+ authorize_with :admin
+ get :index, {
+ where: { object_kind: 'arvados#user' }
+ }
+ assert_response :success
+ found = assigns(:objects)
+ assert_not_equal 0, found.count
+ assert_equal found.count, (found.select { |f| f.object_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
+ l = JSON.parse(@response.body)
+ assert_equal 'arvados#user', l['items'][0]['object_kind']
+ end
+
+ test "test can still use filter object_kind" do
+ authorize_with :admin
+ get :index, {
+ filters: [ ['object_kind', '=', 'arvados#user'] ]
+ }
+ assert_response :success
+ found = assigns(:objects)
+ assert_not_equal 0, found.count
+ assert_equal found.count, (found.select { |f| f.object_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
+ end
+
end