From 5035ff3164da88095ecf9f4be08c3ae9223a9226 Mon Sep 17 00:00:00 2001 From: Sean Crowe <1069588+crowesn@users.noreply.github.com> Date: Thu, 27 Jan 2022 12:28:27 -0500 Subject: [PATCH 1/8] Upgrade to ruby-2.7.5 (#963) Co-authored-by: crowesn --- .circleci/config.yml | 4 ++-- .ruby-version | 2 +- Dockerfile | 2 +- Dockerfile.dev | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9edfeef4..c7d3abce 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ jobs: parameters: ruby_version: type: string - default: 2.7.2 + default: 2.7.5 bundler_version: type: string default: 2.0.1 @@ -90,4 +90,4 @@ workflows: ci: jobs: - build: - name: ruby2-7-2 + name: ruby2-7-5 diff --git a/.ruby-version b/.ruby-version index 37c2961c..a603bb50 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.2 +2.7.5 diff --git a/Dockerfile b/Dockerfile index d6739ea1..fe9c67a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:2.5.5 +FROM ruby:2.7.5 ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 diff --git a/Dockerfile.dev b/Dockerfile.dev index 131c5c47..eb68ec82 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM ruby:2.5.5 +FROM ruby:2.7.5 ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 From 1eb0c1066893184d78d5b1339232a4e80b0830af Mon Sep 17 00:00:00 2001 From: Sean Crowe <1069588+crowesn@users.noreply.github.com> Date: Thu, 27 Jan 2022 13:59:33 -0500 Subject: [PATCH 2/8] un-hide share tab (#961) Co-authored-by: crowesn --- app/views/hyrax/base/_guts4form.html.erb | 2 +- spec/features/create_article_spec.rb | 3 +++ spec/features/create_dataset_spec.rb | 3 +++ spec/features/create_document_spec.rb | 3 +++ spec/features/create_etd_spec.rb | 3 +++ spec/features/create_generic_work_spec.rb | 3 +++ spec/features/create_image_spec.rb | 3 +++ spec/features/create_medium_spec.rb | 3 +++ spec/features/create_student_work_spec.rb | 3 +++ 9 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/views/hyrax/base/_guts4form.html.erb b/app/views/hyrax/base/_guts4form.html.erb index 7c36918e..4e242beb 100644 --- a/app/views/hyrax/base/_guts4form.html.erb +++ b/app/views/hyrax/base/_guts4form.html.erb @@ -32,7 +32,7 @@ <% end %> - - <% end %> - - + + <% end %> From 9123a0c8c1458eaf24621d88dc2b4747ee96e6a9 Mon Sep 17 00:00:00 2001 From: Sean Crowe <1069588+crowesn@users.noreply.github.com> Date: Mon, 31 Jan 2022 16:28:57 -0500 Subject: [PATCH 4/8] ignore batch create mass assign warning (#962) Co-authored-by: crowesn --- config/brakeman.ignore | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 config/brakeman.ignore diff --git a/config/brakeman.ignore b/config/brakeman.ignore new file mode 100644 index 00000000..3b1a0b5a --- /dev/null +++ b/config/brakeman.ignore @@ -0,0 +1,26 @@ +{ + "ignored_warnings": [ + { + "warning_type": "Mass Assignment", + "warning_code": 70, + "fingerprint": "c58372ffa9750e7506995301196bc155ae5e14f7b5f01d301b8232036c8b2ca3", + "check_name": "MassAssignment", + "message": "Specify exact keys allowed for mass assignment instead of using `permit!` which allows any keys", + "file": "app/controllers/hyrax/batch_uploads_controller.rb", + "line": 16, + "link": "https://brakemanscanner.org/docs/warning_types/mass_assignment/", + "code": "params[:title].permit!", + "render_path": null, + "location": { + "type": "method", + "class": "Hyrax::BatchUploadsController", + "method": "create_update_job" + }, + "user_input": null, + "confidence": "Medium", + "note": "" + } + ], + "updated": "2022-01-26 16:34:01 -0500", + "brakeman_version": "5.1.1" +} From fceb5e10b776648e93ddf362d704a82488b38cde Mon Sep 17 00:00:00 2001 From: Sean Crowe <1069588+crowesn@users.noreply.github.com> Date: Thu, 3 Feb 2022 14:55:36 -0500 Subject: [PATCH 5/8] Upgrade rack, puma and browse-everything (#964) * upgrade rack to 2.2.3 * update puma/browse-everything Co-authored-by: crowesn --- Gemfile | 6 +-- Gemfile.lock | 134 +++++++++++++++++++++++++-------------------------- 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Gemfile b/Gemfile index c68c8770..22a05d41 100644 --- a/Gemfile +++ b/Gemfile @@ -11,12 +11,12 @@ end gem 'bigdecimal', '1.3.5' # For BrowseEverything to work with Hyrax 2.x then we need to pin BE -gem 'browse-everything', '1.0.2' +gem 'browse-everything', '1.1.0' gem 'bulkrax', git: 'https://github.com/uclibs/bulkrax.git', ref: '4ad295999ff6c2f095ad3dc2fa67cd9a05f6b77f' gem 'hydra-remote_identifier', github: 'uclibs/hydra-remote_identifier', branch: 'scholar-datacite' gem 'kaltura', '0.1.1' -gem 'rack', '2.0.8' +gem 'rack', '2.2.3' gem 'sidekiq-limit_fetch' gem 'willow_sword', github: 'notch8/willow_sword' @@ -28,7 +28,7 @@ gem 'rails', '~> 5.1.7' # Use sqlite3 as the database for Active Record gem 'sqlite3', '1.3.13' # Use Puma as the app server -gem 'puma', '~> 3.11' +gem 'puma', '~> 4.3.8' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets diff --git a/Gemfile.lock b/Gemfile.lock index 399b939f..dd7f669a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,10 +113,10 @@ GEM activesupport (>= 3.0.0) rdf (>= 2.0.2, < 4.0) rdf-vocab (>= 2.0, < 4.0) - active_attr (0.15.3) - actionpack (>= 3.0.2, < 7.0) - activemodel (>= 3.0.2, < 7.0) - activesupport (>= 3.0.2, < 7.0) + active_attr (0.15.4) + actionpack (>= 3.0.2, < 7.1) + activemodel (>= 3.0.2, < 7.1) + activesupport (>= 3.0.2, < 7.1) active_encode (0.8.2) rails sprockets (< 4) @@ -154,8 +154,8 @@ GEM awesome_nested_set (3.4.0) activerecord (>= 4.0.0, < 7.0) aws-eventstream (1.2.0) - aws-partitions (1.550.0) - aws-sdk-core (3.125.5) + aws-partitions (1.551.0) + aws-sdk-core (3.125.6) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.525.0) aws-sigv4 (~> 1.1) @@ -216,21 +216,19 @@ GEM bootstrap_form (4.4.0) actionpack (>= 5.0) activemodel (>= 5.0) - brakeman (5.1.1) + brakeman (5.2.1) breadcrumbs_on_rails (3.0.1) - browse-everything (1.0.2) + browse-everything (1.1.0) addressable (~> 2.5) aws-sdk-s3 dropbox_api (>= 0.1.10) google-api-client (~> 0.23) - google_drive (~> 2.1) - googleauth (= 0.6.6) - puma (~> 3.11) + google_drive (>= 2.1, < 4) + googleauth (>= 0.6.6, < 1.0) rails (>= 4.2, < 6.0) ruby-box signet (~> 0.8) sprockets (~> 3.7) - thor (~> 0.19) typhoeus builder (3.2.4) bundler-audit (0.7.0.1) @@ -268,7 +266,7 @@ GEM ssrf_filter (~> 1.0) childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) - clamby (1.6.6) + clamby (1.6.8) clipboard-rails (1.7.1) coderay (1.1.3) coercible (1.0.0) @@ -308,9 +306,9 @@ GEM railties (>= 4.1.0, < 6.0) responders warden (~> 1.2.3) - devise-guests (0.7.0) + devise-guests (0.8.1) devise - diff-lcs (1.4.4) + diff-lcs (1.5.0) docile (1.4.0) docopt (0.5.0) domain_name (0.5.20190701) @@ -422,26 +420,27 @@ GEM geocoder (1.7.3) globalid (1.0.0) activesupport (>= 5.0) - google-api-client (0.32.1) + google-api-client (0.52.0) addressable (~> 2.5, >= 2.5.1) - googleauth (>= 0.5, < 0.10.0) + googleauth (~> 0.9) httpclient (>= 2.8.1, < 3.0) mini_mime (~> 1.0) representable (~> 3.0) retriable (>= 2.0, < 4.0) - signet (~> 0.10) - google_drive (2.1.3) + rexml + signet (~> 0.12) + google_drive (3.0.6) google-api-client (>= 0.11.0, < 1.0.0) googleauth (>= 0.5.0, < 1.0.0) nokogiri (>= 1.5.3, < 2.0.0) - googleauth (0.6.6) + googleauth (0.10.0) faraday (~> 0.12) jwt (>= 1.4, < 3.0) - memoist (~> 0.12) + memoist (~> 0.16) multi_json (~> 1.11) os (>= 0.9, < 2.0) - signet (~> 0.7) - grape (1.5.3) + signet (~> 0.12) + grape (1.6.2) activesupport builder dry-types (>= 1.1) @@ -454,19 +453,19 @@ GEM temple (>= 0.8.0) tilt hashdiff (1.0.1) - hashie (4.1.0) + hashie (5.0.0) hiredis (0.6.3) htmlentities (4.3.4) - http (5.0.1) - addressable (~> 2.3) + http (5.0.4) + addressable (~> 2.8) http-cookie (~> 1.0) http-form_data (~> 2.2) - llhttp-ffi (~> 0.3.0) + llhttp-ffi (~> 0.4.0) http-cookie (1.0.4) domain_name (~> 0.5) http-form_data (2.3.0) http_logger (0.7.0) - httparty (0.18.1) + httparty (0.20.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) httpclient (2.8.3) @@ -568,7 +567,7 @@ GEM signet solrizer (>= 3.4, < 5) tinymce-rails (~> 4.1) - i18n (1.9.0) + i18n (1.9.1) concurrent-ruby (~> 1.0) ice_nine (0.11.2) iiif-image-api (0.2.0) @@ -593,16 +592,16 @@ GEM railties (>= 3.2.16) json (2.6.1) json-canonicalization (0.3.0) - json-ld (3.1.10) + json-ld (3.2.0) htmlentities (~> 4.3) - json-canonicalization (~> 0.2) + json-canonicalization (~> 0.3) link_header (~> 0.0, >= 0.0.8) - multi_json (~> 1.14) - rack (~> 2.0) - rdf (~> 3.1) - json-ld-preloaded (3.1.6) - json-ld (~> 3.1) - rdf (~> 3.1) + multi_json (~> 1.15) + rack (~> 2.2) + rdf (~> 3.2) + json-ld-preloaded (3.2.0) + json-ld (~> 3.2) + rdf (~> 3.2) json-schema (2.8.1) addressable (>= 2.4) jwt (2.3.0) @@ -677,7 +676,7 @@ GEM listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - llhttp-ffi (0.3.1) + llhttp-ffi (0.4.0) ffi-compiler (~> 1.0) rake (~> 13.0) logger (1.5.0) @@ -756,15 +755,16 @@ GEM rails (> 3.2.0) orm_adapter (0.5.0) os (1.1.4) - parallel (1.20.1) - parser (3.0.2.0) + parallel (1.21.0) + parser (3.1.0.0) ast (~> 2.4.1) parslet (2.0.0) posix-spawn (0.3.15) power_converter (0.1.2) public_suffix (4.0.6) pul_uv_rails (2.0.1) - puma (3.12.6) + puma (4.3.10) + nio4r (~> 2.0) qa (5.7.0) activerecord-import deprecation @@ -775,7 +775,7 @@ GEM rails (>= 5.0, < 6.2) rdf racc (1.6.0) - rack (2.0.8) + rack (2.2.3) rack-accept (0.4.5) rack (>= 0.4) rack-openid (1.4.2) @@ -814,7 +814,7 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (3.0.0) + rainbow (3.1.1) rake (13.0.6) rb-fsevent (0.11.0) rb-inotify (0.10.1) @@ -832,7 +832,7 @@ GEM nokogiri (~> 1.10) rdf (~> 3.1) rdf-xsd (~> 3.1) - rdf-n3 (3.2.0) + rdf-n3 (3.2.1) ebnf (~> 2.2) rdf (~> 3.2) sparql (~> 3.2) @@ -882,7 +882,7 @@ GEM redis (>= 3.0.4) redlock (1.2.2) redis (>= 3.0.0, < 5.0) - regexp_parser (2.1.1) + regexp_parser (2.2.0) representable (3.1.1) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) @@ -909,15 +909,15 @@ GEM activemodel (>= 3.0) activesupport (>= 3.0) rspec-mocks (>= 2.99, < 4.0) - rspec-core (3.10.1) + rspec-core (3.10.2) rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + rspec-expectations (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-its (1.3.0) rspec-core (>= 3.0.0) rspec-expectations (>= 3.0.0) - rspec-mocks (3.10.2) + rspec-mocks (3.10.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-rails (4.1.2) @@ -930,8 +930,8 @@ GEM rspec-support (~> 3.10) rspec-retry (0.6.2) rspec-core (> 3.3) - rspec-support (3.10.2) - rspec_junit_formatter (0.4.1) + rspec-support (3.10.3) + rspec_junit_formatter (0.5.1) rspec-core (>= 2, < 4, != 2.12.0) rubocop (0.85.1) parallel (~> 1.10) @@ -987,15 +987,15 @@ GEM selenium-webdriver (3.12.0) childprocess (~> 0.5) rubyzip (~> 1.2) - shex (0.6.4) - ebnf (~> 2.1, >= 2.2) + shex (0.7.1) + ebnf (~> 2.2) htmlentities (~> 4.3) - json-ld (~> 3.1) - json-ld-preloaded (~> 3.1) - rdf (~> 3.1) - rdf-xsd (~> 3.1) - sparql (~> 3.1) - sxp (~> 1.1) + json-ld (~> 3.2) + json-ld-preloaded (~> 3.2) + rdf (~> 3.2) + rdf-xsd (~> 3.2) + sparql (~> 3.2) + sxp (~> 1.2) shoulda-matchers (3.1.3) activesupport (>= 4.0.0) show_me_the_cookies (5.0.1) @@ -1065,10 +1065,10 @@ GEM temple (0.8.2) term-ansicolor (1.7.1) tins (~> 1.0) - thor (0.20.3) + thor (1.2.1) thread_safe (0.3.6) tilt (2.0.10) - tins (1.29.1) + tins (1.31.0) sync tinymce-rails (4.9.11) railties (>= 3.1.1) @@ -1089,8 +1089,8 @@ GEM execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.7.7) - unicode-display_width (1.7.0) + unf_ext (0.0.8) + unicode-display_width (1.8.0) unicode-types (1.7.0) validatable (1.6.7) vcr (6.0.0) @@ -1098,8 +1098,8 @@ GEM axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) - warden (1.2.8) - rack (>= 2.0.6) + warden (1.2.9) + rack (>= 2.0.9) web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) @@ -1131,7 +1131,7 @@ DEPENDENCIES bixby (>= 1.0.0) bootstrap-sass (~> 3.4.1) brakeman - browse-everything (= 1.0.2) + browse-everything (= 1.1.0) bulkrax! bundler (~> 1.17) bundler-audit @@ -1167,8 +1167,8 @@ DEPENDENCIES omniauth-openid omniauth-shibboleth orcid! - puma (~> 3.11) - rack (= 2.0.8) + puma (~> 4.3.8) + rack (= 2.2.3) rails (~> 5.1.7) rails-controller-testing rest-client From 7324b596b9229e5ddd6156ca04bd2b39bb737924 Mon Sep 17 00:00:00 2001 From: Thomas Scherz Date: Tue, 21 Sep 2021 12:52:04 -0400 Subject: [PATCH 6/8] Overwrites Hyrax Resource Synce Controller. --- .rubocop.yml | 1 + .../hyrax/resource_sync_controller.rb | 56 +++++++++++++++ .../hyrax/resource_sync_controller_spec.rb | 71 +++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 app/controllers/hyrax/resource_sync_controller.rb create mode 100644 spec/controllers/hyrax/resource_sync_controller_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml index 6c7f08ee..1105cce6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -200,6 +200,7 @@ RSpec/ExampleLength: - 'app/api/**/*' - 'spec/api/*' - 'spec/unit/permission_spec.rb' + - 'spec/controllers/hyrax/resource_sync_controller_spec.rb' RSpec/ExpectActual: Enabled: false diff --git a/app/controllers/hyrax/resource_sync_controller.rb b/app/controllers/hyrax/resource_sync_controller.rb new file mode 100644 index 00000000..274b74da --- /dev/null +++ b/app/controllers/hyrax/resource_sync_controller.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true +class Hyrax::ResourceSyncController < ApplicationController + include ActionController::RequestForgeryProtection + protect_from_forgery with: :null_session + + # We don't need locale here + def default_url_options + super.except(:locale) + end + + def source_description + render_from_cache_as_xml(:source_description) + end + + def capability_list + render_from_cache_as_xml(:capability_list) + end + + def change_list + render_from_cache_as_xml(:change_list) + end + + def resource_list + render_from_cache_as_xml(:resource_list) + end + + private + + def build_change_list + Hyrax::ResourceSync::ChangeListWriter.new(capability_list_url: hyrax.capability_list_url, + resource_host: request.host).write + end + + def build_resource_list + Hyrax::ResourceSync::ResourceListWriter.new(capability_list_url: hyrax.capability_list_url, + resource_host: request.host).write + end + + def build_capability_list + Hyrax::ResourceSync::CapabilityListWriter.new(resource_list_url: hyrax.resource_list_url, + change_list_url: hyrax.change_list_url, + description_url: hyrax.source_description_url).write + end + + def build_source_description + Hyrax::ResourceSync::SourceDescriptionWriter.new(capability_list_url: hyrax.capability_list_url).write + end + + def render_from_cache_as_xml(resource_sync_type) + # Caching based on host, for multi-tenancy support + body = Rails.cache.fetch("#{resource_sync_type}_#{request.host}", expires_in: 1.week) do + send("build_#{resource_sync_type}") + end + render body: body, content_type: 'application/xml' + end +end diff --git a/spec/controllers/hyrax/resource_sync_controller_spec.rb b/spec/controllers/hyrax/resource_sync_controller_spec.rb new file mode 100644 index 00000000..f421ca23 --- /dev/null +++ b/spec/controllers/hyrax/resource_sync_controller_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true +RSpec.describe Hyrax::ResourceSyncController do + routes { Hyrax::Engine.routes } + before do + Rails.cache.clear + end + + describe "source_description" do + let(:writer) { double } + let(:document) { '' } + let(:capability_list) { Hyrax::Engine.routes.url_helpers.capability_list_url(host: 'test.host') } + + it "is successful" do + allow(Hyrax::ResourceSync::SourceDescriptionWriter).to receive(:new).with(capability_list_url: capability_list).and_return(writer) + expect(writer).to receive(:write).and_return(document) + get :source_description + expect(response.content_type).to eq 'application/xml' + expect(response.body).to eq document + end + end + + describe "capability_list" do + let(:writer) { double } + let(:document) { '' } + let(:capability_list) { Hyrax::Engine.routes.url_helpers.capability_list_url(host: 'test.host') } + + it "is successful" do + allow(Hyrax::ResourceSync::CapabilityListWriter).to receive(:new).with(resource_list_url: "http://test.host/resourcelist", change_list_url: "http://test.host/changelist", description_url: "http://test.host/.well-known/resourcesync").and_return(writer) + expect(writer).to receive(:write).and_return(document) + get :capability_list + expect(response.content_type).to eq 'application/xml' + expect(response.body).to eq document + end + end + + describe "resource_list" do + before do + Rails.cache.clear + end + + let(:writer) { double } + let(:document) { '' } + let(:capability_list) { Hyrax::Engine.routes.url_helpers.capability_list_url(host: 'test.host') } + + it "is successful" do + allow(Hyrax::ResourceSync::ResourceListWriter).to receive(:new).with(capability_list_url: capability_list, resource_host: "test.host").and_return(writer) + expect(writer).to receive(:write).and_return(document) + get :resource_list + expect(response.content_type).to eq 'application/xml' + expect(response.body).to eq document + end + end + + describe "change_list" do + before do + Rails.cache.clear + end + + let(:writer) { double } + let(:document) { '' } + let(:capability_list) { Hyrax::Engine.routes.url_helpers.capability_list_url(host: 'test.host') } + + it "is successful" do + allow(Hyrax::ResourceSync::ChangeListWriter).to receive(:new).with(capability_list_url: capability_list, resource_host: "test.host").and_return(writer) + expect(writer).to receive(:write).and_return(document) + get :change_list + expect(response.content_type).to eq 'application/xml' + expect(response.body).to eq document + end + end +end From df7efceeeae38991483844d725a0522024b60587 Mon Sep 17 00:00:00 2001 From: LISA HAITZ Date: Fri, 28 Jan 2022 16:50:03 -0500 Subject: [PATCH 7/8] New Contact Form- Iframe embed This is the new form created from jotform. --- app/views/hyrax/contact_form/new2.html.erb | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 app/views/hyrax/contact_form/new2.html.erb diff --git a/app/views/hyrax/contact_form/new2.html.erb b/app/views/hyrax/contact_form/new2.html.erb new file mode 100644 index 00000000..0825b817 --- /dev/null +++ b/app/views/hyrax/contact_form/new2.html.erb @@ -0,0 +1,97 @@ + + + From 418cced0a0c5302c05b55bdc9d5883c609a00082 Mon Sep 17 00:00:00 2001 From: Thomas Scherz Date: Mon, 31 Jan 2022 16:25:40 -0500 Subject: [PATCH 8/8] Cleans up contact form for jot form. --- .env.development | 4 - .env.test | 6 +- app/assets/stylesheets/hyrax.scss | 5 - .../hyrax/contact_form_controller.rb | 60 -------- app/models/hyrax/contact_form.rb | 36 ----- .../hyrax/contact_form/_directions.html.erb | 1 - app/views/hyrax/contact_form/new.html.erb | 142 ++++++++++++------ app/views/hyrax/contact_form/new2.html.erb | 97 ------------ config/initializers/hyrax.rb | 4 +- config/initializers/load_captcha_configs.rb | 3 - config/locales/hyrax.en.yml | 4 - config/recaptcha.yml | 11 -- .../hyrax/contact_form_controller_spec.rb | 122 --------------- spec/features/hyrax/contact_form_spec.rb | 25 +-- 14 files changed, 102 insertions(+), 418 deletions(-) delete mode 100644 app/controllers/hyrax/contact_form_controller.rb delete mode 100644 app/models/hyrax/contact_form.rb delete mode 100644 app/views/hyrax/contact_form/_directions.html.erb delete mode 100644 app/views/hyrax/contact_form/new2.html.erb delete mode 100644 config/initializers/load_captcha_configs.rb delete mode 100644 config/recaptcha.yml delete mode 100644 spec/controllers/hyrax/contact_form_controller_spec.rb diff --git a/.env.development b/.env.development index ba127777..38019897 100644 --- a/.env.development +++ b/.env.development @@ -44,10 +44,6 @@ SCHOLAR_ANALYTICS_PRIVKEY_PATH=analytics_privkey_path SCHOLAR_ANALYTICS_PRIVKEY_SECRET=analytics_privkey_secret SCHOLAR_ANALYTICS_CLIENT_EMAIL=analytics_client_email -# Google Re-captcha -SCHOLAR_CAPTCHA_SITE_KEY=captcha_site_key -SCHOLAR_CAPTCHA_SECRET_KEY=captcha_secret_key - # ORCID ORCID_AUTHORIZE_URL=change_me ORCID_APP_ID=change_me diff --git a/.env.test b/.env.test index 80fc5ec4..adf36754 100644 --- a/.env.test +++ b/.env.test @@ -43,10 +43,6 @@ SCHOLAR_ANALYTICS_PRIVKEY_PATH=analytics_privkey_path SCHOLAR_ANALYTICS_PRIVKEY_SECRET=analytics_privkey_secret SCHOLAR_ANALYTICS_CLIENT_EMAIL=analytics_client_email -# Google Re-captcha -SCHOLAR_CAPTCHA_SITE_KEY=captcha_site_key -SCHOLAR_CAPTCHA_SECRET_KEY=captcha_secret_key - # ORCID ORCID_AUTHORIZE_URL=change_me ORCID_APP_ID=change_me @@ -77,4 +73,4 @@ SCHOLAR_DOI_URL=https://api.test.datacite.org/dois API_KEY={ :development => 'testKey'} # XRay max log size in MB, must be an integer value -SCHOLAR_XRAY_MAX_LOG_SIZE=10 \ No newline at end of file +SCHOLAR_XRAY_MAX_LOG_SIZE=10 diff --git a/app/assets/stylesheets/hyrax.scss b/app/assets/stylesheets/hyrax.scss index e55f2d1f..2bf36c6d 100644 --- a/app/assets/stylesheets/hyrax.scss +++ b/app/assets/stylesheets/hyrax.scss @@ -32,11 +32,6 @@ padding-bottom: 10px; } -.g-recaptcha { - margin-bottom: 20px; -} - - div.profile a.btn-primary { margin-bottom: 20px; } diff --git a/app/controllers/hyrax/contact_form_controller.rb b/app/controllers/hyrax/contact_form_controller.rb deleted file mode 100644 index aa599ab1..00000000 --- a/app/controllers/hyrax/contact_form_controller.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: false - -module Hyrax - class ContactFormController < ApplicationController - extend ActiveSupport::Concern - before_action :build_contact_form - - def new; end - - def create - # not spam and a valid form - if @contact_form.valid? && passes_captcha_or_is_logged_in? - Hyrax::ContactMailer.contact(@contact_form).deliver_now - flash.now[:notice] = 'Thank you for your message!' - after_deliver - @contact_form = ContactForm.new - else - flash.now[:error] = 'Sorry, this message was not sent successfully. ' - flash.now[:error] << 'You must complete the Captcha to confirm the form. ' unless passes_captcha_or_is_logged_in? - flash.now[:error] << @contact_form.errors.full_messages.map(&:to_s).join(", ") - end - render :new - rescue RuntimeError => exception - handle_create_exception(exception) - end - - def handle_create_exception(exception) - logger.error("Contact form failed to send: #{exception.inspect}") - flash.now[:error] = 'Sorry, this message was not delivered.' - render :new - end - - # Override this method if you want to perform additional operations - # when a email is successfully sent, such as sending a confirmation - # response to the user. - def after_deliver; end - - def verify_google_recaptcha(key, response) - status = `curl "https://www.google.com/recaptcha/api/siteverify?secret=#{key}&response=#{response}"` - hash = JSON.parse(status) - hash["success"] == true - end - - protected - - def build_contact_form - @contact_form = Hyrax::ContactForm.new(contact_form_params) - end - - def contact_form_params - return {} unless params.key?(:contact_form) - params.require(:contact_form).permit(:contact_method, :category, :name, :email, :subject, :message) - end - - def passes_captcha_or_is_logged_in? - return true if current_user.present? - verify_google_recaptcha(CAPTCHA_SERVER['secret_key'], params["g-recaptcha-response"]) - end - end -end diff --git a/app/models/hyrax/contact_form.rb b/app/models/hyrax/contact_form.rb deleted file mode 100644 index c9335800..00000000 --- a/app/models/hyrax/contact_form.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true -module Hyrax - class ContactForm - include ActiveModel::Model - attr_accessor :contact_method, :category, :name, :email, :subject, :message - validates :email, :name, :subject, :message, presence: true - validates :email, format: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i, allow_blank: true - - # - can't use this without ActiveRecord::Base validates_inclusion_of :category, in: self.class.issue_types_for_locale - - # They should not have filled out the `contact_method' field. That's there to prevent spam. - def spam? - contact_method.present? - end - - # Declare the e-mail headers. It accepts anything the mail method - # in ActionMailer accepts. - def headers - { - subject: "#{Hyrax.config.subject_prefix} #{subject}", - to: Hyrax.config.contact_email, - from: email - } - end - - def self.issue_types_for_locale - [ - I18n.t('hyrax.contact_form.issue_types.depositing'), - I18n.t('hyrax.contact_form.issue_types.changing'), - I18n.t('hyrax.contact_form.issue_types.browsing'), - I18n.t('hyrax.contact_form.issue_types.reporting'), - I18n.t('hyrax.contact_form.issue_types.general') - ] - end - end -end diff --git a/app/views/hyrax/contact_form/_directions.html.erb b/app/views/hyrax/contact_form/_directions.html.erb deleted file mode 100644 index eb6b09da..00000000 --- a/app/views/hyrax/contact_form/_directions.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= t('hyrax.contact_form.notice_html', href: link_to(t("hyrax.contact_form.help_resources_href"), main_app.help_path)) %> diff --git a/app/views/hyrax/contact_form/new.html.erb b/app/views/hyrax/contact_form/new.html.erb index a8df4174..0825b817 100644 --- a/app/views/hyrax/contact_form/new.html.erb +++ b/app/views/hyrax/contact_form/new.html.erb @@ -1,47 +1,97 @@ - -
- <%= render 'directions' %> -
-

- <%= t('hyrax.contact_form.header') %> -

- -<% if user_signed_in? %> - <% nm = current_user.name %> - <% em = current_user.email %> -<% else %> - <% nm = '' %> - <% em = '' %> -<% end %> - -<%= form_for @contact_form, url: hyrax.contact_form_index_path, - html: { class: 'form-horizontal' } do |f| %> - <%= f.text_field :contact_method, class: 'hide' %> - -
- <%= f.label :name, t('hyrax.contact_form.name_label'), class: "col-sm-2 control-label" %> -
<%= f.text_field :name, value: nm, class: 'form-control', required: true %>
-
- -
- <%= f.label :email, t('hyrax.contact_form.email_label'), class: "col-sm-2 control-label" %> -
<%= f.text_field :email, value: em, class: 'form-control', required: true %>
-
- -
- <%= f.label :subject, t('hyrax.contact_form.subject_label'), class: "col-sm-2 control-label" %> -
<%= f.text_field :subject, class: 'form-control', required: true %>
-
- -
- <%= f.label :message, t('hyrax.contact_form.message_label'), class: "col-sm-2 control-label" %> -
<%= f.text_area :message, rows: 4, class: 'form-control', required: true %>
-
- - <% if current_user.blank? %> -
- <% end %> - - <%= f.submit value: t('hyrax.contact_form.button_label'), class: "btn btn-primary" %> -<% end %> + + diff --git a/app/views/hyrax/contact_form/new2.html.erb b/app/views/hyrax/contact_form/new2.html.erb deleted file mode 100644 index 0825b817..00000000 --- a/app/views/hyrax/contact_form/new2.html.erb +++ /dev/null @@ -1,97 +0,0 @@ - - - diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index 83f82b56..a8d248bc 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -28,10 +28,10 @@ # config.admin_set_predicate = ::RDF::DC.isPartOf # Email recipient of messages sent via the contact form - config.contact_email = "scholar@uc.edu" + # config.contact_email = "scholar@uc.edu" # Text prefacing the subject entered in the contact form - config.subject_prefix = "Scholar@UC Contact form:" + # config.subject_prefix = "Scholar@UC Contact form:" # How many notifications should be displayed on the dashboard # config.max_notifications_for_dashboard = 5 diff --git a/config/initializers/load_captcha_configs.rb b/config/initializers/load_captcha_configs.rb deleted file mode 100644 index 8fbf89e4..00000000 --- a/config/initializers/load_captcha_configs.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -CAPTCHA_SERVER = YAML.safe_load(ERB.new(File.read(Rails.root.join('config', 'recaptcha.yml'))).result)[Rails.env] diff --git a/config/locales/hyrax.en.yml b/config/locales/hyrax.en.yml index 17e86122..81a39842 100644 --- a/config/locales/hyrax.en.yml +++ b/config/locales/hyrax.en.yml @@ -98,10 +98,6 @@ en: results_per_page: Results per page sort_by: Sort by works_in_collection: Items in this Collection - contact_form: - header: Contact the Scholar@UC Team - notice_html: 'Please us this form to send questions, feedback, or report a problem to the Scholar@UC team. You can also check %{href} for more information' - help_resources_href: 'Help Resources' file_sets: show_details: fixity_check: Fixity Check diff --git a/config/recaptcha.yml b/config/recaptcha.yml deleted file mode 100644 index bb64e721..00000000 --- a/config/recaptcha.yml +++ /dev/null @@ -1,11 +0,0 @@ -# stores ReCaptcha image server url - -development: - site_key: <%= ENV["SCHOLAR_CAPTCHA_SITE_KEY"] %> - secret_key: <%= ENV["SCHOLAR_CAPTCHA_SECRET_KEY"] %> -test: - site_key: <%= ENV["SCHOLAR_CAPTCHA_SITE_KEY"] %> - secret_key: <%= ENV["SCHOLAR_CAPTCHA_SECRET_KEY"] %> -production: - site_key: <%= ENV["SCHOLAR_CAPTCHA_SITE_KEY"] %> - secret_key: <%= ENV["SCHOLAR_CAPTCHA_SECRET_KEY"] %> diff --git a/spec/controllers/hyrax/contact_form_controller_spec.rb b/spec/controllers/hyrax/contact_form_controller_spec.rb deleted file mode 100644 index ecce82cf..00000000 --- a/spec/controllers/hyrax/contact_form_controller_spec.rb +++ /dev/null @@ -1,122 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Hyrax::ContactFormController do - routes { Hyrax::Engine.routes } - let(:user) { create(:user) } - let(:required_params) do - { - category: "Depositing content", - name: "Gandalf the Grey", - email: "gandalf@middle.earth", - subject: "When in doubt,", - message: "Follow your nose!" - } - end - - describe 'while user is unauthenticated' do - it 'successfully allows reCaptcha' do - described_class.any_instance.stub(:verify_google_recaptcha).and_return(true) - Hyrax::ContactMailer.any_instance.stub(:mail).and_return(true) - post :create, params: { contact_form: required_params } - expect(flash[:notice]).to match(/Thank you for your message/) - end - - it 'fails on reCaptcha failure' do - post :create, params: { contact_form: required_params } - expect(flash[:error]).to match(/You must complete the Captcha to confirm the form/) - end - end - - describe "while user is authenticated" do - before { sign_in(user) } - - describe "#new" do - subject { response } - - before { get :new } - it { is_expected.to be_success } - end - - describe "#create" do - subject { flash } - - before { post :create, params: { contact_form: params } } - context "with the required parameters" do - let(:params) { required_params } - - its(:notice) { is_expected.to eq("Thank you for your message!") } - end - - context "without a name" do - let(:params) { required_params.except(:name) } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Name can't be blank") } - end - - context "without an email" do - let(:params) { required_params.except(:email) } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Email can't be blank") } - end - - context "without a subject" do - let(:params) { required_params.except(:subject) } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Subject can't be blank") } - end - - context "without a message" do - let(:params) { required_params.except(:message) } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Message can't be blank") } - end - - context "with an invalid email" do - let(:params) { required_params.merge(email: "bad-wolf") } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Email is invalid") } - end - end - - describe "#after_deliver" do - context "with a successful email" do - it "calls #after_deliver" do - expect(controller).to receive(:after_deliver) - post :create, params: { contact_form: required_params } - end - end - context "with an unsuccessful email" do - it "does not call #after_deliver" do - expect(controller).not_to receive(:after_deliver) - post :create, params: { contact_form: required_params.except(:email) } - end - end - end - - describe "test configuration values" do - context "for the contact form" do - it "check contact email" do - expect(Hyrax.config.contact_email).to eq 'scholar@uc.edu' - end - it "check form name" do - expect(Hyrax.config.subject_prefix).to eq 'Scholar@UC Contact form:' - end - end - end - - context "when encoutering a RuntimeError" do - let(:logger) { double(info?: true) } - - before do - allow(controller).to receive(:logger).and_return(logger) - allow(Hyrax::ContactMailer).to receive(:contact).and_raise(RuntimeError) - end - it "is logged via Rails" do - expect(logger).to receive(:error).with("Contact form failed to send: #") - post :create, params: { contact_form: required_params } - end - end - end -end diff --git a/spec/features/hyrax/contact_form_spec.rb b/spec/features/hyrax/contact_form_spec.rb index 2ef2bb2a..779753d2 100644 --- a/spec/features/hyrax/contact_form_spec.rb +++ b/spec/features/hyrax/contact_form_spec.rb @@ -3,31 +3,12 @@ require 'rails_helper' RSpec.describe "Sending an email via the contact form", type: :feature do - let(:user) { create(:user) } - - describe "with unauthenticated user" do + describe "with Jot Iframe" do it "shows recaptcha dialog" do visit '/' click_link "Contact", match: :first - expect(page).to have_css('div.g-recaptcha') - end - end - - describe "with authenticated user" do - before { sign_in(user) } - - it "sends mail" do - visit '/' - click_link "Contact", match: :first - expect(page).to have_content "Contact the Scholar@UC Team" - expect(page).to have_link "Help Resources" - expect(page).not_to have_content "Issue Type" - fill_in "Your Name", with: "Test McPherson" - fill_in "Your Email", with: "archivist1@example.com" - fill_in "Message", with: "I am contacting you regarding ScholarSphere." - fill_in "Subject", with: "My Subject is Cool" - click_button "Send" - expect(page).to have_content "Thank you for your message!" + expect(page).to have_css('iframe') + page.html.should include('') end end end