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

Upgrade ontologies_api_client library #324

Merged
merged 6 commits into from
Sep 5, 2024
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ gem 'iso-639', '~> 0.3.6'
gem 'multi_json'
gem 'mysql2', '0.5.5'
gem 'oj'
gem 'ontologies_api_client', github: 'ncbo/ontologies_api_ruby_client', tag: 'v2.3.0'
gem 'ontologies_api_client', github: 'ncbo/ontologies_api_ruby_client', tag: 'v2.4.0'
gem 'open_uri_redirections'
gem 'pry'
gem 'psych', '< 4'
Expand Down
8 changes: 3 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GIT
remote: https://github.com/ncbo/ontologies_api_ruby_client.git
revision: 027c749f5de3f644b0392197e9482be51738cbe8
tag: v2.3.0
revision: f589b13dfbbc133ea67cbae1a8f92b41ea85c14b
tag: v2.4.0
specs:
ontologies_api_client (2.2.5)
ontologies_api_client (2.4.0)
activesupport (= 7.0.8)
addressable (~> 2.8)
excon
Expand All @@ -13,7 +13,6 @@ GIT
lz4-ruby
multi_json
oj
spawnling (= 2.1.5)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -352,7 +351,6 @@ GEM
tilt
select2-rails (4.0.13)
sexp_processor (4.17.0)
spawnling (2.1.5)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def create

def edit
# Note: find_by_acronym includes ontology views
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:id]).first
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:id], include: 'all').first
redirect_to_home unless session[:user] && @ontology.administeredBy.include?(session[:user].id) || session[:user].admin?
@categories = LinkedData::Client::Models::Category.all
@user_select_list = LinkedData::Client::Models::User.all.map {|u| [u.username, u.id]}
Expand Down Expand Up @@ -254,9 +254,9 @@ def show
end

# Note: find_by_acronym includes ontology views
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology], include: 'all').first
not_found if @ontology.nil?

# Handle the case where an ontology is converted to summary only.
# See: https://github.com/ncbo/bioportal_web_ui/issues/133.
if @ontology.summaryOnly && params[:p].present?
Expand Down Expand Up @@ -313,7 +313,7 @@ def show
end

def submit_success
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:id]).first
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:id], include: 'all').first
render 'submit_success'
end

Expand Down Expand Up @@ -345,9 +345,9 @@ def update
return
end
# Note: find_by_acronym includes ontology views
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology][:acronym] || params[:id]).first
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:id]).first
@ontology.update_from_params(ontology_params)
error_response = @ontology.update
error_response = @ontology.update(cache_refresh_all: false)
if response_error?(error_response)
@categories = LinkedData::Client::Models::Category.all
@user_select_list = LinkedData::Client::Models::User.all.map {|u| [u.username, u.id]}
Expand Down
45 changes: 10 additions & 35 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@ def index
end

def show
projects = LinkedData::Client::Models::Project.find_by_acronym(params[:id])
if projects.blank?
flash.alert = "Project not found: #{params[:id]}"
redirect_to projects_path
return
end

@project = projects.first
@project = LinkedData::Client::Models::Project.get(params[:id])
@ontologies_used = []
onts_used = @project.ontologyUsed
onts_used.each do |ont_used|
ont = LinkedData::Client::Models::Ontology.find(ont_used)
ont = LinkedData::Client::Models::Ontology.get(ont_used, include: 'name,acronym')
@ontologies_used << Hash['name', ont.name, 'acronym', ont.acronym] unless ont.nil?
end
@ontologies_used.sort_by! { |o| o['name'].downcase }
Expand All @@ -45,13 +38,7 @@ def new
end

def edit
projects = LinkedData::Client::Models::Project.find_by_acronym(params[:id])
if projects.blank?
flash.alert = "Project not found: #{params[:id]}"
redirect_to projects_path
return
end
@project = projects.first
@project = LinkedData::Client::Models::Project.get(params[:id])
@user_select_list = LinkedData::Client::Models::User.all.map { |u| [u.username, u.id] }
@user_select_list.sort! { |a, b| a[1].downcase <=> b[1].downcase }
@usedOntologies = @project.ontologyUsed || []
Expand Down Expand Up @@ -84,21 +71,15 @@ def create
end

def update
projects = LinkedData::Client::Models::Project.find_by_acronym(params[:id])
if projects.blank?
flash.alert = "Project not found: #{params[:id]}"
redirect_to projects_path
return
end
@project = projects.first
@project = LinkedData::Client::Models::Project.get(params[:id])
@project.update_from_params(project_params)
@user_select_list = LinkedData::Client::Models::User.all.map { |u| [u.username, u.id] }
@user_select_list.sort! { |a, b| a[1].downcase <=> b[1].downcase }
@usedOntologies = @project.ontologyUsed || []
@ontologies = LinkedData::Client::Models::Ontology.all
error_response = @project.update
error_response = @project.update(cache_refresh_all: false)
if response_error?(error_response)
@errors = response_errors(error_response)
@user_select_list = LinkedData::Client::Models::User.all.map { |u| [u.username, u.id] }
@user_select_list.sort! { |a, b| a[1].downcase <=> b[1].downcase }
@usedOntologies = @project.ontologyUsed || []
@ontologies = LinkedData::Client::Models::Ontology.all
render :edit
else
flash[:notice] = 'Project successfully updated'
Expand All @@ -107,13 +88,7 @@ def update
end

def destroy
projects = LinkedData::Client::Models::Project.find_by_acronym(params[:id])
if projects.blank?
flash.alert = "Project not found: #{params[:id]}"
redirect_to projects_path
return
end
@project = projects.first
@project = LinkedData::Client::Models::Project.get(params[:id])
error_response = @project.delete
if response_error?(error_response)
@errors = response_errors(error_response)
Expand Down
11 changes: 2 additions & 9 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@ class SubmissionsController < ApplicationController
before_action :authorize_and_redirect, only: [:edit, :update, :create, :new]

def new
begin
# REVIEW: do we really need this double attempt to locate an ontology? I think find_by_acronym (below) should
# be sufficient. It's not evident that we call the new method with a full URI anymore.
@ontology = LinkedData::Client::Models::Ontology.get(CGI.unescape(params[:ontology_id]))
rescue MultiJson::ParseError
nil
end

@ontology ||= LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id]).first
# NOTE: find_by_acronym includes ontology views
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id]).first
@submission = @ontology.explore.latest_submission
@submission ||= LinkedData::Client::Models::OntologySubmission.new
end
Expand Down
20 changes: 6 additions & 14 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ def index
end

def show
@user = if session[:user].admin? && params.has_key?(:id)
LinkedData::Client::Models::User.find_by_username(params[:id]).first
else
LinkedData::Client::Models::User.find(session[:user].id)
end
@user = LinkedData::Client::Models::User.get(params[:id], include: 'all')
@all_ontologies = LinkedData::Client::Models::Ontology.all(ignore_custom_ontologies: true)
@user_ontologies = @user.customOntology

Expand All @@ -41,8 +37,7 @@ def new
end

def edit
@user = LinkedData::Client::Models::User.find(params[:id])
@user ||= LinkedData::Client::Models::User.find_by_username(params[:id]).first
@user = LinkedData::Client::Models::User.get(params[:id], include: 'all')
end

def create
Expand All @@ -58,16 +53,15 @@ def create
else
flash[:notice] = 'Account was successfully created'
session[:user] = LinkedData::Client::Models::User.authenticate(@user.username, @user.password)
redirect_to_browse
redirect_to user_path(@user.username)
end
else
render 'new'
end
end

def update
@user = LinkedData::Client::Models::User.find(params[:id])
@user = LinkedData::Client::Models::User.find_by_username(params[:id]).first if @user.nil?
@user = LinkedData::Client::Models::User.get(params[:id], include: 'all')

@errors = validate_update(user_params)
if @errors.empty?
Expand All @@ -78,7 +72,7 @@ def update
end

@user.update_from_params(user_params.merge!(role: user_roles))
error_response = @user.update
error_response = @user.update(cache_refresh_all: false)

if response_error?(error_response)
@errors = response_errors(error_response)
Expand All @@ -99,12 +93,10 @@ def update

def destroy
response = { errors: String.new(''), success: String.new('') }
@user = LinkedData::Client::Models::User.find(params[:id])
@user = LinkedData::Client::Models::User.find_by_username(params[:id]).first if @user.nil?
@user = LinkedData::Client::Models::User.get(params[:id])
if session[:user].admin?
@user.delete
response[:success] << 'User deleted successfully '

else
response[:errors] << 'Not permitted '
end
Expand Down
4 changes: 1 addition & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def clean_id(string)
end

def get_username(user_id)
user = LinkedData::Client::Models::User.find(user_id)
username = user.nil? ? user_id : user.username
username
user_id.split('/').last
end

def current_user_admin?
Expand Down
Loading