Class: Auth::SearchController

Inherits:
ApplicationController show all
Includes:
Concerns::DeviseConcern, Concerns::TokenConcern
Defined in:
app/controllers/auth/search_controller.rb

Constant Summary collapse

CONDITIONS_FOR_TOKEN_AUTH =
[:authenticated_user_search]
TCONDITIONS =
{:only => CONDITIONS_FOR_TOKEN_AUTH}
LAST_FALLBACK =
:none

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_resource!, #build_model_from_params, #check_for_create, #check_for_destroy, #check_for_update, #from_bson, #from_view, #get_model_class_name, #instantiate_classes, #not_found

Instance Method Details

#authenticated_user_searchObject

only option is to set no fallback so that it will just go through. permitted_params is expected to be a hash, which can provide the following arguments :query_string => a string for the query :search_on_field => the field name on which the search can be performed, will default to the ‘tags’ field. :size => the number of results to return, will default to 5.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/auth/search_controller.rb', line 23

def authenticated_user_search	

	## remaining implementation is that a default as_json public has to be set to "no" for everything, and overriding it will be the job of the implementer to set it to "yes"
	## that way a filter is maintained.

	query = permitted_params[:query]

	if current_signed_in_resource
		if current_signed_in_resource.is_admin?
			query[:resource_is_admin] = true
		else
			query[:resource_id] = lookup_resource.id.to_s
		end
	end
	
	@search_results = Auth::Search::Main.search(query)
	
	@search_results.each do |res|
		if res.respond_to? :m_client
			res.m_client = self.m_client
		end
	end

	puts "these are the search results."
	@search_results.each do |result|
		puts result.to_s	
	end

	


	respond_with @search_results
end

#permitted_paramsObject



59
60
61
# File 'app/controllers/auth/search_controller.rb', line 59

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