1 class Arvados::V1::LinksController < ApplicationController
3 def check_uuid_kind uuid, kind
4 if kind and ArvadosModel::resource_class_for_uuid(uuid).andand.kind != kind
5 render :json => { errors: ["'#{kind}' does not match uuid '#{uuid}', expected '#{ArvadosModel::resource_class_for_uuid(uuid).andand.kind}'"] }.to_json, status: 422
13 return if ! check_uuid_kind resource_attrs[:head_uuid], resource_attrs[:head_kind]
14 return if ! check_uuid_kind resource_attrs[:tail_uuid], resource_attrs[:tail_kind]
16 resource_attrs.delete :head_kind
17 resource_attrs.delete :tail_kind
22 if current_user.can?(manage: @object)
23 # find all links and return them
24 @objects = Link.where(link_class: "permission",
25 head_uuid: params[:uuid])
27 @limit = @objects.count
30 render :json => { errors: ['Forbidden'] }.to_json, status: 403
36 # Override find_object_by_uuid: the get_permissions method may be
37 # called on a uuid belonging to any class.
38 def find_object_by_uuid
39 if action_name == 'get_permissions'
40 @object = ArvadosModel::resource_class_for_uuid(params[:uuid])
41 .readable_by(*@read_users)
42 .where(uuid: params[:uuid])
49 # Overrides ApplicationController load_where_param
53 # head_kind and tail_kind columns are now virtual,
54 # equivilent functionality is now provided by
55 # 'is_a', so fix up any old-style 'where' clauses.
59 @filters << ['head_uuid', 'is_a', @where[:head_kind]]
60 @where.delete :head_kind
63 @filters << ['tail_uuid', 'is_a', @where[:tail_kind]]
64 @where.delete :tail_kind
69 # Overrides ApplicationController load_filters_param
70 def load_filters_param
73 # head_kind and tail_kind columns are now virtual,
74 # equivilent functionality is now provided by
75 # 'is_a', so fix up any old-style 'filter' clauses.
76 @filters = @filters.map do |k|
77 if k[0] == 'head_kind' and k[1] == '='
78 ['head_uuid', 'is_a', k[2]]
79 elsif k[0] == 'tail_kind' and k[1] == '='
80 ['tail_uuid', 'is_a', k[2]]