Skip to content
Snippets Groups Projects
Unverified Commit 697f8d93 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

clean

parent c2a169de
No related branches found
No related tags found
No related merge requests found
......@@ -10,10 +10,22 @@ class PolymorphicObjectFinder
def self.find(params, key:, university:, only: [])
key_id = "#{key}_id".to_sym
key_type = "#{key}_type".to_sym
model_name = only.any? ? only.detect { |item| item == params[key_type] } : params[key_type]
model_name = self.find_model_name(params, key_type, only)
return if model_name.nil?
model = model_name.constantize
id = params[key_id]
model.where(university: university).find(id)
end
private
def self.find_model_name(params, key_type, only)
if only.any?
# Whitelist user input
only.detect { |item| item == params[key_type] }
else
params[key_type]
end
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment