Sha256: 7ed490fc2e363aa9eb805f6a049376ade5bcbf9a6222517fb60ca376cecfa9a0

Contents?: true

Size: 1.96 KB

Versions: 24

Compression:

Stored size: 1.96 KB

Contents

class Auth::SearchController < ApplicationController
		

	CONDITIONS_FOR_TOKEN_AUTH = [:authenticated_user_search]

	TCONDITIONS = {:only => CONDITIONS_FOR_TOKEN_AUTH}

	include Auth::Concerns::DeviseConcern	
	include Auth::Concerns::TokenConcern

	before_action :do_before_request, TCONDITIONS
	
			
	## the intention of this action is :
	## to search all records as admin.
	## to search a user's own records if you are user.
	## to search all public records

	## so if the user is an admin, then no resource_id is provided to the search.(basically all records are searched)
	## if he's not an admin, then the lookup_resource user's id is provided.
	
	## this action assumes that the user is signed_in, will return not authenticated otherwise.

	## rendering logic : 
	## @js erb -> renders html erb -> there each result class is detected and the requisite "_search.html.erb" partial is found for that class and rendered.
	## @json => authenticated_user_search.json is rendered.
	## @html => currently does not support html request.
	def authenticated_user_search	
		
		## m client will be available at this stage.
		## the problem is that it is hard to pass it forward to the mongoid elasticsearch object.
		## because while initializing the user it will have to first be set on the user.
		## is there any other way to achieve this?
		query = permitted_params[:query]
		query[:resource_id] = lookup_resource.id.to_s if !current_signed_in_resource.is_admin?
		
		@search_results = Auth::Search::Main.search(query)
		
		puts "these are the search results."
		puts @search_results.to_s

		#dummy_product = Auth.configuration.product_class.constantize.new
		#dummy_product.name = "test product"
		#dummy_product.price = 100.20
		#@search_results = [dummy_product,dummy_product]
		@search_results.each do |res|
			if res.respond_to? :m_client
				res.m_client = self.m_client
			end
		end
		respond_with @search_results
	end



	def permitted_params
		params.permit({query: [:query_string, :size]})
	end


end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
wordjelly-auth-1.2.2 app/controllers/auth/search_controller.rb
wordjelly-auth-1.2.1 app/controllers/auth/search_controller.rb
wordjelly-auth-1.2.0 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.9 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.8 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.7 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.6 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.5 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.4 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.3 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.2 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.1 app/controllers/auth/search_controller.rb
wordjelly-auth-1.1.0 app/controllers/auth/search_controller.rb
wordjelly-auth-1.0.9 app/controllers/auth/search_controller.rb
wordjelly-auth-1.0.8 app/controllers/auth/search_controller.rb
wordjelly-auth-1.0.5 app/controllers/auth/search_controller.rb
wordjelly-auth-1.0.4 app/controllers/auth/search_controller.rb
wordjelly-auth-1.0.3 app/controllers/auth/search_controller.rb
wordjelly-auth-1.0.2 app/controllers/auth/search_controller.rb
wordjelly-auth-0.0.8 app/controllers/auth/search_controller.rb