Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove $LEGACY_REST_URL environment variable and associated code #276

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 12 additions & 37 deletions app/controllers/ajax_proxy_controller.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,26 @@
# frozen_string_literal: true

require 'open-uri'
require 'net/http'
require 'uri'
require 'cgi'

class AjaxProxyController < ApplicationController


def get

page = open(params[:url])
content = page.read
render :text => content

end

def jsonp
if params[:apikey].nil? || params[:apikey].empty?
render_json '{ "error": "Must supply apikey" }'
return
end

if params[:path].nil? || params[:path].empty?
render_json '{ "error": "Must supply path" }'
return
end

url = URI.parse($LEGACY_REST_URL + params[:path])
url.port = $REST_PORT.to_i
full_path = (url.query.blank?) ? url.path : "#{url.path}?#{url.query}"
full_path = full_path.include?("?") ? full_path + "&apikey=#{params[:apikey]}&userapikey=#{params[:userapikey]}" : full_path + "?apikey=#{params[:apikey]}&userapikey=#{params[:userapikey]}"
http = Net::HTTP.new(url.host, url.port)
headers = { "Accept" => "application/json" }
res = http.get(full_path, headers)
response = res.code.to_i >= 400 ? { :status => res.code.to_i, :body => res.body }.to_json : res.body
render_json response, {:status => 200}
content = page.read
render text: content
end

def json_class
not_found if params[:conceptid].nil? || params[:conceptid].empty?
params[:ontology] ||= params[:ontologyid]

if params[:ontologyid].to_i > 0
params_cleanup_new_api()
stop_words = ["controller", "action", "ontologyid"]
redirect_to "#{request.path}#{params_string_for_redirect(params, stop_words: stop_words)}", :status => :moved_permanently
if params[:ontologyid].to_i.positive?
params_cleanup_new_api
stop_words = %w[controller action ontologyid]
redirect_to "#{request.path}#{params_string_for_redirect(params, stop_words: stop_words)}",
status: :moved_permanently
return
end

Expand All @@ -56,7 +33,6 @@
render_json @concept.to_json
end


def json_ontology
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
not_found if @ontology.nil?
Expand All @@ -65,12 +41,12 @@
end

def loading_spinner
render :partial => "loading_spinner"
render partial: 'loading_spinner'
end

private

def render_json(json, options={})
def render_json(json, options = {})
callback, variable = params[:callback], params[:variable]
response = begin
if callback && variable
Expand All @@ -83,7 +59,6 @@
json
end
end
render({plain: response, content_type: "application/json"}.merge(options))
render({ plain: response, content_type: 'application/json' }.merge(options))

Check notice

Code scanning / Brakeman

Render path contains parameter value. Note

Render path contains parameter value.
end

end
3 changes: 0 additions & 3 deletions config/bioportal_config_env.rb.sample
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ $ONTOLOBRIDGE_AUTHENTICATION_TOKEN = "Token Uq2pae73ktMtmgjUgtnhEOuHxr9sZeuK"
# Ontologies for which to enable the new term request (Ontolobridge) tab
$NEW_TERM_REQUEST_ONTOLOGIES = []

# Legacy REST core service address (BioPortal v3.x and lower)
$LEGACY_REST_URL = "http://example.org:8080/bioportal"

# Max number of children to return when rendering a tree view
$MAX_CHILDREN = 2500

Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
get '/ajax/mappings/get_concept_table' => 'mappings#get_concept_table'
get '/ajax/json_ontology' => 'ajax_proxy#json_ontology'
get '/ajax/json_class' => 'ajax_proxy#json_class'
get '/ajax/jsonp' => 'ajax_proxy#jsonp'
get '/ajax/loading_spinner' => 'ajax_proxy#loading_spinner'
get '/ajax/notes/delete' => 'notes#destroy'
get '/ajax/notes/concept_list' => 'notes#show_concept_list'
Expand Down
Loading