diff --git a/.github/workflows/brakeman-analysis.yml b/.github/workflows/brakeman-analysis.yml index 6ad197b9b..007b47d01 100644 --- a/.github/workflows/brakeman-analysis.yml +++ b/.github/workflows/brakeman-analysis.yml @@ -22,12 +22,10 @@ jobs: # Customize the ruby version depending on your needs - name: Setup Ruby uses: ruby/setup-ruby@v1 - with: - ruby-version: '2.7' - name: Setup Brakeman env: - BRAKEMAN_VERSION: '5.4.0' # SARIF support is provided in Brakeman version 4.10+ + BRAKEMAN_VERSION: '6.0.1' # SARIF support is provided in Brakeman version 4.10+ run: | gem install brakeman --version $BRAKEMAN_VERSION diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2e6a91b0d..b72147a94 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -59,7 +59,6 @@ jobs: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7.7 # Not needed with a .ruby-version file bundler-cache: true # runs 'bundle install' and caches installed gems automatically - name: get-deployment-config uses: actions/checkout@v3 @@ -75,7 +74,7 @@ jobs: mkdir -p ~/.ssh ssh-keyscan -H ${{ secrets.SSH_JUMPHOST }} > ~/.ssh/known_hosts shell: bash - - uses: miloserdow/capistrano-deploy@master + - uses: miloserdow/capistrano-deploy@v3 with: target: ${{ env.TARGET }} # which environment to deploy deploy_key: ${{ secrets.DEPLOY_ENC_KEY }} # Name of the variable configured in Settings/Secrets of your github project diff --git a/.gitignore b/.gitignore index 2dd14061d..eaa496d6f 100644 --- a/.gitignore +++ b/.gitignore @@ -25,8 +25,6 @@ config/deploy/* /public/assets/ nohup.out -.ruby-version - # Ignore editor files .idea *.swp diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000..818bd47ab --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.0.6 diff --git a/Capfile b/Capfile index 8cbf6f87e..27ce9e289 100644 --- a/Capfile +++ b/Capfile @@ -15,7 +15,7 @@ require 'capistrano/deploy' # https://github.com/capistrano/rails # # require 'capistrano/rvm' -# require 'capistrano/rbenv' +require 'capistrano/rbenv' # require 'capistrano/chruby' require 'capistrano/bundler' require "capistrano/scm/git" @@ -23,8 +23,7 @@ install_plugin Capistrano::SCM::Git #require 'capistrano/rails/assets' #require 'capistrano/rails/migrations' require 'capistrano/rails' -require 'capistrano/yarn' require 'capistrano/locally' - +require 'capistrano/yarn' # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } diff --git a/Gemfile b/Gemfile index 0bc71128f..c06158c33 100644 --- a/Gemfile +++ b/Gemfile @@ -34,7 +34,7 @@ gem 'haml', '~> 5.1' gem 'i18n' gem 'iconv' gem 'multi_json' -gem 'mysql2', '0.5.2' +gem 'mysql2', '0.5.5' gem 'oj' gem 'open_uri_redirections' gem 'pry' @@ -44,6 +44,7 @@ gem 'rails_autolink' gem 'rdoc' gem 'recaptcha', '~> 5.9.0' gem 'rest-client' +gem 'rexml', '~> 3' gem 'stackprof', require: false gem 'thin' gem 'will_paginate', '~> 3.0' @@ -61,8 +62,9 @@ end group :development do # Capistrano Deployment gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0', require: false # https://github.com/miloserdow/capistrano-deploy/issues/42 - gem 'capistrano', '~> 3.11', require: false + gem 'capistrano', '~> 3.17', require: false gem 'capistrano-bundler', require: false + gem 'capistrano-rbenv', require: false gem 'capistrano-locally', require: false gem 'capistrano-passenger', require: false gem 'capistrano-rails', '~> 1.4', require: false diff --git a/Gemfile.lock b/Gemfile.lock index d55370d2e..885e31aa7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,17 +79,18 @@ GEM zeitwerk (~> 2.3) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) - airbrussh (1.4.1) + airbrussh (1.4.2) sshkit (>= 1.6.1, != 1.7.0) ast (2.4.2) autoprefixer-rails (10.4.13.0) execjs (~> 2) + base64 (0.1.1) bcrypt_pbkdf (1.1.0) bootstrap (4.1.3) autoprefixer-rails (>= 6.0.3) popper_js (>= 1.12.9, < 2) sass (>= 3.5.2) - brakeman (5.4.1) + brakeman (6.0.1) builder (3.2.4) capistrano (3.17.3) airbrussh (>= 1.0.0) @@ -105,6 +106,9 @@ GEM capistrano-rails (1.6.3) capistrano (~> 3.1) capistrano-bundler (>= 1.1, < 3) + capistrano-rbenv (2.2.0) + capistrano (~> 3.1) + sshkit (~> 1.3) capistrano-yarn (2.0.2) capistrano (~> 3.0) capybara (3.39.2) @@ -132,7 +136,7 @@ GEM erubi (1.12.0) erubis (2.7.0) eventmachine (1.2.7) - excon (0.100.0) + excon (0.102.0) execjs (2.8.1) faraday (2.7.10) faraday-net_http (>= 2.0, < 3.1) @@ -147,7 +151,7 @@ GEM flamegraph (0.9.5) globalid (1.1.0) activesupport (>= 5.0) - graphql (2.0.25) + graphql (2.0.26) graphql-client (0.18.0) activesupport (>= 3.0) graphql @@ -188,14 +192,14 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) - mime-types (3.5.0) + mime-types (3.5.1) mime-types-data (~> 3.2015) - mime-types-data (3.2023.0218.1) - mini_mime (1.1.2) + mime-types-data (3.2023.0808) + mini_mime (1.1.5) minitest (5.19.0) multi_json (1.15.0) multipart-post (2.3.0) - mysql2 (0.5.2) + mysql2 (0.5.5) net-imap (0.3.7) date net-protocol @@ -209,13 +213,15 @@ GEM net-protocol net-ssh (7.2.0) netrc (0.11.0) - newrelic_rpm (9.3.1) + newrelic_rpm (9.4.2) nio4r (2.5.9) - nokogiri (1.15.3-x86_64-darwin) + nokogiri (1.15.4-arm64-darwin) + racc (~> 1.4) + nokogiri (1.15.4-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.3-x86_64-linux) + nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) - oj (3.15.1) + oj (3.16.0) open_uri_redirections (0.2.1) parallel (1.23.0) parser (3.2.2.3) @@ -297,7 +303,8 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) - rubocop (1.55.1) + rubocop (1.56.2) + base64 (~> 0.1.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -364,6 +371,7 @@ GEM zeitwerk (2.6.11) PLATFORMS + arm64-darwin-22 x86_64-darwin-21 x86_64-linux @@ -371,11 +379,12 @@ DEPENDENCIES bcrypt_pbkdf (>= 1.0, < 2.0) bootstrap (~> 4.1.0) brakeman - capistrano (~> 3.11) + capistrano (~> 3.17) capistrano-bundler capistrano-locally capistrano-passenger capistrano-rails (~> 1.4) + capistrano-rbenv capistrano-yarn capybara chart-js-rails @@ -392,7 +401,7 @@ DEPENDENCIES jquery-ui-rails listen multi_json - mysql2 (= 0.5.2) + mysql2 (= 0.5.5) newrelic_rpm oj ontologies_api_client! @@ -405,6 +414,7 @@ DEPENDENCIES rdoc recaptcha (~> 5.9.0) rest-client + rexml (~> 3) rspec-rails rubocop sass-rails (~> 5.0) @@ -415,4 +425,4 @@ DEPENDENCIES will_paginate (~> 3.0) BUNDLED WITH - 2.3.22 + 2.4.18 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 04f03e28f..488cbda5a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,4 @@ require 'uri' -require 'open-uri' require 'net/http' require 'net/https' require 'net/ftp' @@ -29,6 +28,8 @@ class ApplicationController < ActionController::Base EXPIRY_RECENT_MAPPINGS = 60 * 60 # 1:00 hours EXPIRY_ONTOLOGY_SIMPLIFIED = 60 * 1 # 0:01 minute + RETRY_LIMIT = 1 + $trial_license_initialized = false if !$EMAIL_EXCEPTIONS.nil? && $EMAIL_EXCEPTIONS == true @@ -579,22 +580,18 @@ def get_apikey() end def parse_json(uri) - uri = URI.parse(uri) begin - response = open(uri, "Authorization" => "apikey token=#{get_apikey}").read - rescue Exception => error + response = Net::HTTP.get(URI(uri), { 'Authorization' => "apikey token=#{get_apikey}" }) + rescue StandardError => e @retries ||= 0 - if @retries < 1 # retry once only - @retries += 1 - retry - else - raise error - end + raise e unless @retries < RETRY_LIMIT + + @retries += 1 + retry end JSON.parse(response) end - def get_batch_results(params) begin response = RestClient.post REST_URI_BATCH, params.to_json, :content_type => :json, :accept => :json, :authorization => "apikey token=#{get_apikey}" diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 69aa3032e..59c1866ad 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -1,11 +1,19 @@ -class SubmissionsController < ApplicationController +# frozen_string_literal: true +class SubmissionsController < ApplicationController layout :determine_layout - before_action :authorize_and_redirect, :only=>[:edit,:update,:create,:new] + before_action :authorize_and_redirect, only: [:edit, :update, :create, :new] def new - @ontology = LinkedData::Client::Models::Ontology.get(CGI.unescape(params[:ontology_id])) rescue nil - @ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id]).first unless @ontology + 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 @submission = @ontology.explore.latest_submission @submission ||= LinkedData::Client::Models::OntologySubmission.new end @@ -16,21 +24,21 @@ def create @submission = LinkedData::Client::Models::OntologySubmission.new(values: submission_params) @ontology = LinkedData::Client::Models::Ontology.get(params[:submission][:ontology]) - + # Update summaryOnly on ontology object - @ontology.summaryOnly = @submission.isRemote.eql?("3") + @ontology.summaryOnly = @submission.isRemote.eql?('3') @ontology.update - - @submission_saved = @submission.save + + @submission_saved = @submission.save(cache_refresh_all: false) if response_error?(@submission_saved) @errors = response_errors(@submission_saved) # see application_controller::response_errors if @errors && @errors[:uploadFilePath] - @errors = ["Please specify the location of your ontology"] + @errors = ['Please specify the location of your ontology'] elsif @errors && @errors[:contact] - @errors = ["Please enter a contact"] + @errors = ['Please enter a contact'] end - render "new" + render 'new' else redirect_to "/ontologies/success/#{@ontology.acronym}" end @@ -39,7 +47,7 @@ def create def edit @ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id]).first submissions = @ontology.explore.submissions - @submission = submissions.select {|o| o.submissionId == params["id"].to_i}.first + @submission = submissions.select { |o| o.submissionId == params['id'].to_i }.first end def update @@ -50,13 +58,13 @@ def update @ontology = LinkedData::Client::Models::Ontology.get(params[:submission][:ontology]) submissions = @ontology.explore.submissions - @submission = submissions.select {|o| o.submissionId == params["id"].to_i}.first + @submission = submissions.select { |o| o.submissionId == params['id'].to_i }.first @submission.update_from_params(submission_params) # Update summaryOnly on ontology object - @ontology.summaryOnly = @submission.isRemote.eql?("3") + @ontology.summaryOnly = @submission.isRemote.eql?('3') @ontology.update - error_response = @submission.update + error_response = @submission.update(cache_refresh_all: false) if response_error?(error_response) @errors = response_errors(error_response) # see application_controller::response_errors render 'edit' @@ -71,9 +79,8 @@ def submission_params p = params.require(:submission).permit(:ontology, :description, :hasOntologyLanguage, :prefLabelProperty, :synonymProperty, :definitionProperty, :authorProperty, :obsoleteProperty, :obsoleteParent, :version, :status, :released, :isRemote, :pullLocation, - :filePath, { contact:[:name, :email] }, :homepage, :documentation, + :filePath, { contact: [:name, :email] }, :homepage, :documentation, :publication) p.to_h end - end diff --git a/config/deploy.rb b/config/deploy.rb index 4079eca0c..e7ad6276b 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -23,7 +23,7 @@ # set :format, :pretty # Default value for :log_level is :debug -set :log_level, :error +# set :log_level, :error # Default value for :pty is false # set :pty, true @@ -55,6 +55,10 @@ # If you don't set `:passenger_restart_with_touch`, capistrano-passenger will check what version of passenger you are running # and use `passenger-config restart-app` if it is available in that version. +# rbenv ruby version +set :rbenv_type, :system +set :rbenv_ruby, File.read('.ruby-version').strip + desc "Check if agent forwarding is working" task :forwarding do on roles(:all) do |h|