1 class Arvados::V1::ApiClientAuthorizationsController < ApplicationController
2 before_filter :current_api_client_is_trusted
6 def find_objects_for_index
7 # Here we are deliberately less helpful about searching for client
8 # authorizations. Rather than use the generic index/where/order
9 # featuers, we look up tokens belonging to the current user and
10 # filter by exact match on api_token (which we expect in the form
11 # of a where[uuid] parameter to make things easier for API client
13 @objects = model_class.
14 includes(:user, :api_client).
15 where('user_id=? and (? or api_token=?)', current_user.id, !@where['uuid'], @where['uuid']).
16 order('created_at desc')
19 def find_object_by_uuid
20 # Again, to make things easier for the client and our own routing,
21 # here we look for the api_token key in a "uuid" (POST) or "id"
23 @object = model_class.where('api_token=?', params[:uuid] || params[:id]).first
26 def current_api_client_is_trusted
27 unless Thread.current[:api_client].andand.is_trusted
28 render :json => { errors: ['Forbidden: this API client cannot manipulate other clients\' access tokens.'] }.to_json, status: 403