X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cc5023d40182e503e8ba109fc86e09efd6337836..8eaad00b025167a7505ba11ad6a05b52a43c2399:/services/api/app/controllers/arvados/v1/links_controller.rb?ds=sidebyside diff --git a/services/api/app/controllers/arvados/v1/links_controller.rb b/services/api/app/controllers/arvados/v1/links_controller.rb index 1b79295af7..188ecfc1a0 100644 --- a/services/api/app/controllers/arvados/v1/links_controller.rb +++ b/services/api/app/controllers/arvados/v1/links_controller.rb @@ -1,33 +1,61 @@ class Arvados::V1::LinksController < ApplicationController - prepend_before_filter :load_kind_params, :only => :index + def check_uuid_kind uuid, kind + if kind and ArvadosModel::resource_class_for_uuid(uuid).andand.kind != kind + render :json => { errors: ["'#{kind}' does not match uuid '#{uuid}', expected '#{ArvadosModel::resource_class_for_uuid(uuid).andand.kind}'"] }.to_json, status: 422 + nil + else + true + end + end def create + return if ! check_uuid_kind resource_attrs[:head_uuid], resource_attrs[:head_kind] + return if ! check_uuid_kind resource_attrs[:tail_uuid], resource_attrs[:tail_kind] + 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 + + # Overrides ApplicationController load_where_param + def load_where_param + super - 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 + # 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