From d9aa506b4e49099e685c3aa6b2e448de4a006c47 Mon Sep 17 00:00:00 2001 From: lucacug Date: Wed, 12 Oct 2022 23:10:55 +0100 Subject: [PATCH 01/38] feat: add new with_eu_legislation param to taxon concepts endpoint and validate format --- .../api/v1/taxon_concepts_controller.rb | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/taxon_concepts_controller.rb b/app/controllers/api/v1/taxon_concepts_controller.rb index ec64837..aca6642 100644 --- a/app/controllers/api/v1/taxon_concepts_controller.rb +++ b/app/controllers/api/v1/taxon_concepts_controller.rb @@ -1,6 +1,6 @@ class Api::V1::TaxonConceptsController < Api::V1::BaseController after_action only: [:index] { set_pagination_headers(:taxon_concepts) } - before_action :validate_params, only: [:index] + before_action :validate_params, :set_eu_listings_display, only: [:index] resource_description do formats ['JSON', 'XML'] @@ -63,6 +63,7 @@ class Api::V1::TaxonConceptsController < Api::V1::BaseController param :with_descendants, String, desc: 'Broadens the above search by name to include higher taxa. Value must be true or false', required: false param :taxonomy, String, desc: 'Filter taxon concepts by taxonomy, accepts either CITES or CMS as its value. Defaults to CITES if no value is specified', required: false param :language, String, desc: 'Filter languages returned for common names. Value should be a single country code or a comma separated string of country codes (e.g. language=EN,PL,IT). Defaults to showing all available languages if no language parameter is specified', required: false + param :with_eu_listings, String, desc: 'Include EU listing data. Value must be true or false, defaults to false', required: false example <<-EOS { @@ -125,6 +126,24 @@ class Api::V1::TaxonConceptsController < Api::V1::BaseController "annotation":"Included in Appendix I, except the populations of Botswana, Namibia, South Africa and Zimbabwe, which are included in Appendix II.", "hash_annotation":null } + ], + "eu_listings":[ + { + "id":"32796" + "annex":"A" + "annotation":"Except for the populations of Botswana, Namibia, South Africa and Zimbabwe, which are included in Annex B." + "hash_annotation":nil + "effective_at":"2022-01-19" + "party":nil + }, + { + "id":"34129" + "annex":"B" + "annotation":"Only the populations of Botswana, Namibia, South Africa and Zimbabwe; all other populations are included in Annex A. [...]" + "hash_annotation":nil + "effective_at":"2022-01-19" + "party":nil + } ] } ] @@ -194,6 +213,24 @@ class Api::V1::TaxonConceptsController < Api::V1::BaseController + + + 32796 + A + Except for the populations of Botswana, Namibia, South Africa and Zimbabwe, which are [...] + + 2022-01-19 + + + + 34129 + B + Only the populations of Botswana, Namibia, South Africa and Zimbabwe; all other populations are [...] + + 2022-01-19 + + + @@ -260,10 +297,14 @@ def set_language @languages = params[:language].delete(' ').split(',').map! { |lang| lang.upcase } unless params[:language].nil? end + def set_eu_listings_display + @eu_listings = params[:with_eu_listings] + end + def permitted_params [ :page, :per_page, :updated_since, :name, - :with_descendants, :taxonomy, :language, :format + :with_descendants, :taxonomy, :language, :format, :with_eu_listings ] end @@ -273,7 +314,8 @@ def validate_params :updated_since, :page, :per_page, - :with_descendants + :with_descendants, + :with_eu_listings ].each do |param| unless send(:"validate_#{param}_format") track_api_error("Invalid parameter format: #{param}", 400) and return @@ -307,4 +349,9 @@ def validate_with_descendants_format return true unless params[:with_descendants] /^(true|false)$/.match(params[:with_descendants]) end + + def validate_with_eu_listings_format + return true unless params[:with_eu_listings] + /^(true|false)$/.match(params[:with_eu_listings]) + end end From 2af902113e8d1c3afdabdaff02ace8fddea4125d Mon Sep 17 00:00:00 2001 From: lucacug Date: Wed, 12 Oct 2022 23:11:31 +0100 Subject: [PATCH 02/38] feat: retrieve current eu listings --- app/models/taxon_concept.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/models/taxon_concept.rb b/app/models/taxon_concept.rb index e15f73e..85e7f2d 100644 --- a/app/models/taxon_concept.rb +++ b/app/models/taxon_concept.rb @@ -68,6 +68,24 @@ def current_cites_additions ]).where(is_current: true, change_type_name: 'ADDITION') end + def current_eu_listings + eu_listings.select([ + :id, + :effective_at, + :eu_regulation, + :species_listing_name, + :party_en, + :party_es, + :party_fr, + :annotation_en, + :annotation_es, + :annotation_fr, + :hash_annotation_en, + :hash_annotation_es, + :hash_annotation_fr + ]).where(is_current: true, change_type_name: 'ADDITION') + end + def cites_suspensions_including_global CitesSuspension.where( [ From 46aaa7323ccb00c5f4f4ced94e66736ef4ea590e Mon Sep 17 00:00:00 2001 From: lucacug Date: Wed, 12 Oct 2022 23:11:58 +0100 Subject: [PATCH 03/38] feat: add current eu listings to taxon concept api response --- app/views/api/v1/taxon_concepts/index.rabl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/views/api/v1/taxon_concepts/index.rabl b/app/views/api/v1/taxon_concepts/index.rabl index 187209f..31c2d69 100644 --- a/app/views/api/v1/taxon_concepts/index.rabl +++ b/app/views/api/v1/taxon_concepts/index.rabl @@ -30,5 +30,22 @@ child @taxon_concepts => :taxon_concepts do } end } + + attribute :eu_listing, if: :is_accepted_name? + if @eu_listings == 'true' + node(:eu_listings, if: :is_accepted_name?) { |tc| + tc.current_eu_listings.map do |el| + { + :id => el.id, + :annex => el.species_listing_name, + :annotation => el.annotation, + :hash_annotation => el.hash_annotation, + :effective_at => el.effective_at, + :party=> el.party + } + end + } + end + node(:accepted_names, if: :is_synonym?) { |tc| tc.accepted_names } end From e1a85c25acfaf4e3fc8e44df42058ff5c11cdb44 Mon Sep 17 00:00:00 2001 From: lucacug Date: Thu, 13 Oct 2022 14:52:23 +0100 Subject: [PATCH 04/38] feat: add eu_listings fields description --- app/controllers/api/v1/taxon_concepts_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/v1/taxon_concepts_controller.rb b/app/controllers/api/v1/taxon_concepts_controller.rb index aca6642..06e8ac7 100644 --- a/app/controllers/api/v1/taxon_concepts_controller.rb +++ b/app/controllers/api/v1/taxon_concepts_controller.rb @@ -25,6 +25,8 @@ class Api::V1::TaxonConceptsController < Api::V1::BaseController [common_names] list of common names (with language given by ISO 639-1 code; only for accepted names) [name, language max 255 characters] [cites_listing] value of current CITES listing (as per CITES Checklist). When taxon concept is removed from appendices this becomes +NC+. When taxon is split listed it becomes a concatenation of appendix symbols, e.g. +I/II/NC+ (only for accepted names) [max 255 characters] [cites_listings] list of current CITES listings with annotations (there will be more than one element in this list in case of split listings; only for accepted names) [appendix max 255 characters; annotation, hash_annotation unlimited length] +[eu_listing] value of current EU listing. When taxon concept is removed from annexes this becomes +NC+. When taxon is split listed it becomes a concatenation of annex symbols, e.g. +A/B/NC+ (only for accepted names) [max 255 characters] +[eu_listings] list of current EU listings with annotations (there will be more than one element in this list in case of split listings; only for accepted names) [appendix max 255 characters; annotation, hash_annotation unlimited length] [accepted_names] list of accepted names (only for synonyms, i.e. name_status == S) [full_name, author_year and rank follow the same length constraints as respective properties of the main taxon concept] ==== Note on deleted taxon concepts From 6f1c62954e2d37c939c40d4e61651aa020a0e3c6 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Tue, 6 Aug 2024 16:56:46 +0100 Subject: [PATCH 05/38] chore: remove uservoice, which is no longer working --- app/views/layouts/application.html.erb | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6cf86eb..048140d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -80,25 +80,5 @@ - - <% if ["development", "production"].include? Rails.env %> - - - - - - <% end %> From 1d97e2bb32dd878c3b0c7c31a5c9044eb4e449ea Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Tue, 6 Aug 2024 17:44:31 +0100 Subject: [PATCH 06/38] chore: upgrade ruby from 2.2.3 to 2.3.1 (and devise from 3.5.4 to 3.5.10, to fix tests) --- .ruby-version | 2 +- .travis.yml | 2 +- Gemfile | 2 +- Gemfile.lock | 10 +++++----- config/deploy.rb | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.ruby-version b/.ruby-version index 5859406..2bf1c1c 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.2.3 +2.3.1 diff --git a/.travis.yml b/.travis.yml index 35f60ae..190c96f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: ruby bundler_args: --without development production staging rvm: - - 2.2.3 + - 2.3.1 addons: postgresql: 9.4 # uncomment this line if your project needs to run something other than `rake`: diff --git a/Gemfile b/Gemfile index 9da96a4..447d99f 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' gem 'rails', '4.2.5.2' gem 'apipie-rails' # Documentation -gem 'devise', '>= 3.5.4' +gem 'devise', '>= 3.5.10' gem 'annotate' gem 'sass-rails'#, '~> 3.2.3' gem 'uglifier'#, '>= 1.0.3' diff --git a/Gemfile.lock b/Gemfile.lock index 5c1eb7d..900c89f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,7 +48,7 @@ GEM rack thread_safe arel (6.0.3) - bcrypt (3.1.10) + bcrypt (3.1.12) builder (3.2.2) byebug (4.0.2) columnize (= 0.9.0) @@ -104,7 +104,7 @@ GEM compass (~> 1.0.0) sass-rails (<= 5.0.1) sprockets (< 2.13) - devise (3.5.6) + devise (3.5.10) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) @@ -253,7 +253,7 @@ GEM execjs (>= 0.3.0) json (>= 1.8.0) valuable (0.9.9) - warden (1.2.6) + warden (1.2.7) rack (>= 1.0) will_paginate (3.0.7) xpath (2.0.0) @@ -280,7 +280,7 @@ DEPENDENCIES coffee-rails (~> 4.0.0) compass compass-rails - devise (>= 3.5.4) + devise (>= 3.5.10) dotenv-rails factory_girl_rails groupdate @@ -308,4 +308,4 @@ DEPENDENCIES will_paginate BUNDLED WITH - 1.10.6 + 1.17.3 diff --git a/config/deploy.rb b/config/deploy.rb index 63f3c57..6c3e05e 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -5,7 +5,7 @@ set :repo_url, 'git@github.com:unepwcmc/species-api.git' set :rvm_type, :user -set :rvm_ruby_version, '2.2.3' +set :rvm_ruby_version, '2.3.1' set :deploy_user, 'wcmc' set :deploy_to, "/home/#{fetch(:deploy_user)}/#{fetch(:application)}" From 5153d7a4856c43ec52a023cdacc2e6f54caa03bf Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Tue, 6 Aug 2024 17:49:29 +0100 Subject: [PATCH 07/38] docs: add getting started instructions to the readme --- README.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d4cb947..6e887d1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,25 @@ -species-api -=========== +# Species+/CITES Checklist API -Species+/CITES Checklist API +### Getting started -Ensure you already have Species+ installed and the database set up. Species API will use the Species+ database as the integration layer. \ No newline at end of file +Ensure you already have Species+ installed and the database set up and running +on `localhost:5432`. Species API will use the Species+ database. + +### Running locally + +Install the relevant versions of `ruby` and `bundler`. You may find other system +dependencies such as `libsodium-dev` and `libpq-dev` are required. + +``` +# Install gems +bundle + +# Run the server on http://localhost:3011/ +bundle exec rails s -p 3011 +``` + +### Running tests + +``` +bundle exec rake test +``` From 03131f9361a5ed2ae0e746f2395271ebee63d878 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Tue, 6 Aug 2024 18:09:32 +0100 Subject: [PATCH 08/38] chore: add deps for ed25519 keys and update net-ssh for cap --- Gemfile | 6 ++++++ Gemfile.lock | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 447d99f..4073680 100644 --- a/Gemfile +++ b/Gemfile @@ -62,6 +62,12 @@ group :development do gem 'capistrano-maintenance', '~> 1.0', require: false gem 'capistrano-passenger', '~> 0.1.1', require: false gem 'rack-cors', :require => 'rack/cors' + + # Support ed25519 SSH keys + gem 'rbnacl', '4.0.2' + gem 'rbnacl-libsodium', '1.0.16' + gem 'bcrypt_pbkdf', '1.1.0' + gem 'ed25519', '1.2.4' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 900c89f..fc4fe89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,6 +49,7 @@ GEM thread_safe arel (6.0.3) bcrypt (3.1.12) + bcrypt_pbkdf (1.1.0) builder (3.2.2) byebug (4.0.2) columnize (= 0.9.0) @@ -115,6 +116,7 @@ GEM dotenv (2.0.0) dotenv-rails (2.0.0) dotenv (= 2.0.0) + ed25519 (1.2.4) erubis (2.7.0) execjs (2.6.0) factory_girl (4.5.0) @@ -153,7 +155,7 @@ GEM multi_xml (0.5.5) net-scp (1.2.1) net-ssh (>= 2.6.5) - net-ssh (2.9.2) + net-ssh (4.2.0) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) oj (2.12.1) @@ -193,6 +195,10 @@ GEM rb-fsevent (0.9.4) rb-inotify (0.9.5) ffi (>= 0.5.0) + rbnacl (4.0.2) + ffi + rbnacl-libsodium (1.0.16) + rbnacl (>= 3.0.1) rdoc (4.2.0) json (~> 1.4) responders (2.1.1) @@ -267,6 +273,7 @@ DEPENDENCIES api_pagination_headers apipie-rails appsignal + bcrypt_pbkdf (= 1.1.0) byebug capistrano (~> 3.4.0) capistrano-bundler @@ -282,6 +289,7 @@ DEPENDENCIES compass-rails devise (>= 3.5.10) dotenv-rails + ed25519 (= 1.2.4) factory_girl_rails groupdate httparty @@ -294,6 +302,8 @@ DEPENDENCIES rabl rack-cors rails (= 4.2.5.2) + rbnacl (= 4.0.2) + rbnacl-libsodium (= 1.0.16) sass-rails schema_plus sdoc (~> 0.4.0) From a3bf36f63acdd518076605763af9ff630f7ae8f1 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Wed, 7 Aug 2024 13:42:20 +0100 Subject: [PATCH 09/38] feat: implement feedback modal --- app/assets/stylesheets/species/all.scss | 101 +++++++++++++++++++++ app/views/layouts/_feedback_modal.html.erb | 21 +++++ app/views/layouts/application.html.erb | 5 + 3 files changed, 127 insertions(+) create mode 100644 app/views/layouts/_feedback_modal.html.erb diff --git a/app/assets/stylesheets/species/all.scss b/app/assets/stylesheets/species/all.scss index 8391b7d..261c85d 100755 --- a/app/assets/stylesheets/species/all.scss +++ b/app/assets/stylesheets/species/all.scss @@ -267,3 +267,104 @@ body.inner #footer .holder{ left: 50%; margin: 0 auto; } + + +.btn-fixed-vertical { + bottom: 50%; + cursor: pointer; + position: fixed; + right: -28px; + transform: rotate(90deg); + z-index: 10; +} + +/* Also occurs in Species+ SAPI repo. Styles are not quite identical. */ + +.btn-page-feedback { + text-decoration: none; + font-size: 13px; + font-weight: bold; + text-transform: uppercase; + color: #fff; + margin: 18px 0 0; + padding: 0 14px; + background: #376382; + line-height: 31px; + -webkit-border-radius: 20px; + border-radius: 20px; + border: 2px solid #fff +} + +.btn-page-feedback:hover { + color: #fff; + background: #253848; + transition: all 0.5s ease; + text-decoration: none; +} + +#feedback_modal { + position: fixed; + top: 0; + left: 0; + background: rgba(0,0,0,0.6); + z-index: 9999; + width: 100%; + height: 100%; + display: none; +} + +#feedback_modal:target { + display: block; + opacity: 2; +} + +#feedback_form { + height: fit-content; + width: 560px; + margin: auto; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: 10; + display: block; + background-color: #A4C5DA; + .feedback-cancel { + float: right; + padding: 4px 8px; + margin: 10px 10px 0; + color: #376382; + text-decoration: none; + cursor: pointer; + } + .feedback-header { + padding: 32px 32px 16px; + h2 { + padding: 0; + margin: 0; + text-transform: none; + font-size: 24px; + font-weight: bold; + color: black; + } + } + .feedback-body { + padding: 16px 32px 32px; + color: black; + p { + padding-bottom: 8px; + } + } +} + +.footer-feedback { + clear: both; + margin-left: auto; + width: fit-content; + a { + color: #648aa2; + text-decoration: none; + cursor: pointer; + } +} diff --git a/app/views/layouts/_feedback_modal.html.erb b/app/views/layouts/_feedback_modal.html.erb new file mode 100644 index 0000000..5195955 --- /dev/null +++ b/app/views/layouts/_feedback_modal.html.erb @@ -0,0 +1,21 @@ +
+
+ + +
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 048140d..316e330 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -40,6 +40,8 @@ + Feedback + <%= render "layouts/feedback_modal" %>
+
From 4af58dc27a17e0d5eb08526a2fab3e2736dfece4 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Wed, 7 Aug 2024 16:02:29 +0100 Subject: [PATCH 10/38] feat: allow deploying from branches other than master --- config/deploy/production.rb | 2 +- config/deploy/staging.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/deploy/production.rb b/config/deploy/production.rb index b423810..4b9f028 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,5 +1,5 @@ set :stage, :production -set :branch, "master" +set :branch, ENV['CAP_BRANCH'] || 'master' server "sapi-production.linode.unep-wcmc.org", user: "wcmc", roles: %w{app web db} diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 5b18530..704787a 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,5 +1,5 @@ set :stage, :staging -set :branch, :master +set :branch, ENV['CAP_BRANCH'] || 'master' # note, not develop, oddly. server "sapi-staging.linode.unep-wcmc.org", user: "wcmc", roles: %w{app web db} From 43d1821c5e42b59382ca766bbb9385986c6ee64c Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Thu, 8 Aug 2024 10:55:56 +0100 Subject: [PATCH 11/38] style: tweak alignment of feedback link in footer --- app/assets/stylesheets/species/all.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/stylesheets/species/all.scss b/app/assets/stylesheets/species/all.scss index 261c85d..5e6caed 100755 --- a/app/assets/stylesheets/species/all.scss +++ b/app/assets/stylesheets/species/all.scss @@ -362,6 +362,7 @@ body.inner #footer .holder{ clear: both; margin-left: auto; width: fit-content; + min-width: 100px; /* to be same size as logo */ a { color: #648aa2; text-decoration: none; From 017c707429c9630cce5e16cbde4d0f1b4bf11a2d Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Mon, 11 Nov 2024 08:49:32 +0000 Subject: [PATCH 12/38] fix: Most urls should be https --- app/views/devise/registrations/new.html.erb | 2 +- app/views/layouts/application.html.erb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index ad54ffd..fae0e36 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -29,7 +29,7 @@
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 316e330..7dbd22c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -47,7 +47,7 @@