Skip to content

Commit

Permalink
Merge branch 'development' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Apr 7, 2024
2 parents 139fb8e + 16024fb commit 7128e3c
Show file tree
Hide file tree
Showing 17 changed files with 542 additions and 38 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Docker branch Images build
on:
push:
branches:
- master
- development
- stage
- test
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
openjdk-11-jre-headless \
raptor2-utils \
wait-for-it \
libraptor2-dev \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /srv/ontoportal/ontologies_api
Expand All @@ -24,4 +25,4 @@ COPY . /srv/ontoportal/ontologies_api
RUN cp /srv/ontoportal/ontologies_api/config/environments/config.rb.sample /srv/ontoportal/ontologies_api/config/environments/development.rb

EXPOSE 9393
CMD ["bundle", "exec", "rackup", "-p", "9393", "--host", "0.0.0.0"]
CMD ["bundle", "exec", "rackup", "-p", "9393", "--host", "0.0.0.0"]
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gem 'request_store'
gem 'parallel'
gem 'json-ld'


# Rack middleware
gem 'ffi'
gem 'rack-accept', '~> 0.4'
Expand Down
36 changes: 21 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: 3f8b1f0b62c4334306f9ed5cb7b17a1b645e7db3
revision: 0e554fce49713ce4d5a742a06c2fb59a547caf47
branch: development
specs:
goo (0.0.2)
Expand Down Expand Up @@ -57,7 +57,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: 337dce98ec27627d14a440ff2a6ed09483cdac12
revision: 026c9c46baf6c0d638568528c2adcb7bcb1c2796
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -117,7 +117,7 @@ GEM
bcrypt_pbkdf (1.1.0)
bigdecimal (1.4.2)
builder (3.2.4)
capistrano (3.18.0)
capistrano (3.18.1)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
Expand Down Expand Up @@ -183,7 +183,7 @@ GEM
google-cloud-errors (~> 1.0)
google-apis-analytics_v3 (0.15.0)
google-apis-core (>= 0.14.0, < 2.a)
google-apis-core (0.14.0)
google-apis-core (0.14.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
httpclient (>= 2.8.1, < 3.a)
Expand All @@ -197,12 +197,13 @@ GEM
google-cloud-env (2.1.1)
faraday (>= 1.0, < 3.a)
google-cloud-errors (1.4.0)
google-protobuf (3.25.3-x86_64-darwin)
google-protobuf (3.25.3-x86_64-linux)
googleapis-common-protos (1.5.0)
google-protobuf (~> 3.18)
googleapis-common-protos-types (~> 1.7)
grpc (~> 1.41)
googleapis-common-protos-types (1.13.0)
googleapis-common-protos-types (1.14.0)
google-protobuf (~> 3.18)
googleauth (1.11.0)
faraday (>= 1.0, < 3.a)
Expand All @@ -211,6 +212,9 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
grpc (1.62.0-x86_64-darwin)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
grpc (1.62.0-x86_64-linux)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
Expand All @@ -225,17 +229,17 @@ GEM
httpclient (2.8.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json (2.7.1)
json (2.7.2)
json-ld (3.0.2)
multi_json (~> 1.12)
rdf (>= 2.2.8, < 4.0)
json-schema (2.8.1)
addressable (>= 2.4)
json_pure (2.7.1)
json_pure (2.7.2)
jwt (2.8.1)
base64
kgio (2.11.4)
libxml-ruby (5.0.2)
libxml-ruby (5.0.3)
link_header (0.0.8)
logger (1.6.0)
macaddr (1.7.2)
Expand Down Expand Up @@ -269,11 +273,11 @@ GEM
net-ssh (>= 2.6.5, < 8.0.0)
net-sftp (4.0.0)
net-ssh (>= 5.0.0, < 8.0.0)
net-smtp (0.4.0.1)
net-smtp (0.5.0)
net-protocol
net-ssh (7.2.1)
net-ssh (7.2.3)
netrc (0.11.0)
newrelic_rpm (9.7.1)
newrelic_rpm (9.8.0)
oj (2.18.5)
omni_logger (0.1.4)
logger
Expand All @@ -285,7 +289,7 @@ GEM
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.4)
public_suffix (5.0.5)
rack (1.6.13)
rack-accept (0.4.5)
rack (>= 0.4)
Expand Down Expand Up @@ -342,7 +346,7 @@ GEM
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.2.6)
rsolr (2.5.0)
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
ruby-xxHash (0.4.0.2)
Expand Down Expand Up @@ -377,7 +381,8 @@ GEM
rack-test
sinatra (~> 1.4.0)
tilt (>= 1.3, < 3)
sshkit (1.22.0)
sshkit (1.22.1)
base64
mutex_m
net-scp (>= 1.1.2)
net-sftp (>= 2.1.2)
Expand All @@ -404,6 +409,7 @@ GEM
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
x86_64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down Expand Up @@ -462,4 +468,4 @@ DEPENDENCIES
webmock (~> 3.19.1)

BUNDLED WITH
2.3.15
2.4.22
2 changes: 0 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
require 'oj'
require 'multi_json'
require 'cgi'
require 'google/apis/analytics_v3'
require 'google/api_client/auth/key_utils'

# NCBO dependencies
require 'ontologies_linked_data'
Expand Down
5 changes: 3 additions & 2 deletions bin/ontoportal
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ build_docker_run_cmd() {
local goo_path="$3"
local sparql_client_path="$4"

local docker_run_cmd="docker compose run --rm -it"
local docker_run_cmd="docker compose -p ontoportal_docker run --rm -it --name api-service"
local bash_cmd=""

# Conditionally add bind mounts only if the paths are not empty
Expand All @@ -100,6 +100,7 @@ build_docker_run_cmd() {
eval "$docker_run_cmd"
}


# Function to handle the "dev" and "test" options
run_command() {
local custom_command="$1"
Expand Down Expand Up @@ -177,7 +178,7 @@ run_command() {
dev() {
echo "Starting OntoPortal API development server..."

local custom_command="bundle exec shotgun --host 0.0.0.0 --env=development"
local custom_command="bundle exec shotgun --host 0.0.0.0 --env=development --port 9393"
run_command "$custom_command" "$@"
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/analytics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'csv'

class OntologyAnalyticsController < ApplicationController
class AnalyticsController < ApplicationController

##
# get all ontology analytics for a given year/month combination
# TODO use a namespace analytics after migration the old OntologyAnalyticsController
namespace "/data/analytics" do

get 'ontologies' do
get '/ontologies' do
expires 86400, :public
year = year_param(params)
error 400, "The year you supplied is invalid. Valid years start with 2 and contain 4 digits." if params["year"] && !year
Expand All @@ -20,7 +20,7 @@ class OntologyAnalyticsController < ApplicationController
end


get 'users' do
get '/users' do
expires 86400, :public
year = year_param(params)
error 400, "The year you supplied is invalid. Valid years start with 2 and contain 4 digits." if params["year"] && !year
Expand All @@ -30,7 +30,7 @@ class OntologyAnalyticsController < ApplicationController
reply analytics['all_users']
end

get 'page_visits' do
get '/page_visits' do
expires 86400, :public
year = year_param(params)
error 400, "The year you supplied is invalid. Valid years start with 2 and contain 4 digits." if params["year"] && !year
Expand Down
55 changes: 55 additions & 0 deletions controllers/dereference_resource_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require_relative '../test/test_case'

use Rack::ContentNegotiation

class DereferenceResourceController < ApplicationController
namespace "/ontologies" do
get "/:acronym/resolve/:uri" do
acronym = params[:acronym]
uri = params[:uri]

if acronym.blank? || uri.blank?
error 500, "Usage: ontologies/:acronym/resolve/:uri?output_format= OR POST: acronym, uri, output_format parameters"
end

output_format = env["format"].presence || params[:output_format].presence || 'application/n-triples'

process_request(acronym, uri, output_format)
end

private

def process_request(acronym_param, uri_param, output_format)
acronym = acronym_param
uri = URI.decode_www_form_component(uri_param)

error 500, "INVALID URI" unless valid_url?(uri)
sub = LinkedData::Models::Ontology.find(acronym).first&.latest_submission

error 500, "Ontology not found" unless sub

r = Resource.new(sub.id, uri)
case output_format
when 'application/ld+json', 'application/json'
r.to_json
when 'application/rdf+xml', 'application/xml'
r.to_xml
when 'text/turtle'
r.to_turtle
when 'application/n-triples'
r.to_ntriples
else
error 500, "Invalid output format, valid format are: application/json, application/ld+json, application/xml, application/rdf+xml, text/turtle and application/n-triples"
end


end

def valid_url?(url)
uri = URI.parse(url)
uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
rescue URI::InvalidURIError
false
end
end
end
5 changes: 4 additions & 1 deletion controllers/slices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ class SlicesController < ApplicationController
##
# Create a new slice
post do
error 403, "Access denied" unless current_user && current_user.admin?
create_slice
end

# Delete a slice
delete '/:slice' do
error 403, "Access denied" unless current_user && current_user.admin?
LinkedData::Models::Slice.find(params[:slice]).first.delete
halt 204
end

# Update an existing slice
patch '/:slice' do
error 403, "Access denied" unless current_user && current_user.admin?
slice = LinkedData::Models::Slice.find(params[:slice]).include(LinkedData::Models::Slice.attributes(:all)).first
populate_from_params(slice, params)
if slice.valid?
Expand All @@ -61,7 +64,7 @@ class SlicesController < ApplicationController
end
halt 204
end

private

def create_slice
Expand Down
2 changes: 2 additions & 0 deletions controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class UsersController < ApplicationController
# Update an existing submission of an user
patch '/:username' do
user = User.find(params[:username]).include(User.attributes).first
params.delete("role") unless current_user.admin?
populate_from_params(user, params)
if user.valid?
user.save
Expand All @@ -102,6 +103,7 @@ def create_user
params ||= @params
user = User.find(params["username"]).first
error 409, "User with username `#{params["username"]}` already exists" unless user.nil?
params.delete("role") unless current_user.admin?
user = instance_from_params(User, params)
if user.valid?
user.save(send_notifications: false)
Expand Down
4 changes: 1 addition & 3 deletions helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def send_reset_token(email, username)
error 404, "User not found" unless user
reset_token = token(36)
user.resetToken = reset_token

return user if user.valid?


user.save(override_security: true)
LinkedData::Utils::Notifications.reset_password(user, reset_token)
user
Expand Down
Loading

0 comments on commit 7128e3c

Please sign in to comment.