X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/dc51a3a6a2915d66f1b8f82580637b5733bb49f5..5a3b04f7177afe202ab4f8776b5ca2567b4fdabe:/services/api/app/controllers/arvados/v1/links_controller.rb diff --git a/services/api/app/controllers/arvados/v1/links_controller.rb b/services/api/app/controllers/arvados/v1/links_controller.rb index 188ecfc1a0..798217dc0c 100644 --- a/services/api/app/controllers/arvados/v1/links_controller.rb +++ b/services/api/app/controllers/arvados/v1/links_controller.rb @@ -2,7 +2,8 @@ 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 + send_error("'#{kind}' does not match uuid '#{uuid}', expected '#{ArvadosModel::resource_class_for_uuid(uuid).andand.kind}'", + status: 422) nil else true @@ -18,8 +19,44 @@ class Arvados::V1::LinksController < ApplicationController super end + def get_permissions + if current_user.can?(manage: @object) + # find all links and return them + @objects = Link.where(link_class: "permission", + head_uuid: params[:uuid]) + @offset = 0 + @limit = @objects.count + render_list + else + render :json => { errors: ['Forbidden'] }.to_json, status: 403 + end + end + protected + def find_object_by_uuid + if action_name == 'get_permissions' + # get_permissions accepts a UUID for any kind of object. + @object = ArvadosModel::resource_class_for_uuid(params[:uuid]) + .readable_by(*@read_users) + .where(uuid: params[:uuid]) + .first + else + super + if @object.nil? + # Normally group permission links are not readable_by users. + # Make an exception for users with permission to manage the group. + # FIXME: Solve this more generally - see the controller tests. + link = Link.find_by_uuid(params[:uuid]) + if (not link.nil?) and + (link.link_class == "permission") and + (@read_users.any? { |u| u.can?(manage: link.head_uuid) }) + @object = link + end + end + end + end + # Overrides ApplicationController load_where_param def load_where_param super