X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/67816eb0a0b0d2c60072bb002f6a4c294c82b1b1..dabc8e61c00e204e9b03ce8fce4efa4ce9927d8b:/app/controllers/application_controller.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cb71121c75..6b17fb4a30 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,12 +4,14 @@ class ApplicationController < ActionController::Base protect_from_forgery before_filter :uncamelcase_params_hash_keys around_filter :thread_with_auth_info, :except => [:render_error, :render_not_found] - before_filter :find_object_by_uuid, :except => [:index, :create] before_filter :remote_ip before_filter :login_required, :except => :render_not_found - before_filter :catch_redirect_hint + + before_filter :find_objects_for_index, :only => :index + before_filter :find_object_by_uuid, :except => [:index, :create] + attr_accessor :resource_attrs def catch_redirect_hint @@ -49,7 +51,7 @@ class ApplicationController < ActionController::Base render json: { errors: ["Path not found"] }, status: 404 end - def index + def find_objects_for_index uuid_list = [current_user.uuid, *current_user.groups_i_can(:read)] sanitized_uuid_list = uuid_list. collect { |uuid| model_class.sanitize(uuid) }.join(', ') @@ -59,18 +61,18 @@ class ApplicationController < ActionController::Base true, current_user.is_admin, uuid_list, current_user.uuid) + @where = params[:where] || {} + @where = Oj.load(@where) if @where.is_a?(String) if params[:where] - where = params[:where] - where = Oj.load(where) if where.is_a?(String) conditions = ['1=1'] - where.each do |attr,value| + @where.each do |attr,value| if (!value.nil? and attr.to_s.match(/^[a-z][_a-z0-9]+$/) and model_class.columns.collect(&:name).index(attr)) if value.is_a? Array conditions[0] << " and #{table_name}.#{attr} in (?)" conditions << value - else + elsif value.is_a? String or value.is_a? Fixnum or value == true or value == false conditions[0] << " and #{table_name}.#{attr}=?" conditions << value end @@ -96,7 +98,10 @@ class ApplicationController < ActionController::Base else @objects = @objects.limit(100) end - @objects = @objects.order('modified_at desc') + @objects = @objects.order("#{table_name}.modified_at desc") + end + + def index @objects.uniq!(&:id) if params[:eager] and params[:eager] != '0' and params[:eager] != 0 and params[:eager] != '' @objects.each(&:eager_load_associations) @@ -182,8 +187,10 @@ class ApplicationController < ActionController::Base api_client = ApiClient. where('uuid=?',session[:api_client_uuid]). first rescue nil - api_client_auth = ApiClientAuthorization. - find session[:api_client_authorization_id] + if session[:api_client_authorization_id] then + api_client_auth = ApiClientAuthorization. + find session[:api_client_authorization_id] + end end Thread.current[:api_client_trusted] = session[:api_client_trusted] Thread.current[:api_client_ip_address] = remote_ip