1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class Arvados::V1::LinksController < ApplicationController
7 def check_uuid_kind uuid, kind
8 if kind and ArvadosModel::resource_class_for_uuid(uuid).andand.kind != kind
9 send_error("'#{kind}' does not match uuid '#{uuid}', expected '#{ArvadosModel::resource_class_for_uuid(uuid).andand.kind}'",
18 return if ! check_uuid_kind resource_attrs[:head_uuid], resource_attrs[:head_kind]
19 return if ! check_uuid_kind resource_attrs[:tail_uuid], resource_attrs[:tail_kind]
21 resource_attrs.delete :head_kind
22 resource_attrs.delete :tail_kind
27 if current_user.andand.can?(manage: @object)
28 # find all links and return them
29 @objects = Link.where(link_class: "permission",
30 head_uuid: params[:uuid])
32 @limit = @objects.count
35 render :json => { errors: ['Forbidden'] }.to_json, status: 403
41 def find_object_by_uuid
42 if action_name == 'get_permissions'
43 # get_permissions accepts a UUID for any kind of object.
44 @object = ArvadosModel::resource_class_for_uuid(params[:uuid])
45 .readable_by(*@read_users)
46 .where(uuid: params[:uuid])
53 # Overrides ApplicationController load_where_param
57 # head_kind and tail_kind columns are now virtual,
58 # equivalent functionality is now provided by
59 # 'is_a', so fix up any old-style 'where' clauses.
63 @filters << ['head_uuid', 'is_a', @where[:head_kind]]
64 @where.delete :head_kind
67 @filters << ['tail_uuid', 'is_a', @where[:tail_kind]]
68 @where.delete :tail_kind
73 # Overrides ApplicationController load_filters_param
74 def load_filters_param
77 # head_kind and tail_kind columns are now virtual,
78 # equivalent functionality is now provided by
79 # 'is_a', so fix up any old-style 'filter' clauses.
80 @filters = @filters.map do |k|
81 if k[0] == 'head_kind' and k[1] == '='
82 ['head_uuid', 'is_a', k[2]]
83 elsif k[0] == 'tail_kind' and k[1] == '='
84 ['tail_uuid', 'is_a', k[2]]