forked from ontoportal/ontologies_api
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feature/add-query-logs-endpoints
- Loading branch information
Showing
8 changed files
with
112 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.0.6 | ||
2.7.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'ncbo_cron/graphs_counts' | ||
class AdminGraphsController < ApplicationController | ||
|
||
namespace '/admin' do | ||
GRAPH_COUNT_REPORT_PATH = NcboCron.settings.graphs_counts_report_path | ||
before do | ||
if LinkedData.settings.enable_security && (!env['REMOTE_USER'] || !env['REMOTE_USER'].admin?) | ||
error 403, 'Access denied' | ||
end | ||
end | ||
|
||
get '/graphs' do | ||
output = NcboCron::GraphsCounts.new(nil, GRAPH_COUNT_REPORT_PATH).read_graph_counts | ||
reply output | ||
end | ||
|
||
post '/graphs' do | ||
generate_graphs_counts | ||
reply({ message: 'Graph counts generated', status: 200 }) | ||
end | ||
|
||
delete '/graphs' do | ||
url = params['url'] | ||
error 400, 'You must provide a valid URL for the graph to delete' if url.blank? | ||
Goo.sparql_data_client.delete_graph(url) | ||
generate_graphs_counts | ||
reply({ message: "Graph #{url} deleted", status: 200 }) | ||
end | ||
|
||
def generate_graphs_counts | ||
NcboCron::GraphsCounts.new(nil, GRAPH_COUNT_REPORT_PATH).run | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tools] | ||
ruby = "2.7.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require_relative '../test_case' | ||
|
||
class TestGraphAdminController < TestCase | ||
def setup | ||
ontologies = LinkedData::Models::Ontology.all | ||
if ontologies.empty? | ||
LinkedData::SampleData::Ontology.delete_ontologies_and_submissions | ||
@@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies(process_submission: false) | ||
end | ||
file_path = AdminGraphsController::GRAPH_COUNT_REPORT_PATH | ||
File.delete(file_path) if File.exist?(file_path) | ||
end | ||
|
||
def test_initial_graphs_admin_actions | ||
get '/admin/graphs' | ||
assert last_response.ok? | ||
response = MultiJson.load(last_response.body) | ||
assert_empty response | ||
end | ||
|
||
def test_graph_creation_and_retrieval | ||
post '/admin/graphs' | ||
|
||
get '/admin/graphs' | ||
assert last_response.ok? | ||
response = MultiJson.load(last_response.body) | ||
refute_empty response | ||
|
||
response.each do |graph, count| | ||
assert graph.is_a?(String) | ||
assert count.is_a?(Array) | ||
assert count[0].is_a?(Integer) | ||
assert count[1].is_a?(TrueClass) || count[1].is_a?(FalseClass) | ||
end | ||
end | ||
|
||
def test_graph_deletion | ||
post '/admin/graphs' | ||
|
||
get '/admin/graphs' | ||
response = MultiJson.load(last_response.body) | ||
refute_empty response | ||
|
||
graph = 'http://data.bioontology.org/metadata/OntologySubmission' | ||
|
||
delete '/admin/graphs', url: graph | ||
|
||
get '/admin/graphs' | ||
assert last_response.ok? | ||
response = MultiJson.load(last_response.body) | ||
assert_nil response[graph] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters