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 send_error("'#{kind}' does not match uuid '#{uuid}', expected '#{ArvadosModel::resource_class_for_uuid(uuid).andand.kind}'",
14 return if ! check_uuid_kind resource_attrs[:head_uuid], resource_attrs[:head_kind]
15 return if ! check_uuid_kind resource_attrs[:tail_uuid], resource_attrs[:tail_kind]
17 resource_attrs.delete :head_kind
18 resource_attrs.delete :tail_kind
23 if current_user.can?(manage: @object)
24 # find all links and return them
25 @objects = Link.where(link_class: "permission",
26 head_uuid: params[:uuid])
28 @limit = @objects.count
31 render :json => { errors: ['Forbidden'] }.to_json, status: 403
37 def find_object_by_uuid
38 if action_name == 'get_permissions'
39 # get_permissions accepts a UUID for any kind of object.
40 @object = ArvadosModel::resource_class_for_uuid(params[:uuid])
41 .readable_by(*@read_users)
42 .where(uuid: params[:uuid])
47 # Normally group permission links are not readable_by users.
48 # Make an exception for users with permission to manage the group.
49 # FIXME: Solve this more generally - see the controller tests.
50 link = Link.find_by_uuid(params[:uuid])
51 if (not link.nil?) and
52 (link.link_class == "permission") and
53 (@read_users.any? { |u| u.can?(manage: link.head_uuid) })
60 # Overrides ApplicationController load_where_param
64 # head_kind and tail_kind columns are now virtual,
65 # equivilent functionality is now provided by
66 # 'is_a', so fix up any old-style 'where' clauses.
70 @filters << ['head_uuid', 'is_a', @where[:head_kind]]
71 @where.delete :head_kind
74 @filters << ['tail_uuid', 'is_a', @where[:tail_kind]]
75 @where.delete :tail_kind
80 # Overrides ApplicationController load_filters_param
81 def load_filters_param
84 # head_kind and tail_kind columns are now virtual,
85 # equivilent functionality is now provided by
86 # 'is_a', so fix up any old-style 'filter' clauses.
87 @filters = @filters.map do |k|
88 if k[0] == 'head_kind' and k[1] == '='
89 ['head_uuid', 'is_a', k[2]]
90 elsif k[0] == 'tail_kind' and k[1] == '='
91 ['tail_uuid', 'is_a', k[2]]