Merge branch 'master' into 2857-collection-tests
[arvados.git] / services / api / app / controllers / arvados / v1 / links_controller.rb
index 1b5bf78dbeb61821411e6cb754d6d977825bad58..188ecfc1a04a78731697a55da0ad05a5d8706476 100644 (file)
@@ -1,6 +1,18 @@
 class Arvados::V1::LinksController < ApplicationController
 
+  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