Merge branch 'master' into 1971-show-image-thumbnails
[arvados.git] / services / api / app / controllers / arvados / v1 / links_controller.rb
1 class Arvados::V1::LinksController < ApplicationController
2
3   def create
4     if resource_attrs[:head_kind] and ArvadosModel::resource_class_for_uuid(resource_attrs[:head_uuid]).kind != resource_attrs[:head_kind]
5       errors.add(attr, "'#{resource_attrs[:head_kind]}' does not match '#{head_uuid}'")
6     end
7
8     if resource_attrs[:tail_kind] and ArvadosModel::resource_class_for_uuid(resource_attrs[:tail_uuid]).kind != resource_attrs[:tail_kind]
9       errors.add(attr, "'#{resource_attrs[:tail_kind]}' does not match '#{tail_uuid}'")
10     end
11
12     resource_attrs.delete :head_kind
13     resource_attrs.delete :tail_kind
14     super
15   end
16
17   protected
18
19   # Overrides ApplicationController load_where_param
20   def load_where_param
21     super
22
23     # head_kind and tail_kind columns are now virtual,
24     # equivilent functionality is now provided by
25     # 'is_a', so fix up any old-style 'where' clauses.
26     if @where
27       @filters ||= []
28       if @where[:head_kind]
29         @filters << ['head_uuid', 'is_a', @where[:head_kind]]
30         @where.delete :head_kind
31       end
32       if @where[:tail_kind]
33         @filters << ['tail_uuid', 'is_a', @where[:tail_kind]]
34         @where.delete :tail_kind
35       end
36     end
37   end
38
39   # Overrides ApplicationController load_filters_param
40   def load_filters_param
41     super
42
43     # head_kind and tail_kind columns are now virtual,
44     # equivilent functionality is now provided by
45     # 'is_a', so fix up any old-style 'filter' clauses.
46     @filters = @filters.map do |k|
47       if k[0] == 'head_kind' and k[1] == '='
48         ['head_uuid', 'is_a', k[2]]
49       elsif k[0] == 'tail_kind' and k[1] == '='
50         ['tail_uuid', 'is_a', k[2]]
51       else
52         k
53       end
54     end
55   end
56
57 end