Skip to content

Commit

Permalink
implemented #127 - Add API call to trigger ontology pull from remote …
Browse files Browse the repository at this point in the history
…location
  • Loading branch information
mdorf committed Jan 10, 2024
1 parent 34a876c commit f147504
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
17 changes: 0 additions & 17 deletions controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,6 @@ class AdminController < ApplicationController
halt 204
end

# on demand ontology pull
post "/ontologies/:acronym/pull" do
LOGGER.info "Forcing the pull and processing of ontology #{params['acronym']}"
actions = NcboCron::Models::OntologySubmissionParser::ACTIONS.dup
actions[:remote_pull] = true
ont = Ontology.find(params["acronym"]).first
error 404, "You must provide a valid `acronym` to retrieve an ontology" if ont.nil?
ont.bring(:acronym, :submissions)
latest = ont.latest_submission(status: :any)
error 404, "Ontology #{params["acronym"]} contains no submissions" if latest.nil?
check_last_modified(latest)
latest.bring(*OntologySubmission.goo_attrs_to_load(includes_param))
NcboCron::Models::OntologySubmissionParser.new.queue_submission(latest, actions)
LOGGER.info "Ontology #{params['acronym']} has been queued for pull and processing"
halt 204
end

private

def process_long_operation(timeout, args)
Expand Down
19 changes: 19 additions & 0 deletions controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ class OntologiesController < ApplicationController
reply(latest || {})
end

# on demand ontology pull
post "/:acronym/pull" do
LOGGER.info "Forcing the pull and processing of ontology #{params['acronym']}"
actions = NcboCron::Models::OntologySubmissionParser::ACTIONS.dup
actions[:remote_pull] = true
ont = Ontology.find(params["acronym"]).first
error 404, "You must provide a valid `acronym` to retrieve an ontology" if ont.nil?
ont.bring(:acronym, :submissions, :viewingRestriction, :administeredBy)
check_write_access(ont)
latest = ont.latest_submission(status: :any)
error 404, "Ontology #{params["acronym"]} contains no submissions" if latest.nil?
check_last_modified(latest)
latest.bring(*OntologySubmission.goo_attrs_to_load(includes_param))
error 404, "Ontology #{params["acronym"]} is not configured to be remotely pulled" unless latest.remote_pulled?
NcboCron::Models::OntologySubmissionParser.new.queue_submission(latest, actions)
LOGGER.info "Ontology #{params['acronym']} has been queued for pull and processing"
halt 204
end

##
# Create an ontology
post do
Expand Down
2 changes: 1 addition & 1 deletion helpers/access_control_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def check_access(obj)
# For a given object, check if the current user has permission to perform writes.
def check_write_access(obj)
return obj unless LinkedData.settings.enable_security
if obj.is_a?(LinkedData::Models::Base) && obj.write_restricted?
if obj.is_a?(LinkedData::Models::Base)
writable = obj.writable?(env["REMOTE_USER"])
error 403, "Access denied for this resource" unless writable
end
Expand Down

0 comments on commit f147504

Please sign in to comment.